@@ -2,6 +2,9 @@ name: Test
22
33on : [push, pull_request]
44
5+ permissions :
6+ contents : read
7+
58jobs :
69 pytest-conda :
710 name : pytest (conda)
@@ -191,3 +194,65 @@ jobs:
191194
192195 - name : Analyze shell scripts
193196 uses : bewuethr/shellcheck-action@v2
197+
198+ # Check that only jobs intended not to block PR auto-merge are omitted as
199+ # dependencies of the `all-pass` job below, so that whenever a job is added,
200+ # a decision is made about whether it must pass for PRs to merge.
201+ all-pass-meta :
202+ runs-on : ubuntu-latest
203+
204+ env :
205+ # List all jobs that are intended NOT to block PR auto-merge here.
206+ EXPECTED_NONBLOCKING_JOBS : |-
207+ all-pass
208+
209+ defaults :
210+ run :
211+ shell : bash
212+
213+ steps :
214+ - name : Find this workflow
215+ run : |
216+ relative_workflow_with_ref="${GITHUB_WORKFLOW_REF#"$GITHUB_REPOSITORY/"}"
217+ echo "WORKFLOW_PATH=${relative_workflow_with_ref%@*}" >> "$GITHUB_ENV"
218+
219+ - uses : actions/checkout@v4
220+ with :
221+ sparse-checkout : ${{ env.WORKFLOW_PATH }}
222+
223+ - name : Get all jobs
224+ run : yq '.jobs | keys.[]' -- "$WORKFLOW_PATH" | sort | tee all-jobs.txt
225+
226+ - name : Get blocking jobs
227+ run : yq '.jobs.all-pass.needs.[]' -- "$WORKFLOW_PATH" | sort | tee blocking-jobs.txt
228+
229+ - name : Get jobs we intend do not block
230+ run : sort <<<"$EXPECTED_NONBLOCKING_JOBS" | tee expected-nonblocking-jobs.txt
231+
232+ - name : Each job must block PRs or be declared not to
233+ run : |
234+ sort -m blocking-jobs.txt expected-nonblocking-jobs.txt |
235+ diff --color=always -U1000 - all-jobs.txt
236+
237+ all-pass :
238+ name : All tests pass
239+
240+ needs :
241+ - pytest-conda
242+ - pytest-pipenv-lock
243+ - pytest-pipenv
244+ - lint
245+ - shellcheck
246+ - all-pass-meta
247+
248+ runs-on : ubuntu-latest
249+
250+ steps :
251+ - name : Some failed
252+ if : contains(needs.*.result, 'cancelled') || contains(needs.*.result, 'failure')
253+ run : |
254+ false
255+
256+ - name : All passed
257+ run : |
258+ true
0 commit comments