Skip to content

Commit 806b87f

Browse files
committed
split config so downstream jobs may start earlier
Signed-off-by: Mitchell <mitch_dz@hotmail.com>
1 parent 67c7c98 commit 806b87f

File tree

2 files changed

+62
-31
lines changed

2 files changed

+62
-31
lines changed

.github/workflows/ci.yml

Lines changed: 57 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@ jobs:
9999
environment: ghcr-ci
100100
# needed only for the cloudposse GitHub action
101101
matrix_key: ${{ matrix.platform }}-${{ matrix.toolchain }}
102+
matrix_step_name: dev_environment_devdeps
102103

103104
wheeldeps:
104105
name: Load wheel dependencies
@@ -127,6 +128,7 @@ jobs:
127128
environment: ghcr-ci
128129
# needed only for the cloudposse GitHub action
129130
matrix_key: ${{ matrix.platform }}-cu${{ matrix.cuda_version }}-python
131+
matrix_step_name: dev_environment_wheeldeps
130132

131133
source_build:
132134
name: Load source build cache
@@ -154,28 +156,49 @@ jobs:
154156
environment: ghcr-ci
155157
# needed only for the cloudposse GitHub action
156158
matrix_key: ${{ matrix.platform }}-cu${{ matrix.cuda_version }}-installer
159+
matrix_step_name: dev_environment_source_build
157160

158-
# This job is needed only when using the cloudposse GitHub action to read
159-
# the output of a matrix job. This is a workaround due to current GitHub
160-
# limitations that may not be needed if the work started here concludes:
161-
# https://github.com/actions/runner/pull/2477
162-
config:
163-
name: Configure build
161+
# Split config jobs so downstream jobs can start as soon as their deps are ready
162+
# (no need to wait for all 14 dependency jobs before any build/test runs).
163+
config_devdeps:
164+
name: Configure build (devdeps)
164165
runs-on: ubuntu-latest
165-
needs: [devdeps, wheeldeps, source_build]
166+
needs: devdeps
167+
outputs:
168+
json: "${{ steps.read_json.outputs.result }}"
169+
steps:
170+
- uses: cloudposse/github-action-matrix-outputs-read@1.0.0
171+
id: read_json
172+
with:
173+
matrix-step-name: dev_environment_devdeps
166174

175+
config_wheeldeps:
176+
name: Configure build (wheeldeps)
177+
runs-on: ubuntu-latest
178+
needs: wheeldeps
167179
outputs:
168180
json: "${{ steps.read_json.outputs.result }}"
181+
steps:
182+
- uses: cloudposse/github-action-matrix-outputs-read@1.0.0
183+
id: read_json
184+
with:
185+
matrix-step-name: dev_environment_wheeldeps
169186

187+
config_source_build:
188+
name: Configure build (source_build)
189+
runs-on: ubuntu-latest
190+
needs: source_build
191+
outputs:
192+
json: "${{ steps.read_json.outputs.result }}"
170193
steps:
171194
- uses: cloudposse/github-action-matrix-outputs-read@1.0.0
172195
id: read_json
173196
with:
174-
matrix-step-name: dev_environment
197+
matrix-step-name: dev_environment_source_build
175198

176199
build_and_test:
177200
name: Build and test
178-
needs: config
201+
needs: config_devdeps
179202
strategy:
180203
matrix:
181204
platform: [amd64, arm64]
@@ -191,14 +214,14 @@ jobs:
191214
with:
192215
platform: linux/${{ matrix.platform }}
193216
mpi: ${{ matrix.mpi }}
194-
devdeps_image: ${{ fromJson(needs.config.outputs.json).image_hash[format('{0}-{1}', matrix.platform, matrix.toolchain)] }}
195-
devdeps_cache: ${{ fromJson(needs.config.outputs.json).cache_key[format('{0}-{1}', matrix.platform, matrix.toolchain)] }}
196-
devdeps_archive: ${{ fromJson(needs.config.outputs.json).tar_archive[format('{0}-{1}', matrix.platform, matrix.toolchain)] }}
217+
devdeps_image: ${{ fromJson(needs.config_devdeps.outputs.json).image_hash[format('{0}-{1}', matrix.platform, matrix.toolchain)] }}
218+
devdeps_cache: ${{ fromJson(needs.config_devdeps.outputs.json).cache_key[format('{0}-{1}', matrix.platform, matrix.toolchain)] }}
219+
devdeps_archive: ${{ fromJson(needs.config_devdeps.outputs.json).tar_archive[format('{0}-{1}', matrix.platform, matrix.toolchain)] }}
197220
export_environment: ${{ github.event_name == 'workflow_dispatch' && inputs.export_environment }}
198221

199222
gen_code_coverage:
200223
name: Gen code coverage
201-
needs: config
224+
needs: config_devdeps
202225
strategy:
203226
matrix:
204227
platform: [amd64]
@@ -209,14 +232,14 @@ jobs:
209232
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
210233
with:
211234
platform: linux/${{ matrix.platform }}
212-
devdeps_image: ${{ fromJson(needs.config.outputs.json).image_hash[format('{0}-{1}', matrix.platform, matrix.toolchain)] }}
213-
devdeps_cache: ${{ fromJson(needs.config.outputs.json).cache_key[format('{0}-{1}', matrix.platform, matrix.toolchain)] }}
214-
devdeps_archive: ${{ fromJson(needs.config.outputs.json).tar_archive[format('{0}-{1}', matrix.platform, matrix.toolchain)] }}
235+
devdeps_image: ${{ fromJson(needs.config_devdeps.outputs.json).image_hash[format('{0}-{1}', matrix.platform, matrix.toolchain)] }}
236+
devdeps_cache: ${{ fromJson(needs.config_devdeps.outputs.json).cache_key[format('{0}-{1}', matrix.platform, matrix.toolchain)] }}
237+
devdeps_archive: ${{ fromJson(needs.config_devdeps.outputs.json).tar_archive[format('{0}-{1}', matrix.platform, matrix.toolchain)] }}
215238
export_environment: ${{ github.event_name == 'workflow_dispatch' && inputs.export_environment }}
216239

217240
docker_image:
218241
name: Create Docker images
219-
needs: config
242+
needs: config_devdeps
220243
strategy:
221244
matrix:
222245
platform: [amd64, arm64]
@@ -227,14 +250,14 @@ jobs:
227250
DOCKERHUB_READONLY_TOKEN: ${{ secrets.DOCKERHUB_READONLY_TOKEN }}
228251
with:
229252
platforms: linux/${{ matrix.platform }}
230-
devdeps_image: ${{ fromJson(needs.config.outputs.json).image_hash[format('{0}-gcc11', matrix.platform)] }}
231-
devdeps_cache: ${{ fromJson(needs.config.outputs.json).cache_key[format('{0}-gcc11', matrix.platform)] }}
232-
devdeps_archive: ${{ fromJson(needs.config.outputs.json).tar_archive[format('{0}-gcc11', matrix.platform)] }}
253+
devdeps_image: ${{ fromJson(needs.config_devdeps.outputs.json).image_hash[format('{0}-gcc11', matrix.platform)] }}
254+
devdeps_cache: ${{ fromJson(needs.config_devdeps.outputs.json).cache_key[format('{0}-gcc11', matrix.platform)] }}
255+
devdeps_archive: ${{ fromJson(needs.config_devdeps.outputs.json).tar_archive[format('{0}-gcc11', matrix.platform)] }}
233256
environment: ghcr-ci
234257

235258
python_wheels:
236259
name: Create Python wheels
237-
needs: config
260+
needs: config_wheeldeps
238261
strategy:
239262
matrix:
240263
platform: [amd64, arm64]
@@ -249,9 +272,9 @@ jobs:
249272
platform: linux/${{ matrix.platform }}
250273
python_version: ${{ matrix.python_version }}
251274
cuda_version: ${{ matrix.cuda_version }}
252-
devdeps_image: ${{ fromJson(needs.config.outputs.json).image_hash[format('{0}-cu{1}-python', matrix.platform, matrix.cuda_version)] }}
253-
devdeps_cache: ${{ fromJson(needs.config.outputs.json).cache_key[format('{0}-cu{1}-python', matrix.platform, matrix.cuda_version)] }}
254-
devdeps_archive: ${{ fromJson(needs.config.outputs.json).tar_archive[format('{0}-cu{1}-python', matrix.platform, matrix.cuda_version)] }}
275+
devdeps_image: ${{ fromJson(needs.config_wheeldeps.outputs.json).image_hash[format('{0}-cu{1}-python', matrix.platform, matrix.cuda_version)] }}
276+
devdeps_cache: ${{ fromJson(needs.config_wheeldeps.outputs.json).cache_key[format('{0}-cu{1}-python', matrix.platform, matrix.cuda_version)] }}
277+
devdeps_archive: ${{ fromJson(needs.config_wheeldeps.outputs.json).tar_archive[format('{0}-cu{1}-python', matrix.platform, matrix.cuda_version)] }}
255278

