Skip to content

Commit 594438e

Browse files
committed
fix: the generated gate fails when a needed job was skipped
The All checks passed job failed only on failure or cancelled, so a job that ended skipped counted as passed. Today that takes a failed lint, which already fails the gate, but an if: or a paths filter added to the test jobs later would turn "the tests did not run" into a green required check. Every needed job now has to succeed. A job skipped by design is named in MAY_SKIP, and only those may end skipped. The template's own CI already requires success from every job; the generated one now does too, without breaking a library that skips a job on purpose. Closes #16
1 parent 8ebf45d commit 594438e

1 file changed

Lines changed: 14 additions & 3 deletions

File tree

‎template/.github/workflows/ci.yml.jinja‎

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,17 +56,28 @@ jobs:
5656
set -e
5757
test $STATUS -eq 0 -o $STATUS -eq 5
5858

59-
# Sentinel job — use this as the single required status check in branch protection.
59+
# Sentinel job — the single required status check in the master ruleset. A job
60+
# counts only when it succeeded: "skipped" means the work did not happen. A job
61+
# skipped by design (one that runs on pull requests only, say) goes in MAY_SKIP
62+
# by its job id, and only those may end skipped.
6063
all-checks-passed:
6164
name: All checks passed
6265
if: always()
6366
needs: [lint, test-unit, test-integration]
6467
runs-on: ubuntu-latest
6568
steps:
6669
- name: Check all jobs succeeded
70+
env:
71+
NEEDS: ${% raw %}{{ toJSON(needs) }}{% endraw %}
72+
MAY_SKIP: '[]'
6773
run: |
68-
if [[ "${% raw %}{{ contains(needs.*.result, 'failure') || contains(needs.*.result, 'cancelled') }}{% endraw %}" == "true" ]]; then
69-
echo "One or more required checks failed."
74+
NOT_PASSED=$(jq -r --argjson skip "$MAY_SKIP" '
75+
to_entries[]
76+
| select((.value.result == "success" or (.value.result == "skipped" and (.key | IN($skip[])))) | not)
77+
| "\(.key): \(.value.result)"' <<< "$NEEDS")
78+
if [ -n "$NOT_PASSED" ]; then
79+
echo "Not passed:"
80+
echo "$NOT_PASSED"
7081
exit 1
7182
fi
7283
echo "All checks passed."

0 commit comments

Comments
 (0)