Skip to content

Commit 570a20c

Browse files
committed
workflows: skip download job entirely when start emits the placeholder
The {name:none,...} placeholder existed to keep strategy.matrix non-empty when there's no work, with a comment promising the downstream job would 'skip entries with name=none'. The skip was never implemented — every step would try to source os/external/${{ matrix.name }}.conf, which fails on os/external/none.conf because no such file exists. Job-level `if: matrix.name != 'none'` doesn't work either: matrix.* isn't available at job-level if-evaluation (it's expanded after). Fix: thread a `has_work` boolean output from the start job and gate the download job on it via a job-level `if:` (needs.* outputs ARE available there). Set has_work='false' in both placeholder paths (no matrix entries at all, OR this chunk's slice happens to be empty). The placeholder still ships to keep strategy.matrix valid, but the job is skipped before the matrix expands so no runner is allocated and no source attempt is made.
1 parent f16304a commit 570a20c

1 file changed

Lines changed: 28 additions & 2 deletions

File tree

.github/workflows/infrastructure-download-external.yml

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,13 @@ jobs:
196196
name: "Mirror"
197197
outputs:
198198
matrix: ${{steps.lists.outputs.matrix}}
199+
# 'true' when the matrix has real work; 'false' when start
200+
# only emitted the {name:none,...} placeholder (empty slice
201+
# for this chunk, or no actionable changes at all). The
202+
# download job gates on this via a job-level `if:` so an
203+
# empty chunk skips the entire matrix expansion instead of
204+
# trying to source os/external/none.conf.
205+
has_work: ${{steps.lists.outputs.has_work}}
199206
steps:
200207

201208
- name: Fix workspace ownership
@@ -367,10 +374,19 @@ jobs:
367374
# Check if matrix is valid
368375
MATRIX_COUNT=$(echo "${MATRIX_JSON}" | jq '.include | length')
369376
377+
# has_work tracks whether the resulting matrix has any real
378+
# entries vs the {name:none,...} placeholder. The download
379+
# job's job-level `if:` reads this output and skips the
380+
# whole matrix expansion when has_work='false', avoiding the
381+
# source of os/external/none.conf that would otherwise hard-
382+
# fail on the placeholder entry.
383+
HAS_WORK="true"
384+
370385
# Handle empty matrix - add a dummy entry that will be skipped
371386
if [[ "${MATRIX_COUNT}" -eq 0 ]]; then
372387
echo "::warning::No matrix entries generated, adding placeholder" >&2
373388
MATRIX_JSON_COMPACTED='{"include":[{"name":"none","arch":"amd64","release":"bookworm"}]}'
389+
HAS_WORK="false"
374390
else
375391
# Chunk the matrix so each invocation keeps strategy.matrix
376392
# below GitHub Actions' 256-entry cap. Callers that don't
@@ -415,20 +431,30 @@ jobs:
415431
SLICE_COUNT=$(echo "${SLICED}" | jq '.include | length')
416432
echo "::notice::chunk ${CHUNK_INDEX}/${CHUNK_COUNT}: ${SLICE_COUNT} of ${MATRIX_COUNT} entries" >&2
417433
418-
# Empty slice needs a placeholder for the downstream job to
419-
# run at all — it'll skip entries with name=none.
434+
# Empty slice still needs a placeholder so strategy.matrix
435+
# is a valid (non-empty) value — but we set HAS_WORK=false
436+
# so the download job's job-level `if:` skips it before
437+
# the matrix even expands.
420438
if [[ "${SLICE_COUNT}" -eq 0 ]]; then
421439
MATRIX_JSON_COMPACTED='{"include":[{"name":"none","arch":"amd64","release":"bookworm"}]}'
440+
HAS_WORK="false"
422441
else
423442
MATRIX_JSON_COMPACTED="${SLICED}"
424443
fi
425444
echo "::debug::Compacted matrix JSON: ${MATRIX_JSON_COMPACTED}" >&2
426445
fi
427446
428447
echo "matrix=${MATRIX_JSON_COMPACTED}" >> $GITHUB_OUTPUT
448+
echo "has_work=${HAS_WORK}" >> $GITHUB_OUTPUT
429449
430450
download:
431451
needs: [start]
452+
# Skip the whole job when start emitted a placeholder matrix
453+
# (no work for this chunk, or no actionable changes at all).
454+
# Job-level `if:` cannot reference `matrix.*` because matrix
455+
# is expanded after if-evaluation; using a needs.* output works
456+
# because those resolve at job-graph time.
457+
if: needs.start.outputs.has_work == 'true'
432458
outputs:
433459
project: ${{steps.make.outputs.project}}
434460
strategy:

0 commit comments

Comments
 (0)