256279
python_metapackages:
257280
name: Create Python metapackages
@@ -265,7 +288,7 @@ jobs:
265288

266289
binaries:
267290
name: Create CUDA Quantum installer
268-
needs: [metadata, config]
291+
needs: [metadata, config_source_build]
269292
strategy:
270293
matrix:
271294
platform: [amd64, arm64]
@@ -280,12 +303,12 @@ jobs:
280303
platform_base_image: ${{ fromJson(needs.metadata.outputs.platform_config)[format('{0}', matrix.platform)].minimal_base_image }}
281304
build_config_id: cu${{ matrix.cuda_version }}-llvm
282305
cuda_version: ${{ matrix.cuda_version }}
283-
build_cache: ${{ fromJson(needs.config.outputs.json).build_cache[format('{0}-cu{1}-installer', matrix.platform, matrix.cuda_version)] }}
306+
build_cache: ${{ fromJson(needs.config_source_build.outputs.json).build_cache[format('{0}-cu{1}-installer', matrix.platform, matrix.cuda_version)] }}
284307

285308
clean_up:
286309
name: Prepare cache clean-up
287310
runs-on: ubuntu-latest
288-
needs: [metadata, config, build_and_test, docker_image, wheeldeps, python_wheels]
311+
needs: [metadata, config_devdeps, config_wheeldeps, config_source_build, build_and_test, docker_image, wheeldeps, python_wheels]
289312
# We need to clean up even if the workflow is cancelled or fails.
290313
if: always()
291314

@@ -294,9 +317,13 @@ jobs:
294317
id: workflow_inputs
295318
run: |
296319
set -e
297-
key_matrix='${{ needs.config.outputs.json }}'
298-
keys=`echo $key_matrix | jq '.cache_key | to_entries | .[].value' --raw-output`
299-
echo "$keys" >> cache_keys.txt
320+
touch cache_keys.txt
321+
key_matrix='${{ needs.config_devdeps.outputs.json }}'
322+
[ -n "$key_matrix" ] && [ "$key_matrix" != "{}" ] && echo "$key_matrix" | jq -r '.cache_key | to_entries | .[].value' >> cache_keys.txt || true
323+
key_matrix='${{ needs.config_wheeldeps.outputs.json }}'
324+
[ -n "$key_matrix" ] && [ "$key_matrix" != "{}" ] && echo "$key_matrix" | jq -r '.cache_key | to_entries | .[].value' >> cache_keys.txt || true
325+
key_matrix='${{ needs.config_source_build.outputs.json }}'
326+
[ -n "$key_matrix" ] && [ "$key_matrix" != "{}" ] && echo "$key_matrix" | jq -r '.cache_key | to_entries | .[].value' >> cache_keys.txt || true
300327
301328
echo "pr-number: ${{ needs.metadata.outputs.pull_request_number }}" >> metadata.txt
302329
echo "pr-base: ${{ needs.metadata.outputs.pull_request_base }}" >> metadata.txt

.github/workflows/dev_environment.yml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,10 @@ on:
5656
required: false
5757
type: string
5858
description: The key to use for the json entry in the output of the cloudposse GitHub action (only needed when the workflow runs as part of a matrix job).
59+
matrix_step_name:
60+
required: false
61+
type: string
62+
description: Override the step name used when writing matrix outputs (enables split config so downstream jobs can start as soon as their deps are ready).
5963
environment:
6064
required: false
6165
type: string
@@ -465,7 +469,7 @@ jobs:
465469
- uses: cloudposse/github-action-matrix-outputs-write@1.0.0
466470
id: write_json
467471
with:
468-
matrix-step-name: ${{ inputs.matrix_key && 'dev_environment' }}
472+
matrix-step-name: ${{ inputs.matrix_step_name || (inputs.matrix_key && 'dev_environment') }}
469473
matrix-key: ${{ inputs.matrix_key }}
470474
outputs: |
471475
image_hash: ${{ needs.build.outputs.image_hash }}

0 commit comments

Comments
 (0)