Repository navigation
Run Patch provenance without GitHub's API - #9228
Conversation
The check's compare and commits API calls got HTTP 403 on a GitHub-hosted runner (#9224), so it failed before judging the backport. It now reads everything with git, without a token: - One fetch brings every commit and tree of main, the line and the pull request, without file contents, so merge bases and histories are exact and the depth retries go away. Git fetches a file's text when the check first reads it. - The line's cut is git merge-base, still required to be one of main's landings. - A changeset the line has had since its cut comes from git log over the line's history since the cut, instead of the commits and compare API calls. - A failed read of a file's text fails the check, instead of reading as a missing file. - The job's token gets no permissions. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
git ls-remote matches the end of ref names, so a branch such as a/refs/heads/stable/5.2 also matched refs/heads/stable/5.2, and the check took the first line of output as the line's head. It now keeps only the exact ref. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
| if (!/^[0-9a-f]{40}$/.test(lineHead ?? '')) fail(`Couldn't read the head of ${BASE_REF}.`) | ||
| // Every commit and tree of the line, the pull request and main, without file contents, so | ||
| // merge bases and histories are exact. | ||
| git('fetch', '--quiet', '--no-tags', '--filter=blob:none', 'origin', lineHead, HEAD_SHA, '+refs/heads/main:refs/remotes/origin/main') |
There was a problem hiding this comment.
Nit: this fetch is now the check's main network step, before every file read. If it fails, git() throws, and the job ends with a stack trace and no summary. A fail('Fetching … failed: …') around it would give the same clear message as the other refusals. It fails closed as it is.
There was a problem hiding this comment.
Agreed. It fails closed today, but a failed fetch should end with a message and a summary like every other refusal, not a stack trace. #9229 has already merged this same file into stable/5.2, so I'll make this change and the hasFile one together in a small follow-up for main and stable/5.2, which keeps the two copies identical.
| } | ||
| } | ||
| // The fetch below brings every commit and tree, so whether a commit has a path reads no file. | ||
| const hasFile = (commit, path) => gitSucceeds('rev-parse', '--verify', '--quiet', `${commit}:${path}`) |
There was a problem hiding this comment.
Nit: hasFile reads any git error as a missing path. With every commit and tree fetched this should not happen. But git ls-tree throws on an error and prints nothing for a missing path, so a check built on it would keep the "a failed read never reads as a missing file" rule for trees too.
There was a problem hiding this comment.
Agreed. It matters most through fileAt: a tree read that failed for any other reason would come back as a missing file, and packagesAt and checkReportedVersions skip missing files. With every commit and tree fetched that shouldn't happen, but the check shouldn't depend on it. In the same follow-up, hasFile will use git ls-tree --full-tree, which fails on a read error and prints nothing for a missing path.
WHY are these changes introduced?
Patch provenance failed on #9224 before it judged anything. Its
gh api repos/Shopify/cli/compare/main...stable%2F5.2call got HTTP 403 on the GitHub-hosted runner ("theShopifyorganization has an IP allow list enabled"), while the job's anonymous git reads worked. The check is required onstable/5.2and later, so backports into the line could fail it the same way.WHAT is this pull request doing?
The check now reads everything with git, anonymously, and calls no API:
main, the line and the pull request, without file contents (--filter=blob:none, about 26 MB and 3 seconds locally), so merge bases and histories are exact and the depth retries go away. Git fetches a file's text when the check first reads it.git merge-base, still required to be one ofmain's landings.git log <cut>..<line head> -- <changeset>, instead of the commits and compare API calls.git ls-remotematches the end of ref names, so a branch such asa/refs/heads/stable/5.2also matched.The rules and messages don't change. Checked locally:
ghcall refused. New cases: a failed read fails, a line cut from a commit that isn't one ofmain's landings fails, and other branches whose names end like the line's don't change which commit the check reads as the line's head.stable/4.9,5.0,5.1and5.2,git merge-basegives the same cut as the compare API, and the new line-history rule gives the same first commit as the API calls for all 73 changesets those lines have touched since their cuts.mainin one commit together with an unrelated change.How to manually test your changes?
Run the check against #9224 with no token (needs git and Node):
It takes a few seconds and fails with "It leaves out .changeset/payments-enforce-authorization-expiry.md, ... which main's f56ab6b... also changes". Once
stable/5.2moves past #9224's base, it fails earlier, with "doesn't build on stable/5.2's head".🤖 Generated with Claude Code