Skip to content

Commit 9be72a5

Browse files
committed
ci: keep both fail-safe paths from aborting instead of refusing
Two fixes from the fourth review on #844. Both are cases where a condition the code intends to handle deliberately instead killed the step with no explanation. Read the example matrix from the default branch, not from the verified head. A Dependabot branch cut before this file existed 404s at its own head, and gh's non-zero exit aborted the whole step under set -e with a bare "Not Found" rather than the refusal every other unresolvable condition here gets. Reachable immediately: confirmed a 404 against #842's current head, and all 69 open Dependabot PRs branch from a main that predates the file. The default branch is also the right source of truth — it is repository config, the examples-only guard means the pull request cannot have changed it, and a pull_request workflow runs the merge-ref copy, so it is the matrix the run actually used. A failed read or a malformed file now refuses explicitly. Stop the selector aborting when nothing under examples/ changed. `grep -oE` exits 1 on no match and pipefail turned that into a red Verify Examples with no diagnostic, contradicting the fail-safe contract documented at the top of the script. Reproduced with an empty diff, which is reachable for a stale pull request whose change already landed through a duplicate. It now emits empty matrices and exits 0, which the `if: ... != '[]'` guards and the auto-merge job's job-count check already handle. grep is kept out of the pipeline so `|| true` tolerates only its no-match status, and the empty case is explicit rather than relying on `jq -R .` turning an empty string into [""].
1 parent 38e46fd commit 9be72a5

2 files changed

Lines changed: 37 additions & 4 deletions

File tree

.github/scripts/select-examples.sh

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,25 @@ if grep -qE '^(src/|layer/|Cargo\.toml$|Cargo\.lock$|\.github/workflows/examples
5151
exit 0
5252
fi
5353

54-
# examples/<name>/... -> <name>
55-
names="$(grep -oE '^examples/[^/]+' <<<"$changed" | cut -d/ -f2 | sort -u | jq -R . | jq -sc .)"
54+
# examples/<name>/... -> <name>. grep exits 1 when nothing matches, which pipefail
55+
# would turn into an unexplained failure of this script — so tolerate that one status,
56+
# and only that one, by keeping grep out of the pipeline below.
57+
example_paths="$(grep -oE '^examples/[^/]+' <<<"$changed" || true)"
58+
59+
# Reachable with an empty diff: a stale pull request whose change already landed
60+
# through a duplicate (#804 and #811 carry an identical update set), or a re-run after
61+
# the commit merged. "Select nothing" is the documented contract here, not "fail" —
62+
# the `if: ... != '[]'` guards in examples.yaml skip the test jobs, and the auto-merge
63+
# workflow refuses a run with no successful test job.
64+
if [[ -z "$example_paths" ]]; then
65+
echo "No example changed: nothing to verify."
66+
for kind in image zip stream; do
67+
echo "$kind=[]" >>"$GITHUB_OUTPUT"
68+
done
69+
exit 0
70+
fi
71+
72+
names="$(cut -d/ -f2 <<<"$example_paths" | sort -u | jq -R . | jq -sc .)"
5673
echo "Changed examples: $names"
5774

5875
for kind in image zip stream; do

.github/workflows/dependabot-automerge.yaml

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,8 +93,24 @@ jobs:
9393
# example while never exercising the second. Require coverage for every
9494
# changed example, read at the verified commit.
9595
changed_examples=$(cut -d/ -f2 <<<"$files" | sort -u)
96-
covered=$(gh api "repos/$REPO/contents/.github/example-matrix.json?ref=$HEAD_SHA" \
97-
-H 'Accept: application/vnd.github.raw' -q '[.[][].name] | unique | .[]' | sort -u)
96+
97+
# Read the matrix from the default branch, not from $HEAD_SHA: a Dependabot
98+
# branch cut before this file existed 404s at its own head, and gh's non-zero
99+
# exit would abort the step with a bare "Not Found" instead of refusing
100+
# deliberately like every other unresolvable condition here. The default
101+
# branch is also the correct source of truth — this is repository config, the
102+
# examples-only guard above means the pull request cannot have changed it, and
103+
# a pull_request workflow runs the merge-ref copy anyway, so this is the matrix
104+
# the run actually used.
105+
if ! matrix_json=$(gh api "repos/$REPO/contents/.github/example-matrix.json" \
106+
-H 'Accept: application/vnd.github.raw'); then
107+
echo "Could not read .github/example-matrix.json; refusing to merge."
108+
exit 0
109+
fi
110+
if ! covered=$(jq -r '[.[][].name] | unique | .[]' <<<"$matrix_json" | sort -u); then
111+
echo "Could not parse .github/example-matrix.json; refusing to merge."
112+
exit 0
113+
fi
98114
uncovered=$(comm -23 <(printf '%s\n' "$changed_examples") <(printf '%s\n' "$covered") || true)
99115
if [[ -n "$uncovered" ]]; then
100116
echo "PR #$PR_NUMBER changes examples with no build-and-boot coverage:"

0 commit comments

Comments
 (0)