Skip to content

[13.4-stable] pr-gate: fix PR identification behind a finished build - #6695

Merged
rene merged 5 commits into
lf-edge:13.4-stablefrom
eriknordmark:pr-gate-head-sha-13.4-stable
Oct 7, 2026
Merged

rene merged 5 commits into
lf-edge:13.4-stablefrom
eriknordmark:pr-gate-head-sha-13.4-stable

Conversation

@eriknordmark

@eriknordmark eriknordmark commented Oct 1, 2026 •

Copy link
Copy Markdown
Contributor

Description

Backport of #6595, plus part of #6698, to 13.4-stable.

The PR gate identified the PR behind a finished PR build with an issue
search on the built commit and took the first hit, which for stacked PRs can
be a neighbour; when the search matched nothing (a force-push during a build)
the job crashed instead of declining. #6595 resolves the PR by head-commit
identity, keys the concurrency group on the source repository and branch, and
publishes a pending Eden Runner status when the gate declines. See #6595 for
the full analysis.

Commits, all git cherry-pick -x from master:

  1. pr-gate: add scoped permissions block — the pr-gate.yml part only of
    0474ec035 ("github/workflows: add scoped permissions blocks"), which this
    branch lacks. The first fix commit adds statuses: write to the job-level
    permissions: block that commit created; without it the job would run with
    the repository's default token, which is write-all. The other workflows
    that commit scoped are left unchanged here.
  2. pr-gate: resolve the built PR by head commit (3133d5806)
  3. pr-gate: group gate runs by source branch (fd14184ea)
  4. pr-gate: report a decline only where it can write (81c663a60)
  5. pr-gate: group writes to GITHUB_OUTPUT (989636b13) — the pr-gate.yml
    commit of actionlint: re-enable shellcheck #6698. Its other commit, which re-enables shellcheck in master's
    Workflow Lint configuration, is not backported: this branch has no Workflow Lint.

Commits 2–5 apply cleanly, and their diffs are identical to those on master. With
commit 1, pr-gate.yml on this branch is byte-identical to master's.

PR dependencies

None.

How to test and validate this PR

As with #6595, this PR cannot exercise its own change: PR build ignores
.github/**, and a workflow_run gate always runs master's copy of the
workflow. The pull_request_review leg runs this branch's copy, so after merge
check the gate log on the next review of a 13.4-stable PR: the resolved PR
should match the reviewed one. The change touches no other file.

Checked on this branch: eden-trusted.yml uses the same
EDEN_IN_PR_STATUS_TITLE_PREFIX (Eden Runner) and build.yml the same
workflow name (PR build) that the gate relies on.

Changelog notes

None. CI tooling only, no user-facing changes.

PR Backports

Checklist

  • I've provided a proper description
  • I've added the proper documentation
  • I've tested my PR on amd64 device
  • I've tested my PR on arm64 device
  • I've written the test verification instructions
  • I've set the proper labels to this PR

For backport PRs (remove it if it's not a backport):

  • I've added a reference link to the original PR
  • PR's title follows the template

And the last but not least:

  • I've checked the boxes above, or I've provided a good reason why I didn't
    check them.

Device testing does not apply: the change touches a GitHub Actions workflow
only.

🤖 Generated with Claude Code

eriknordmark and others added 4 commits October 1, 2026 12:20
The GITHUB_TOKEN handed to a job inherits whichever scope the
repository default grants when a workflow does not declare its own
permissions:. pr-gate.yml's eden-gate job uses gh CLI to read PR
review state and the upstream build run; grant actions: read and
pull-requests: read over a permissions: {} default.

This is the pr-gate.yml part of the upstream commit only; the other
workflows it scoped are left as they are on this branch.

Signed-off-by: eriknordmark <erik@zededa.com>
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
(cherry picked from commit 0474ec0)
The gate found the PR behind a finished PR build with an issue search on
the built commit and took the first hit. That search matches every open
PR whose commit list contains the commit, so a stacked PR matches its
parent's head too and the winner is decided by relevance ranking. The
gate then judged the neighbour's approval state, and on a pass Eden
tested the neighbour's image while publishing its verdict against the
commit that was actually built. When the neighbour was unapproved the
gate declined instead, and because the declining path skips every
downstream job the PR showed no Eden row at all and nothing said why.

Enumerate the open PRs and keep the one whose head is the built commit,
taking the base branch from the same answer so a neighbour targeting a
different branch cannot select the wrong suite set. Neither obvious
alternative works here: the commit-to-PR endpoint returns nothing for a
PR raised from a fork, and the workflow_run payload's pull_requests list
is empty for those same PRs. Refuse to guess when several open PRs share
a head commit, and distinguish a failed lookup from a genuine "not
approved" rather than letting an empty PR number reach gh pr view.

A declined gate now publishes the Eden Runner status itself, carrying
the reason, so the common and legitimate case of an unreviewed PR reads
as pending on the PR instead of as a missing check.

Signed-off-by: eriknordmark <erik@zededa.com>
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
(cherry picked from commit 3133d58)
The gate's concurrency group asked the finished build's payload for the
PR number, but that list is empty for a PR raised from a fork, which is
almost every PR here. The expression fell through to a branch meant for
review events, where a build-triggered run has no pull_request to read
and the run id makes the group unique every time. Gate runs therefore
never shared a group and nothing was ever superseded, so a burst of
pushes left a queue of gates for commits already overtaken. Where the
payload did carry PR numbers, on a same-repo PR, taking the first of
them could put two stacked PRs in one group and let either cancel the
other.

Key the group on the repository and branch the build came from, which
the payload always carries and which a stacked PR has its own copy of.
Group names share one namespace across the whole repository, so prefix
the workflow name as every other workflow here does.

Signed-off-by: eriknordmark <erik@zededa.com>
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
(cherry picked from commit fd14184)
A gate run started by a review takes its workflow file from the pull
request's head, so GitHub caps its token at read-only whenever that head
lives in a fork. The commit status announcing a declined gate then fails
with 403 and turns the whole Ready for Eden job red, on a path where the
gate itself reached the right verdict. Restrict the status write to the
leg that runs off a finished build, where the workflow file comes from
the base branch and the token can carry statuses: write.

Announcing the reason on the review leg as well requires the trusted
workflow to do the writing.

Signed-off-by: eriknordmark <erik@zededa.com>
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
(cherry picked from commit 81c663a)
@eriknordmark eriknordmark mentioned this pull request Oct 2, 2026
4 of 7 tasks
Three steps append to GITHUB_OUTPUT one echo at a time, which
shellcheck flags as SC2129. Write each set of outputs through a
single grouped redirect instead; the outputs themselves are
unchanged.

Signed-off-by: eriknordmark <erik@zededa.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
(cherry picked from commit 989636b)
@github-actions
github-actions Bot requested a review from uncleDecart October 7, 2026 14:47
@rene
rene merged commit c89f5fa into lf-edge:13.4-stable Oct 7, 2026
10 checks passed
@eriknordmark
eriknordmark deleted the pr-gate-head-sha-13.4-stable branch October 8, 2026 15:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants