Skip to content

Run Patch provenance without GitHub's API - #9228

Merged
craigmichaelmartin merged 2 commits into
mainfrom
patch-provenance-git-only
Dec 4, 2026
Merged

craigmichaelmartin merged 2 commits into
mainfrom
patch-provenance-git-only

Conversation

@craigmichaelmartin

@craigmichaelmartin craigmichaelmartin commented Dec 4, 2026 •

Copy link
Copy Markdown
Contributor

WHY are these changes introduced?

Patch provenance failed on #9224 before it judged anything. Its gh api repos/Shopify/cli/compare/main...stable%2F5.2 call got HTTP 403 on the GitHub-hosted runner ("the Shopify organization has an IP allow list enabled"), while the job's anonymous git reads worked. The check is required on stable/5.2 and 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:

  • One fetch brings every commit and tree of 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.
  • The line's cut is git merge-base, still required to be one of main's landings.
  • "The line has had this changeset since its cut" comes from git log <cut>..<line head> -- <changeset>, 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. A read is now a network call, and a missing oclif manifest, for example, would otherwise skip that file's version check.
  • The job's token gets no permissions.
  • The line's head comes from the exact branch ref. git ls-remote matches the end of ref names, so a branch such as a/refs/heads/stable/5.2 also matched.

The rules and messages don't change. Checked locally:

  • The 29 cases from earlier reviews give the same results and messages as the current file, with every gh call refused. New cases: a failed read fails, a line cut from a commit that isn't one of main'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.
  • On stable/4.9, 5.0, 5.1 and 5.2, git merge-base gives 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.
  • Against [stable/5.2] Skip releases that don't support the running Node when picking the auto-upgrade target #9224, it gives the same verdict as the current file run with the API: the fix reached main in 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):

mkdir /tmp/provenance && cd /tmp/provenance
curl -fsSL https://raw.githubusercontent.com/Shopify/cli/aa95c1ead6e8bcf7a09fc52e60cb1c91a17d5034/.github/workflows/patch-provenance.yml \
  | sed -n "/cat > check.mjs <<'SCRIPT'/,/^ *SCRIPT$/p" | sed '1d;$d;s/^          //' > check.mjs
touch summary.md
GITHUB_REPOSITORY=Shopify/cli GITHUB_STEP_SUMMARY=summary.md PR_NUMBER=9224 BASE_REF=stable/5.2 \
  HEAD_REF=patch-backport/stable/5.2/auto-upgrade-supported-node \
  HEAD_SHA=e63d093f1ac956faafe30cb68dffb9fd766664a8 HEAD_REPO=Shopify/cli node check.mjs

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.2 moves past #9224's base, it fails earlier, with "doesn't build on stable/5.2's head".

🤖 Generated with Claude Code

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>
@craigmichaelmartin
craigmichaelmartin requested a review from a team as a code owner December 4, 2026 17:38
@github-actions github-actions Bot added the no-changelog This PR doesn't include a changeset entry. Is an internal only change not relevant to end users. label Dec 4, 2026
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')

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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}`)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@craigmichaelmartin
craigmichaelmartin added this pull request to the merge queue Dec 4, 2026
Merged via the queue into main with commit 9c8820a Dec 4, 2026
28 checks passed
@craigmichaelmartin
craigmichaelmartin deleted the patch-provenance-git-only branch December 4, 2026 19:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

no-changelog This PR doesn't include a changeset entry. Is an internal only change not relevant to end users.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants