1717 - uses : actions/checkout@v6
1818 - uses : nextstrain/.github/actions/shellcheck@master
1919
20- # Build multi-platform builder and final images with caching from Docker Hub
21- # and GitHub Container Registry; push to GitHub Container Registry.
22- build :
20+ vars :
2321 runs-on : ubuntu-latest
2422 steps :
25-
26- - uses : actions/checkout@v6
27-
28- - uses : actions/setup-python@v6
29- with :
30- python-version : ' >=3.8'
31-
3223 - name : Set $CACHE_DATE
3324 run : echo "CACHE_DATE=$(date --utc +%Y%m%dT%H%M%SZ)" | tee -a "$GITHUB_ENV"
3425
4233 # and hyphens.
4334 run : echo "TAG=branch-${GITHUB_REF_NAME//[^A-Za-z0-9._-]/-}" | tee -a "$GITHUB_ENV"
4435
36+ outputs :
37+ cache-date : ${{ env.CACHE_DATE }}
38+ tag : ${{ env.TAG }}
39+
40+ # Build multi-platform builder and final images with caching from Docker Hub
41+ # and GitHub Container Registry; push to GitHub Container Registry.
42+ build :
43+ needs : vars
44+ runs-on : ubuntu-latest
45+ steps :
46+
47+ - uses : actions/checkout@v6
48+
49+ - uses : actions/setup-python@v6
50+ with :
51+ python-version : ' >=3.8'
52+
4553 - uses : docker/setup-qemu-action@v3
4654
4755 # GITHUB_TOKEN is unreliable¹ so use a token from nextstrain-bot.
5361 password : ${{ secrets.GH_TOKEN_NEXTSTRAIN_BOT_MANAGE_PACKAGES }}
5462
5563 - run : ./devel/build -p linux/amd64,linux/arm64 -r ghcr.io -t "$TAG" -l logs/
64+ env :
65+ TAG : ${{ needs.vars.outputs.tag }}
66+ CACHE_DATE : ${{ needs.vars.outputs.cache-date }}
5667
5768 - if : always()
5869 name : Upload build logs as artifacts
@@ -75,13 +86,10 @@ jobs:
7586 } >> "$GITHUB_STEP_SUMMARY"
7687 done
7788
78- outputs :
79- tag : ${{ env.TAG }}
80-
8189 # Run tests with the final image from GitHub Container Registry.
8290 test :
8391 name : test (${{ matrix.platform }})
84- needs : build
92+ needs : [vars, build]
8593 runs-on : ubuntu-latest
8694 strategy :
8795 matrix :
@@ -119,21 +127,21 @@ jobs:
119127
120128 - run : make test
121129 env :
122- IMAGE : ghcr.io/nextstrain/base:${{ needs.build .outputs.tag }}
130+ IMAGE : ghcr.io/nextstrain/base:${{ needs.vars .outputs.tag }}
123131 DOCKER_DEFAULT_PLATFORM : ${{ matrix.platform }}
124132
125133 - uses : nextstrain/.github/actions/setup-nextstrain-cli@master
126134
127135 - name : Run zika-tutorial
128136 run : |
129137 git clone https://github.com/nextstrain/zika-tutorial
130- nextstrain build --image ghcr.io/nextstrain/base:${{ needs.build .outputs.tag }} zika-tutorial -F
138+ nextstrain build --image ghcr.io/nextstrain/base:${{ needs.vars .outputs.tag }} zika-tutorial -F
131139 env :
132140 DOCKER_DEFAULT_PLATFORM : ${{ matrix.platform }}
133141
134142 validate-platforms :
135143 name : Validate platforms
136- needs : build
144+ needs : [vars, build]
137145 runs-on : ubuntu-latest
138146 steps :
139147 - uses : actions/checkout@v6
@@ -147,13 +155,13 @@ jobs:
147155 password : ${{ secrets.GH_TOKEN_NEXTSTRAIN_BOT_MANAGE_PACKAGES }}
148156
149157 - name : Validate final images
150- run : ./devel/validate-platforms -r ghcr.io -t ${{ needs.build .outputs.tag }}
158+ run : ./devel/validate-platforms -r ghcr.io -t ${{ needs.vars .outputs.tag }}
151159
152160 # "Push" (copy) the builder and final images from GitHub Container Registry to
153161 # Docker Hub, where they will persist. Do this regardless of test results.
154162 push-branch :
155- if : startsWith(needs.build .outputs.tag, 'branch-') && github.event_name != 'pull_request'
156- needs : build
163+ if : startsWith(needs.vars .outputs.tag, 'branch-') && github.event_name != 'pull_request'
164+ needs : [vars, build]
157165 runs-on : ubuntu-latest
158166 steps :
159167 - uses : actions/checkout@v6
@@ -171,13 +179,13 @@ jobs:
171179 password : ${{ secrets.DOCKER_TOKEN }}
172180
173181 - name : Copy $TAG images to Docker Hub
174- run : ./devel/copy-images -i ghcr.io -o docker.io -t ${{ needs.build .outputs.tag }}
182+ run : ./devel/copy-images -i ghcr.io -o docker.io -t ${{ needs.vars .outputs.tag }}
175183
176184 # "Push" (copy) the builder and final images from GitHub Container Registry to
177185 # Docker Hub, where they will persist. Only do this if tests pass.
178186 push-build :
179- if : startsWith(needs.build .outputs.tag, 'build-')
180- needs : [build, test, validate-platforms]
187+ if : startsWith(needs.vars .outputs.tag, 'build-')
188+ needs : [vars, build, test, validate-platforms]
181189 runs-on : ubuntu-latest
182190 steps :
183191 - uses : actions/checkout@v6
@@ -196,7 +204,7 @@ jobs:
196204
197205 - name : Copy $TAG + latest images to Docker Hub
198206 run : |
199- ./devel/copy-images -i ghcr.io -o docker.io -t ${{ needs.build .outputs.tag }} -l
207+ ./devel/copy-images -i ghcr.io -o docker.io -t ${{ needs.vars .outputs.tag }} -l
200208
201209 # Run pathogen repo CI builds with the final image
202210 # This is running pathogen-repo-ci@v0 for pathogen repos that do not conform
@@ -206,7 +214,7 @@ jobs:
206214 test-pathogen-repo-ci-v0 :
207215 # Only one of push-{branch,build} runs for any given workflow run, and
208216 # we're ok with either of them.
209- needs : [build , push-branch, push-build]
217+ needs : [vars , push-branch, push-build]
210218 if : |2
211219 success()
212220 || needs.push-branch.result == 'success'
@@ -227,7 +235,7 @@ jobs:
227235 runtimes : |
228236 - docker
229237 env : |
230- NEXTSTRAIN_DOCKER_IMAGE: nextstrain/base:${{ needs.build .outputs.tag }}
238+ NEXTSTRAIN_DOCKER_IMAGE: nextstrain/base:${{ needs.vars .outputs.tag }}
231239 artifact-name : ${{ matrix.pathogen }}-outputs
232240 continue-on-error : true
233241 secrets : inherit
@@ -239,7 +247,7 @@ jobs:
239247 test-pathogen-repo-ci :
240248 # Only one of push-{branch,build} runs for any given workflow run, and
241249 # we're ok with either of them.
242- needs : [build , push-branch, push-build]
250+ needs : [vars , push-branch, push-build]
243251 if : |2
244252 success()
245253 || needs.push-branch.result == 'success'
@@ -267,15 +275,15 @@ jobs:
267275 runtimes : |
268276 - docker
269277 env : |
270- NEXTSTRAIN_DOCKER_IMAGE: nextstrain/base:${{ needs.build .outputs.tag }}
278+ NEXTSTRAIN_DOCKER_IMAGE: nextstrain/base:${{ needs.vars .outputs.tag }}
271279 artifact-name : ${{ matrix.pathogen }}-outputs
272280 continue-on-error : true
273281 secrets : inherit
274282
275283 # Delete the builder and final images from GitHub Container Registry.
276284 cleanup-registry :
277285 if : always()
278- needs : [build, test, validate-platforms, push-branch, push-build]
286+ needs : [vars, build, test, validate-platforms, push-branch, push-build]
279287 runs-on : ubuntu-latest
280288 steps :
281289 - uses : actions/checkout@v6
@@ -285,6 +293,6 @@ jobs:
285293 github-token : ${{ secrets.GH_TOKEN_NEXTSTRAIN_BOT_MANAGE_PACKAGES }}
286294 script : |
287295 const script = require('./devel/delete-from-ghcr.js');
288- const tag = "${{ needs.build .outputs.tag }}";
296+ const tag = "${{ needs.vars .outputs.tag }}";
289297 const token = "${{ secrets.GH_TOKEN_NEXTSTRAIN_BOT_MANAGE_PACKAGES }}";
290298 script({fetch, octokit: github, tag, token});
0 commit comments