Repository navigation
Check stable-line pull requests with Patch QA and Patch provenance - #9196
craigmichaelmartin wants to merge 7 commits into
Conversation
Patch QA builds the @shopify/cli tarball a release of the pull request's head would publish, installs it on Linux, Windows and macOS (x64 and arm64), runs the checks that need no Shopify account, and fails if its files differ from the line's last release. Patch provenance passes only for a backport whose changes main already has (pinned to the main commit that added its patch changesets) and for the line's Version Packages pull request when it only versions the packages on top of the line's head. It runs from the stable line's own copy of the workflow and reads commits without running the pull request's code. After a release publishes, release.yml installs it from npm on Linux, Windows and macOS and runs the same checks. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A JSON comparison of package.json and oclif manifests misses changes that parsing normalizes away, such as a duplicated key. Require the same lines, with only version lines changed. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A backport now has to build on the line's head, and each file it changes has to be, whole, what the main commit that added its changesets does to that file when applied to the line. That commit must have reached main after the line's cut. Before, a backport could reuse an old changeset to bring back old main code, or apply only part of a main commit's change. A Version Packages pull request's new changelog section may only hold the consumed changesets' entries and dependency updates, and no versioned file may change mode. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
| if (merged.status !== 0 && merged.status !== 1) fail(`Couldn't apply main's ${origin} to ${BASE_REF}: ${merged.stderr.trim()}`) | ||
| const [mergedTree, ...conflicted] = merged.stdout.trim().split('\n') | ||
| const changedByOrigin = new Set(changedFiles(`${origin}^1`, origin).map(({path}) => path)) | ||
| for (const {path} of changes) { |
There was a problem hiding this comment.
This loop only visits files the PR changed. A backport that omits a source file can pass and ship an incomplete fix. Could we compare the PR tree with the expected merge-tree result and flag partial backports for manual review?
There was a problem hiding this comment.
I ran the script against candidates built on stable/5.1's head, and two more cases pass besides an omitted source file:
- a pull request with only
.changeset/mfa-required-error.mdfrom a0c9f53, and none of the fix; - a9f1d13 with every file except
.changeset/app-client-secret-variable.md. That commit adds oneminorand onepatchchangeset, and the patch-only rule on line 339 reads only the changesets the pull request includes, so theSHOPIFY_CLI_APP_CLIENT_SECRETfeature passes as a patch.
Comparing whole trees closes both. It also means a mirror commit that bundles a minor change with a fix, like a9f1d13, always goes to manual review.
There was a problem hiding this comment.
Thanks for building those. Both cases reproduce, and so does the omitted file. Fixed in 989388d: a backport's tree must now be exactly main's commit applied to the line's head, so a changeset without its fix fails, and so does a9f1d13 without its minor changeset. As you say, a commit on main that batches a fix with other changes now goes to manual review. The bot gets the same rule in its own pull request: it holds such a fix and comments that it waits for the next minor.
| # It runs on pull_request_target, so this file comes from the stable line, not from the pull request, | ||
| # and it never checks out or runs the pull request's code: it only reads commits. | ||
| on: | ||
| pull_request_target: |
There was a problem hiding this comment.
GitHub loads this workflow from main for every stable/** target. Starting December 2, public repos also need an explicit policy to allow this event. Could we configure that policy before rollout and update the comment above? Event reference · December 2 change
There was a problem hiding this comment.
You're right on both counts. In 1b13f65, Patch provenance moves to pull_request, so each stable line runs its own copy and the December 2 default doesn't affect it. It still only reads the pull request's commits and never checks out or runs its code, and the comment now says that. A pull request that edits this workflow runs its edited copy. The backports and Version Packages pull requests never touch .github/, and any other change to it gets a maintainer's review.
| if (!gitSucceeds('merge-base', lineHead, HEAD_SHA)) fail(`${HEAD_SHA} doesn't share history with ${BASE_REF}.`) | ||
|
|
||
| if (HEAD_REF === `changeset-release/${BASE_REF}`) { | ||
| checkVersionPackages() |
There was a problem hiding this comment.
Changesets opens and updates Version Packages PRs with GITHUB_TOKEN. GitHub documents its approval exception for pull_request, so we can’t rely on pull_request_target to run this check. Could the versioning job dispatch provenance and report the result on the generated head SHA? GitHub token rules
There was a problem hiding this comment.
Moving to pull_request (see the thread above) covers this. When Changesets updates the pull request with GITHUB_TOKEN, provenance now gets the same approval-required run as the other checks, and closing and reopening the pull request starts them all. The bot already does that close and reopen, but it skipped it whenever another app, such as Graphite, had reported on the commit. Its own pull request now counts only GitHub Actions runs there.
| if (!title || !next.startsWith(title) || !next.endsWith(rest) || !added.startsWith(`## ${version}\n`)) { | ||
| fail(`${path} must only gain a "## ${version}" section at the top.`) | ||
| } | ||
| const headings = new Set(['', '### Patch Changes', '- Updated dependencies']) |
There was a problem hiding this comment.
Replaying #9064 fails here on - Updated dependencies [3895769], which the stable/5.0 formatter generated. The loop also accepts missing release notes because it only checks lines that are present. Could we compare each package’s section with the entries its stable-line formatter generates?
There was a problem hiding this comment.
Fixed in c8fe61c. checkChangelog now rebuilds each package's new section with the line's own .changeset/changelog.cjs, read from the line's head and never from the pull request, and requires an exact match. Only the order of entries is free, since Changesets orders them as it reads them from disk. Missing entries, extra lines, wrong dependency versions, entries in the wrong package and missing bare sections all fail now. A line that still uses @changesets/cli/changelog, like stable/5.0, fails with a message saying the line isn't supported. The check is required only from stable/5.1. One known gap: of Prettier's rewrites, it reproduces only the blank line after headings. So a changeset that Prettier rewrites, for example one with a blank line in its summary, fails and needs a maintainer. That's 22 of the 1,611 changesets in main's history.
| # head would publish: installs it on each supported platform, runs the checks that need no Shopify | ||
| # account, and compares its files with the line's last release. Nothing is published. | ||
| on: | ||
| pull_request: |
There was a problem hiding this comment.
Retargeting a PR from main to stable/5.1 emits edited, so Patch QA misses it until another push or reopen. Could we handle edited when github.event.changes.base is present?
There was a problem hiding this comment.
Fixed in 3a795af. Patch QA now runs on edited too, and in full on every edit. A job skipped on title or body edits would report a skipped "Patch QA", which a required check counts as passing.
| } | ||
|
|
||
| start_case "Turn off auto-upgrade" | ||
| shopify config autoupgrade off |
There was a problem hiding this comment.
Could we remove this command? CI=1 already skips auto-upgrade. Running the documented smoke test locally otherwise leaves auto-upgrade disabled in the developer’s CLI config.
There was a problem hiding this comment.
Removed in 3a795af. versionToAutoUpgrade() returns early when CI is set, and the script sets CI=1.
|
|
||
| # A patch release should ship the same files as the release before it. Bundle chunk names carry | ||
| # a content hash, which changes with any code change, so they're compared by count only. | ||
| - name: Compare the files with the line's last release |
There was a problem hiding this comment.
Replaying this comparison on the 15 patch releases from 4.6 to 5.0, 14 match and 4.9.1 → 4.9.2 fails: it has one fewer chunk-[hash].js and no other difference. A failure here also fails package, so install is skipped on every platform. Could this run in its own job that gate also needs, and treat a difference in chunk count alone as a warning?
There was a problem hiding this comment.
Done in 3a795af. The comparison now runs in its own job, which gate needs, so a difference no longer skips the installs. A difference only in hashed bundle chunks is a warning: 4.9.1 to 4.9.2 now warns about its one fewer chunk, and 5.0.2 to 5.1.0 still fails.
| # Git-only path: the default Skeleton URL looks up its release through the GitHub API, whose | ||
| # unauthenticated rate limit is shared by every machine behind the same address. | ||
| start_case "shopify theme init" | ||
| shopify theme init qa-theme --clone-url https://github.com/Shopify/skeleton-theme --latest |
There was a problem hiding this comment.
--latest follows skeleton-theme's newest tag, while a stable line keeps the theme-check it shipped with. A later theme release could then fail theme check on an older line for reasons unrelated to the patch. Could we pin a tag with --clone-url https://github.com/Shopify/skeleton-theme#<tag> and drop --latest? Reading theme init, that URL still skips the GitHub API lookup.
There was a problem hiding this comment.
Done in 3a795af. It's pinned to v1.0.0, Skeleton's only release so far, through the #tag URL without --latest. That still takes the Git-only path, and the smoke script passes with it against the published 5.1.0.
| git('config', 'maintenance.auto', 'false') | ||
| git('config', 'gc.auto', '0') | ||
| git('remote', 'add', 'origin', `https://github.com/${repository}`) | ||
| const lineHead = git('ls-remote', 'origin', `refs/heads/${BASE_REF}`).split('\t')[0] |
There was a problem hiding this comment.
A backport is checked against the line's head at the time of this run. If another pull request merges first, nothing runs this again, so the pass describes a base that has moved and the merged result was never checked. release.yml covers this for Version Packages with its tree check; backports have nothing equivalent. Could stable/* require branches to be up to date once this check is required?
There was a problem hiding this comment.
Yes. The ruleset we plan for stable/5.1 and later lines, which makes these checks required, also requires branches to be up to date before merging. The bot builds each backport on the line's current head and merges only while that is still the head.
| node-version: 24.22.1 | ||
|
|
||
| # The same build the release runs, before it publishes. | ||
| - name: Bundle |
There was a problem hiding this comment.
nit: the bundle, pack and upload steps are a copy of the ones in release-qa-package.yml. Could both use one composite action, so the two tarballs can't drift apart?
There was a problem hiding this comment.
Done in 3a795af. Both workflows now build through .github/actions/build-cli-tarball.
| needs: [check, publish] | ||
| if: ${{ !cancelled() && needs.publish.result == 'success' }} | ||
| runs-on: ${{ matrix.os }} | ||
| timeout-minutes: 40 |
There was a problem hiding this comment.
nit: the wait for npm below can take 30 minutes, which leaves 10 for the install and the smoke tests. Could the timeout be higher, or the wait shorter?
There was a problem hiding this comment.
Done in 3a795af. The smoke job now has 60 minutes.
- Patch QA also runs when a pull request is edited, so a pull request retargeted to a stable line gets it. It runs in full on every edit: a skipped run would count as passing. - The file comparison runs in its own job, so a difference no longer stops the platform installs. A difference only in the number of hashed bundle chunks warns instead of failing. - Patch QA and Release QA package build the tarball through one composite action. - The smoke test pins the Skeleton theme release instead of following its latest tag, and no longer turns off auto-upgrade, which CI=1 already skips. - The release smoke job gets 60 minutes: the wait for npm alone can take 30. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…tter Patch provenance now builds each package's new changelog section with the changelog formatter at the line's head, never the pull request's, and requires the section to match it, apart from the order of entries. A missing entry, an extra line, a wrong dependency version or an entry in the wrong package fails. A line whose changesets config doesn't use ./changelog.cjs isn't supported. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
pull_request_target always loads the workflow from main, whatever the pull request's base, and from December 2, 2026 public repositories block it unless an Actions event policy allows it. On pull_request each stable line runs its own copy. The check still only reads the pull request's commits. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A backport passed when every file it changed matched main's commit, so one that left files out could ship a changeset without its fix, or one change of a batched commit without the changeset that makes it a minor. Its tree must now be exactly main's commit applied to the line's head, so a fix that reached main together with other changes goes to a maintainer. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
WHY are these changes introduced?
Patch releases ship from
stable/X.Yas fixes land, instead of waiting for the next minor. Two things then need checking on every pull request into a stable line, by machine rather than by memory:mainalready has, plus its own version bumps;Today a stable line's pull requests run unit tests, but nothing installs the packed CLI or checks where a backport's changes come from. After a release publishes, nothing checks the published package either.
WHAT is this pull request doing?
Patch QA (
patch-qa.yml), on pull requests intostable/**, including ones retargeted there:@shopify/clitarball the way a release does, through.github/actions/build-cli-tarball, which Release QA package now uses too;npm install -gonubuntu-latest,ubuntu-24.04-arm,windows-latest,windows-11-armandmacos-latest;.github/scripts/smoke-test-cli.sh): version, help, the app, theme and Hydrogen topics, andtheme init(from a pinned Skeleton release),theme checkandtheme package;Patch provenance (
patch-provenance.yml), onpull_requestforstable/**. Each stable line runs its own copy, and the check never checks out or runs the pull request's code: it only reads commits. It passes only for:patchchangesets for the fixed version group, changes no path outside main's mirrored files, and whose tree is exactly themaincommit that first added its changesets, applied to the line's head. That commit must be newer than the line's cut frommain. A commit that batches a fix with other changes therefore goes to a maintainer;version.ts, oclif manifest versions, the lockfile's workspace specifiers, and changelog sections exactly as the line's own.changeset/changelog.cjswrites them for the consumed changesets and dependency updates. Only lines that use that formatter are supported.Any other pull request into a stable line fails it, and a maintainer reviews and merges it.
Release smoke test: after Publish to npm succeeds,
release.ymlinstalls the published version from npm on Linux, Windows and macOS and runs the same checks.Both workflows are inert on
main(they only trigger for pull requests intostable/**). They land here first so new stable lines inherit them, then onstable/5.1.How to manually test your changes?
npm install -g @shopify/cli@5.1.0 --prefix /tmp/shopify-cli-smoke, put/tmp/shopify-cli-smoke/binfirst onPATH, thenbash .github/scripts/smoke-test-cli.sh 5.1.0.stable/5.1's head, a0c9f53 applied whole passes. Only its changeset fails, and so does a9f1d13 without itsminorchangeset, or with only one of the fixes it batches. Hand backports such as [5.0] Backport: fetch the app client secret only in commands that use it #9145 and Fix Cloudflare tunnel shutdown errors on Windows (5.0) #9066 fail.changeset versionpasses. Versions of it with an entry dropped, a line added, a dependency version changed or an entry in the wrong package fail. Version Packages - stable/5.1 #9186 (5.1.0, a minor) fails, and Version Packages - stable/5.0 #9064 and Version Packages - stable/5.0 #9158 fail becausestable/5.0uses another changelog formatter.4.9.2against4.9.1warns about one fewer chunk, and5.1.0against5.0.2fails.stable/5.1runs Patch QA on its own head. Patch provenance fails there, as it should for a change that isn't a backport ofmain.🤖 Generated with Claude Code