Repository navigation
Check stable-line pull requests with Patch QA and Patch provenance - #9196
craigmichaelmartin wants to merge 3 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.
| # 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
| 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
| 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?
| # 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?
| } | ||
|
|
||
| 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.
|
|
||
| # 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?
| # 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.
| 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?
| 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?
| 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?
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/**:@shopify/clitarball the way a release does;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,theme checkandtheme package;Patch provenance (
patch-provenance.yml), onpull_request_targetforstable/**, so the workflow comes from the stable line and never runs the pull request's code. It passes only for:patchchangesets for the fixed version group, changes no path outside main's mirrored files, and in which every changed file is exactly what themaincommit that first added its changesets does to that file when applied to the line's head. That commit must be newer than the line's cut frommain;version.ts, oclif manifest versions, the lockfile's workspace specifiers and changelog sections made of the consumed changesets' entries.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.maincommit also carried another fix to the same file; the two pass when backported together. Altered versions that add code, edit.github/actions, change a changeset's bump, reuse an old changeset to bring back old code, apply part of a commit, add changelog text, change a file's mode or change a third-party lockfile entry all fail.stable/5.1runs Patch QA on its own head.🤖 Generated with Claude Code