Tooling: skip the PR preview publish when the head has moved on - #796
Merged
Conversation
`PR Preview Publish` resolves the PR from the trusted `workflow_run` payload and requires the PR's head to still be the exact commit the build ran on. When a second push lands while the first build is still running, that commit is superseded before the publish job starts, the lookup matches nothing, and the step calls `core.setFailed`. Nothing is actually broken when that happens: the newer commit's own build/publish pair posts the preview, the job attaches no check run to the PR, and it is not in the trunk ruleset's required checks. But `workflow_run` runs are attributed to the default branch, so each race paints a red run in the trunk Actions tab. It fired twice in two days (#794, and a `codex/agent-async-jobs` push the day before), and it will fire whenever anyone pushes twice in quick succession. Warn and skip instead. The four steps that need a PR number are gated on it, so the job ends green with an annotation saying the head moved on. Publishing the superseded build under the current PR was never the alternative: a reviewer clicking that preview would get older code. The trust model is unchanged. A preview is still only ever published to a PR positively identified from the payload, and the loud failures stay loud: a malformed head SHA or incomplete head data still fails, and an API or permission error throws out of `paginate` rather than returning an empty list.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What it does
Turns a benign race in
PR Preview Publishfrom a red run into a green one with a warning annotation.The workflow resolves the PR from the trusted
workflow_runpayload and requires the PR's head to still be the exact commit the build ran on. Push a second commit while the first preview build is running, and that commit is superseded before the publish job starts. The lookup matches nothing and the step callscore.setFailed.Rationale
Nothing is actually broken when it happens. The newer commit's own build/publish pair posts the preview, the job attaches no check run to the PR, and it is not among the trunk ruleset's required checks.
The cost is noise, in the one place noise is expensive.
workflow_runruns are attributed to the default branch, so every race paints a red run in the trunk Actions tab. It fired twice in two days, on #794 and on acodex/agent-async-jobspush the day before, and it will fire whenever anyone pushes twice in quick succession. A red trunk run that routinely means nothing is a red trunk run people stop reading.Timeline of the #794 case:
5d4b4f6da2d67cc5, new build starts5d4b4f6dbuild, finds no matching head, failsa2d67cc5succeeds and posts the previewImplementation
core.warningand an early return replacecore.setFailedin the no-match branch. The four steps that need a PR number are gated onsteps.meta.outputs.pr-number != '', so the job ends green with an annotation naming the branch and the SHA that moved on.Two things deliberately not done:
setFailed, and an API or permission error throws out ofpaginaterather than returning an empty list, so it surfaces as a step error and not as a silent skip.The trust model is untouched: a preview is still only ever published to a PR positively identified from the
workflow_runpayload, never from artifact bytes.Testing instructions
The workflow only runs from the default branch, so the skip path is exercised after merge rather than on this PR.
No pull request for …; the head has moved on, skipping the preview.annotation, and the later run should post the preview as usual.