Skip to content

Commit 2dd09be

Browse files
committed
move tag generation to upstream job to avoid race condition
1 parent 29702da commit 2dd09be

File tree

1 file changed

+28
-18
lines changed

1 file changed

+28
-18
lines changed

.github/workflows/image-ci.yml

Lines changed: 28 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,32 @@ on:
1111
- "06-demo-application/**/*"
1212

1313
jobs:
14+
generate-image-tag:
15+
runs-on: ubuntu-latest
16+
outputs:
17+
image_tag: ${{ steps.generate-image-tag.outputs.image_tag }}
18+
steps:
19+
- name: Checkout
20+
uses: actions/checkout@v4
21+
with:
22+
# Necessary to get all tags for IMAGE_TAG generation with git describe
23+
fetch-depth: 0
24+
25+
- name: Install Task
26+
uses: arduino/setup-task@v2
27+
with:
28+
version: 3.x
29+
30+
- name: Generate Image Tag
31+
id: generate-image-tag
32+
working-directory: 14-cicd/github-actions
33+
run: |
34+
image_tag=$(task generate-version-tag)
35+
echo "image_tag=$image_tag" >> $GITHUB_OUTPUT
36+
1437
build-tag-push:
1538
runs-on: ubuntu-latest
39+
needs: generate-image-tag
1640
strategy:
1741
matrix:
1842
path:
@@ -25,9 +49,6 @@ jobs:
2549
steps:
2650
- name: Checkout
2751
uses: actions/checkout@v4
28-
with:
29-
# Necessary to get all tags for IMAGE_TAG generation with git describe
30-
fetch-depth: 0
3152

3253
- name: Install Task
3354
uses: arduino/setup-task@v2
@@ -65,39 +86,28 @@ jobs:
6586

6687
- name: Build Image
6788
env:
68-
IMAGE_TAG: ${{ steps.generate-image-tag.outputs.image_tag }}
89+
IMAGE_TAG: ${{ needs.generate-image-tag.outputs.image_tag }}
6990
working-directory: ${{ matrix.path }}
7091
run: |
7192
task build-container-image-multi-arch IMAGE_TAG=${IMAGE_TAG}
7293
7394
update-tags:
7495
runs-on: ubuntu-latest
75-
needs: build-tag-push
96+
needs: [generate-image-tag, build-tag-push]
7697

7798
steps:
7899
- name: Checkout
79100
uses: actions/checkout@v4
80-
with:
81-
# Necessary to get all tags for IMAGE_TAG generation with git describe
82-
fetch-depth: 0
83101

84102
- name: Install Task
85103
uses: arduino/setup-task@v2
86104
with:
87105
version: 3.x
88106

89-
# TODO: generate once and use everywhere (to avoid race condition)
90-
- name: Generate Image Tag
91-
id: generate-image-tag
92-
working-directory: 14-cicd/github-actions
93-
run: |
94-
image_tag=$(task generate-version-tag)
95-
echo "image_tag=$image_tag" >> $GITHUB_OUTPUT
96-
97107
- name: Update Image Tags
98108
working-directory: 14-cicd/github-actions
99109
env:
100-
IMAGE_TAG: ${{ steps.generate-image-tag.outputs.image_tag }}
110+
IMAGE_TAG: ${{ needs.generate-image-tag.outputs.image_tag }}
101111
run: |
102112
# Update staging tags for push to main or release tag
103113
task update-staging-image-tags NEW_TAG=${IMAGE_TAG}
@@ -112,4 +122,4 @@ jobs:
112122
with:
113123
base: main
114124
token: ${{ secrets.DEVOPS_DIRECTIVE_KUBERNETES_COURSE_GITHUB_ACTION_PAT }}
115-
title: "Update image tags to (${{ steps.generate-image-tag.outputs.image_tag }})"
125+
title: "Update image tags to (${{ needs.generate-image-tag.outputs.image_tag }})"

0 commit comments

Comments
 (0)