Skip to content

Commit c2ee06a

Browse files
committed
fix(ci): act on a Unit Tests verdict only for the commit it covers (#1643)
Conda Update, Vendor Update and GitHub Pages check out github.sha, main's tip when the workflow_run is raised, not the commit the completed Unit Tests run verified. In a merge wave an older commit's success authorised work on an untested tip: Conda Update 38325136710 bumped 2e941bb under 9083163's verdict. - Add a `verdict` job to each, running util/verdict_covers_checkout.py. It accepts the tip when it is the verified commit, or that commit plus github-actions[bot] commits to conda/build and conda/requirements.txt only. The acting job's workflow_run clause now also needs `verified == 'true'`. - Key the workflow-level concurrency group on the verdict's sha for a workflow_run, so a stale run that skips cannot cancel a pending run whose verdict matches. Other events keep their groups. - workflows.rst: describe the check and what it leaves uncovered, and renumber the three `uses:` citations. tests/project/test_workflow_run_verdict.py: 25 pass. With origin/main's three workflows swapped in, 9 fail (failures=22, subtests counted); with the verdict checkout at fetch-depth 1, 1 fails in all three workflows. A merge whose side branch runs past the shallow checkout is refused with exit 0, not a crash. Its throwaway repos run no git maintenance: since git 2.54 a commit's detached auto repack raced their cleanup ("Directory not empty", git 2.55.0). Closes #1643
1 parent b375656 commit c2ee06a

6 files changed

Lines changed: 813 additions & 22 deletions

File tree

‎.github/workflows/cron-conda.yml‎

Lines changed: 51 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,18 @@ on:
2323
# publishes to Anaconda, and letting two runs upload the same version
2424
# concurrently is worse than dropping a superseded duplicate.
2525
#
26+
# A `workflow_run` is keyed on the commit `Unit Tests` verified instead (#1643).
27+
# Each `Unit Tests` completion raises a run here, and one whose verdict is for an
28+
# older commit only runs `verdict` and skips -- but in a shared group it would
29+
# still displace a pending run whose verdict matches, since "any existing pending
30+
# job or workflow in the same concurrency group will be canceled" (GitHub,
31+
# "Control the concurrency of workflows and jobs").
32+
#
2633
# Note this group is not what serialises the repository writes -- the
2734
# `conda-update` job below carries its own `repository-maintenance` group, shared
2835
# with cron-vendor, and that is what actually stops two jobs committing at once.
2936
concurrency:
30-
group: conda-update-${{ github.ref }}
37+
group: conda-update-${{ github.event.workflow_run.head_sha || github.ref }}
3138
cancel-in-progress: false
3239

3340
jobs:
@@ -44,18 +51,54 @@ jobs:
4451
with:
4552
gate-only: true
4653

54+
# #1643: `github.sha`, which every checkout here takes, is main's tip when the
55+
# `workflow_run` was raised -- not the commit the completed `Unit Tests` run
56+
# verified, and in a merge wave the two differ. This job compares them with
57+
# util/verdict_covers_checkout.py, whose docstring gives the rule, and the job
58+
# below acts on a `workflow_run` only when `verified` is 'true'. Its `if:` is
59+
# that job's `workflow_run` clause, so a run raised by a pull request's or a
60+
# failed `Unit Tests` run still concludes `skipped`, as before.
61+
verdict:
62+
name: Verdict covers this commit
63+
if: >-
64+
github.event_name == 'workflow_run' &&
65+
github.event.workflow_run.conclusion == 'success' &&
66+
github.event.workflow_run.event == 'push' &&
67+
github.event.workflow_run.head_branch == 'main'
68+
runs-on: ubuntu-latest
69+
timeout-minutes: 5
70+
permissions:
71+
contents: read
72+
outputs:
73+
verified: ${{ steps.verdict.outputs.verified }}
74+
steps:
75+
# The default ref, as the job below uses, so both see the same `github.sha`.
76+
# Twenty commits leaves room for the bot commits the rule accepts; a verdict
77+
# further back is not found, and so not accepted.
78+
- uses: actions/checkout@v7
79+
with:
80+
fetch-depth: 20
81+
persist-credentials: false
82+
83+
- name: Compare the verified commit with this checkout
84+
id: verdict
85+
env:
86+
VERDICT_SHA: ${{ github.event.workflow_run.head_sha }}
87+
run: python3 util/verdict_covers_checkout.py
88+
4789
conda-update:
4890
name: Update requirements.txt
4991
runs-on: ubuntu-latest
50-
needs: [ unit-tests ]
92+
needs: [ unit-tests, verdict ]
5193
# `needs` cannot itself be conditional, so a skipped gate (`workflow_run`)
5294
# has to be accepted explicitly -- by default this job would inherit the
5395
# skip. `!cancelled()` rather than `always()` so that cancelling the run
5496
# still cancels the update; a gate that actually failed still blocks.
5597
#
5698
# The `workflow_run` clause is the real gate for a push to main now: it
57-
# reads the verdict `Unit Tests` already reached for this exact commit
58-
# instead of re-running it. `.event == 'push'` and `.head_branch == 'main'`
99+
# reads the verdict `Unit Tests` already reached instead of re-running it,
100+
# and `verdict` says whether that verdict covers the commit checked out
101+
# below (#1643). `.event == 'push'` and `.head_branch == 'main'`
59102
# both matter -- `workflow_run` fires for *every* completion of that
60103
# workflow, including one triggered by a pull request, and without this
61104
# check a green PR would upload a conda distribution built from that PR's
@@ -65,7 +108,8 @@ jobs:
65108
(github.event_name != 'workflow_run' || (
66109
github.event.workflow_run.conclusion == 'success' &&
67110
github.event.workflow_run.event == 'push' &&
68-
github.event.workflow_run.head_branch == 'main'
111+
github.event.workflow_run.head_branch == 'main' &&
112+
needs.verdict.outputs.verified == 'true'
69113
))
70114
concurrency:
71115
group: repository-maintenance
@@ -90,7 +134,8 @@ jobs:
90134
# default-branch commit removes the pattern outright rather than
91135
# relying on CodeQL tracing through the guard. The push below rebases
92136
# onto main's actual tip before writing regardless, so pinning to the
93-
# exact tested sha would have bought nothing here either.
137+
# exact tested sha would have bought nothing here either. Whether this
138+
# commit is one that verdict covers is `verdict`'s question (#1643).
94139
#
95140
# The push below re-points `origin` at an SSH remote and authenticates
96141
# with the loaded deploy key, not with this checkout's credential --

‎.github/workflows/cron-vendor.yml‎

Lines changed: 51 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,18 @@ permissions: {}
2929
# picks the registries up again, whereas a dropped validation run means a commit
3030
# nobody ever checked.
3131
#
32+
# A `workflow_run` is keyed on the commit `Unit Tests` verified instead (#1643).
33+
# Each `Unit Tests` completion raises a run here, and one whose verdict is for an
34+
# older commit only runs `verdict` and skips -- but in a shared group it would
35+
# still displace a pending run whose verdict matches, since "any existing pending
36+
# job or workflow in the same concurrency group will be canceled" (GitHub,
37+
# "Control the concurrency of workflows and jobs").
38+
#
3239
# Note this group is not what serialises the repository writes -- the
3340
# `vendor-update` job below carries its own `repository-maintenance` group, shared
3441
# with cron-conda, and that is what actually stops two jobs committing at once.
3542
concurrency:
36-
group: vendor-update-${{ github.ref }}
43+
group: vendor-update-${{ github.event.workflow_run.head_sha || github.ref }}
3744
cancel-in-progress: false
3845

3946
jobs:
@@ -50,17 +57,53 @@ jobs:
5057
with:
5158
gate-only: true
5259

60+
# #1643: `github.sha`, which every checkout here takes, is main's tip when the
61+
# `workflow_run` was raised -- not the commit the completed `Unit Tests` run
62+
# verified, and in a merge wave the two differ. This job compares them with
63+
# util/verdict_covers_checkout.py, whose docstring gives the rule, and the job
64+
# below acts on a `workflow_run` only when `verified` is 'true'. Its `if:` is
65+
# that job's `workflow_run` clause, so a run raised by a pull request's or a
66+
# failed `Unit Tests` run still concludes `skipped`, as before.
67+
verdict:
68+
name: Verdict covers this commit
69+
if: >-
70+
github.event_name == 'workflow_run' &&
71+
github.event.workflow_run.conclusion == 'success' &&
72+
github.event.workflow_run.event == 'push' &&
73+
github.event.workflow_run.head_branch == 'main'
74+
runs-on: ubuntu-latest
75+
timeout-minutes: 5
76+
permissions:
77+
contents: read
78+
outputs:
79+
verified: ${{ steps.verdict.outputs.verified }}
80+
steps:
81+
# The default ref, as the job below uses, so both see the same `github.sha`.
82+
# Twenty commits leaves room for the bot commits the rule accepts; a verdict
83+
# further back is not found, and so not accepted.
84+
- uses: actions/checkout@v7
85+
with:
86+
fetch-depth: 20
87+
persist-credentials: false
88+
89+
- name: Compare the verified commit with this checkout
90+
id: verdict
91+
env:
92+
VERDICT_SHA: ${{ github.event.workflow_run.head_sha }}
93+
run: python3 util/verdict_covers_checkout.py
94+
5395
vendor-update:
5496
runs-on: macos-latest
55-
needs: [ unit-tests ]
97+
needs: [ unit-tests, verdict ]
5698
# `needs` cannot itself be conditional, so a skipped gate (`workflow_run`)
5799
# has to be accepted explicitly -- by default this job would inherit the
58100
# skip. `!cancelled()` rather than `always()` so that cancelling the run
59101
# still cancels the update; a gate that actually failed still blocks.
60102
#
61103
# The `workflow_run` clause is the real gate for a push to main now: it
62-
# reads the verdict `Unit Tests` already reached for this exact commit
63-
# instead of re-running it. `.event == 'push'` and `.head_branch == 'main'`
104+
# reads the verdict `Unit Tests` already reached instead of re-running it,
105+
# and `verdict` says whether that verdict covers the commit checked out
106+
# below (#1643). `.event == 'push'` and `.head_branch == 'main'`
64107
# both matter -- `workflow_run` fires for *every* completion of that
65108
# workflow, including one triggered by a pull request, and without this
66109
# check a green PR would push a vendor-registry commit from that PR's tree.
@@ -69,7 +112,8 @@ jobs:
69112
(github.event_name != 'workflow_run' || (
70113
github.event.workflow_run.conclusion == 'success' &&
71114
github.event.workflow_run.event == 'push' &&
72-
github.event.workflow_run.head_branch == 'main'
115+
github.event.workflow_run.head_branch == 'main' &&
116+
needs.verdict.outputs.verified == 'true'
73117
))
74118
concurrency:
75119
group: repository-maintenance
@@ -94,7 +138,8 @@ jobs:
94138
# default-branch commit removes the pattern outright rather than
95139
# relying on CodeQL tracing through the guard. The push below rebases
96140
# onto main's actual tip before writing regardless, so pinning to the
97-
# exact tested sha would have bought nothing here either.
141+
# exact tested sha would have bought nothing here either. Whether this
142+
# commit is one that verdict covers is `verdict`'s question (#1643).
98143
# The push below re-points `origin` at an SSH remote and authenticates
99144
# with the loaded deploy key, not with this checkout's credential --
100145
# so there is nothing here for a persisted token to do, and one less

‎.github/workflows/deploy-pages.yml‎

Lines changed: 52 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,16 @@ permissions:
2929
# the newer one publishes, and deploying the older commit's docs after the newer
3030
# ones would actively be wrong. GitHub Pages also permits only one live
3131
# deployment, so serialising here is a requirement rather than a saving.
32+
#
33+
# A `workflow_run` is keyed on the commit `Unit Tests` verified instead (#1643).
34+
# One whose verdict is for an older commit only runs `verdict` and skips, and in
35+
# the shared group it would still displace a pending run whose verdict matches,
36+
# since "any existing pending job or workflow in the same concurrency group will
37+
# be canceled" (GitHub, "Control the concurrency of workflows and jobs"). The
38+
# coalescing and serialising above then happen in `deploy-pages`' own `ci-`
39+
# group, which only a run whose verdict covers its checkout reaches.
3240
concurrency:
33-
group: pages-${{ github.ref }}
41+
group: pages-${{ github.event.workflow_run.head_sha || github.ref }}
3442
cancel-in-progress: ${{ github.event_name == 'pull_request' }}
3543

3644
jobs:
@@ -48,17 +56,53 @@ jobs:
4856
with:
4957
gate-only: true
5058

59+
# #1643: `github.sha`, which every checkout here takes, is main's tip when the
60+
# `workflow_run` was raised -- not the commit the completed `Unit Tests` run
61+
# verified, and in a merge wave the two differ. This job compares them with
62+
# util/verdict_covers_checkout.py, whose docstring gives the rule, and the job
63+
# below acts on a `workflow_run` only when `verified` is 'true'. Its `if:` is
64+
# that job's `workflow_run` clause, so a run raised by a pull request's or a
65+
# failed `Unit Tests` run still concludes `skipped`, as before.
66+
verdict:
67+
name: Verdict covers this commit
68+
if: >-
69+
github.event_name == 'workflow_run' &&
70+
github.event.workflow_run.conclusion == 'success' &&
71+
github.event.workflow_run.event == 'push' &&
72+
github.event.workflow_run.head_branch == 'main'
73+
runs-on: ubuntu-latest
74+
timeout-minutes: 5
75+
permissions:
76+
contents: read
77+
outputs:
78+
verified: ${{ steps.verdict.outputs.verified }}
79+
steps:
80+
# The default ref, as the job below uses, so both see the same `github.sha`.
81+
# Twenty commits leaves room for the bot commits the rule accepts; a verdict
82+
# further back is not found, and so not accepted.
83+
- uses: actions/checkout@v7
84+
with:
85+
fetch-depth: 20
86+
persist-credentials: false
87+
88+
- name: Compare the verified commit with this checkout
89+
id: verdict
90+
env:
91+
VERDICT_SHA: ${{ github.event.workflow_run.head_sha }}
92+
run: python3 util/verdict_covers_checkout.py
93+
5194
deploy-pages:
52-
needs: [ unit-tests ]
95+
needs: [ unit-tests, verdict ]
5396
# `needs` cannot itself be conditional, so a skipped gate (pull requests,
5497
# and now `workflow_run`) has to be accepted explicitly -- by default this
5598
# job would inherit the skip. `!cancelled()` rather than `always()` so that
5699
# cancelling the run still cancels the docs build; a gate that actually
57100
# failed still blocks.
58101
#
59102
# The `workflow_run` clause is the real gate for a push to main now: it
60-
# reads the verdict `Unit Tests` already reached for this exact commit
61-
# instead of re-running it. `.event == 'push'` and `.head_branch == 'main'`
103+
# reads the verdict `Unit Tests` already reached instead of re-running it,
104+
# and `verdict` says whether that verdict covers the commit checked out
105+
# below (#1643). `.event == 'push'` and `.head_branch == 'main'`
62106
# both matter -- `workflow_run` fires for *every* completion of that
63107
# workflow, including one triggered by a pull request, and without this
64108
# check a green PR would publish docs from that PR's tree.
@@ -67,7 +111,8 @@ jobs:
67111
(github.event_name != 'workflow_run' || (
68112
github.event.workflow_run.conclusion == 'success' &&
69113
github.event.workflow_run.event == 'push' &&
70-
github.event.workflow_run.head_branch == 'main'
114+
github.event.workflow_run.head_branch == 'main' &&
115+
needs.verdict.outputs.verified == 'true'
71116
))
72117
concurrency: ci-${{ github.ref }} # Recommended if you intend to make multiple deployments in quick succession.
73118
runs-on: macos-latest
@@ -86,6 +131,8 @@ jobs:
86131
# relying on CodeQL tracing through the guard. `main`'s tip is also
87132
# the *right* commit for docs, which should reflect current main,
88133
# not a slightly older one -- so this is not a compromise here.
134+
# Whether this commit is one that verdict covers is `verdict`'s
135+
# question (#1643).
89136
persist-credentials: false
90137

91138
- uses: actions/setup-python@v7

‎docs/source/contributing/workflows.rst‎

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -196,8 +196,10 @@ itself (dotted, above) **only when its own trigger is not** ``workflow_run``
196196
(their gate jobs' ``if:`` guards this explicitly) -- i.e. only on the
197197
Saturday ``schedule`` path, where no completed Unit Tests run exists yet to
198198
read a verdict from. On the ``workflow_run`` path (thick arrows), each reads
199-
the verdict Unit Tests already reached for that same commit instead of
200-
re-running the gate a second time.
199+
the verdict Unit Tests already reached instead of re-running the gate a second
200+
time. Vendor Update, Conda Update and GitHub Pages act on it only once their
201+
``verdict`` job, described under the edge list below, says it is a verdict on
202+
the commit they build.
201203

202204
``workflow_run`` Edges
203205
----------------------
@@ -224,6 +226,19 @@ and ``.head_branch`` (or, for Create Release and Coverage Comment, ``.conclusion
224226
doing anything with an outward effect; none of the filtering happens in the
225227
``on:`` block.
226228

229+
Those checks say nothing about *which* commit was verified. A ``workflow_run``
230+
checks out ``github.sha``, ``main``'s tip when the event is raised, not
231+
``github.event.workflow_run.head_sha``, the commit the completed run tested, and
232+
in a merge wave the two differ: Conda Update 38325136710 bumped 2e941bbb7 under
233+
the verdict for 9083163f5 (`#1643 <https://github.com/JarryShaw/PyPCAPKit/issues/1643>`__).
234+
So Vendor Update, Conda Update and GitHub Pages each run a ``verdict`` job first,
235+
and act only when the tip is the verified commit, or that commit plus bot commits
236+
to ``conda/build`` and ``conda/requirements.txt`` alone; otherwise they skip, and
237+
the tip's own Unit Tests run raises them again. The rule and its evidence are in
238+
``util/verdict_covers_checkout.py``. It covers the checkout only: Conda Update's
239+
push rebases onto ``main`` again, and Conda Tag tags whatever ``git pull`` brings
240+
in, so a commit that lands after the event can still be tagged.
241+
227242
Reusable-Workflow Calls (``uses:``)
228243
-----------------------------------
229244

@@ -234,11 +249,11 @@ repository target the same reusable workflow, with the same input:
234249

235250
* ``.github/workflows/create-release.yml:374`` -- job ``unit-tests`` calls
236251
``./.github/workflows/unit-tests.yml`` with ``gate-only: true``.
237-
* ``.github/workflows/cron-conda.yml:43`` -- job ``unit-tests`` calls
252+
* ``.github/workflows/cron-conda.yml:50`` -- job ``unit-tests`` calls
238253
``./.github/workflows/unit-tests.yml`` with ``gate-only: true``.
239-
* ``.github/workflows/cron-vendor.yml:49`` -- job ``unit-tests`` calls
254+
* ``.github/workflows/cron-vendor.yml:56`` -- job ``unit-tests`` calls
240255
``./.github/workflows/unit-tests.yml`` with ``gate-only: true``.
241-
* ``.github/workflows/deploy-pages.yml:47`` -- job ``unit-tests`` calls
256+
* ``.github/workflows/deploy-pages.yml:55`` -- job ``unit-tests`` calls
242257
``./.github/workflows/unit-tests.yml`` with ``gate-only: true``.
243258

244259
``gate-only: true`` selects **two** of ``unit-tests.yml``'s **ten** jobs,

0 commit comments

Comments
 (0)