From 69ead44e4507e50524460d6bf851d61600c13c33 Mon Sep 17 00:00:00 2001 From: Craig Martin Date: Wed, 18 Nov 2026 11:35:19 -0500 Subject: [PATCH 1/4] Publish only the versions a push changed A release whose publish failed was finished by the next push, from that push's newer tree. The check now counts only packages whose version the push changed, or that it made public, and the publish job marks every other package private for the run. A version an earlier push brought is finished by re-running that push's run, or by the new `release` option of a manual run. Co-Authored-By: Claude Opus 5.5 --- .github/workflows/release.yml | 112 +++++++++++++++++++++++++++------- 1 file changed, 91 insertions(+), 21 deletions(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 41b3d37e063..944b272024b 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -21,6 +21,9 @@ on: options: - nightly - experimental + # Publishes the current commit's versions on main or stable/*, for a release whose push + # started no run, or whose run can no longer be re-run. + - release concurrency: group: changeset-${{ github.head_ref || github.run_id }} @@ -61,51 +64,97 @@ jobs: env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - # Decides, without an npm credential, whether a push has anything to publish, so a push that - # doesn't change a version never waits for the npm-release approval. Every public package counts, - # so a partly failed publish is retried. + # Decides, without an npm credential, whether a push has anything to publish. Only versions this + # push changed count, and the publish job publishes only those. A version that an earlier push + # brought, which npm still lacks, is finished by re-running that push's run, which builds the same + # commit, or by the `release` option of a manual run. A later push never publishes it from a + # newer tree that wasn't released under that version. check: name: Check for unpublished versions needs: version-packages # Like changesets/action before it, a stable line doesn't publish while changesets are pending. - if: ${{ !cancelled() && github.event_name == 'push' && needs.version-packages.result != 'failure' && needs.version-packages.outputs.has-changesets != 'true' }} + if: ${{ !cancelled() && (github.event_name == 'push' || github.event.inputs.tag == 'release') && needs.version-packages.result != 'failure' && needs.version-packages.outputs.has-changesets != 'true' }} runs-on: ubuntu-latest permissions: contents: read outputs: unpublished: ${{ steps.npm.outputs.unpublished }} version: ${{ steps.npm.outputs.version }} + packages: ${{ steps.npm.outputs.packages }} steps: - uses: actions/checkout@v6 - - name: Compare package versions with npm + - name: Compare the pushed versions with npm id: npm + env: + BEFORE: ${{ github.event.before }} + MANUAL: ${{ github.event_name == 'workflow_dispatch' }} run: | set -euo pipefail + if [ "$MANUAL" = true ]; then + # A manual release counts every version at this commit. + BEFORE=all + elif [[ "$BEFORE" =~ ^0*$ ]]; then + # A push that creates the branch has no earlier commit, so it changes no version. + BEFORE=none + else + git fetch --no-tags --depth=1 origin "$BEFORE" + fi VERSION=$(node -p "require('./packages/cli/package.json').version") - # `shopify` is published from a copy of packages/cli (bin/create-cli-duplicate-package.js). - PACKAGES="shopify@$VERSION" - for MANIFEST in packages/*/package.json; do - PACKAGES="$PACKAGES $(node -p "const p = require('./$MANIFEST'); p.private ? '' : p.name + '@' + p.version")" - done + # One "pushed|carried name@version" line per public package. A package counts as pushed + # when this push changed its version or made it public. `shopify` is published from a + # copy of packages/cli (bin/create-cli-duplicate-package.js). + LINES=$(node -e ' + const {execFileSync} = require("node:child_process") + const fs = require("node:fs") + const before = process.argv[1] + const manifestAt = (path) => { + try { + return JSON.parse(execFileSync("git", ["show", `${before}:${path}`], {encoding: "utf8", stdio: ["ignore", "pipe", "ignore"]})) + } catch { + return undefined + } + } + for (const directory of fs.readdirSync("packages")) { + const path = `packages/${directory}/package.json` + if (!fs.existsSync(path)) continue + const manifest = JSON.parse(fs.readFileSync(path, "utf8")) + if (manifest.private) continue + let pushed = before === "all" + if (before !== "all" && before !== "none") { + const previous = manifestAt(path) + pushed = !previous || previous.private === true || previous.version !== manifest.version + } + const names = directory === "cli" ? [manifest.name, "shopify"] : [manifest.name] + for (const name of names) console.log(`${pushed ? "pushed" : "carried"} ${name}@${manifest.version}`) + } + ' "$BEFORE") UNPUBLISHED=false - for PACKAGE in $PACKAGES; do - # An npm error counts as unpublished: the publish job then asks for approval, and - # `changeset publish` skips every version npm already has. + PUSHED="" + while read -r STATE PACKAGE; do + [ -n "$PACKAGE" ] || continue + if [ "$STATE" = pushed ]; then + PUSHED="$PUSHED ${PACKAGE%@*}" + fi + # An npm error counts as unpublished. `changeset publish` skips every version npm + # already has, so publishing a pushed version that npm does have is harmless. if [ "$(npm view "$PACKAGE" version 2>/dev/null || true)" = "${PACKAGE##*@}" ]; then echo "$PACKAGE is on npm" - else - echo "$PACKAGE is not on npm" + elif [ "$STATE" = pushed ]; then + echo "$PACKAGE is not on npm, and this run publishes it" UNPUBLISHED=true + else + echo "::warning::$PACKAGE is not on npm, but an earlier push brought that version, so this run doesn't publish it. If that push's Release run failed, re-run its failed jobs; if it can't be re-run, start this workflow by hand with the release option." fi - done - echo "Version $VERSION, unpublished $UNPUBLISHED" + done <<< "$LINES" + echo "Version $VERSION, unpublished $UNPUBLISHED, packages:$PUSHED" { echo "version=$VERSION" echo "unpublished=$UNPUBLISHED" + echo "packages=${PUSHED# }" } >> "$GITHUB_OUTPUT" # The only job that publishes a release. The npm-release environment limits it to main and - # stable/* and asks Dev Experience to approve each run. + # stable/*. publish: name: Publish to npm needs: check @@ -129,7 +178,7 @@ jobs: with: node-version: 24.22.1 - # After the approval, which can take hours, so a release that published meanwhile counts. + # Read when the job runs, so a release that published meanwhile counts. - name: Choose the dist-tag id: dist-tag env: @@ -152,6 +201,27 @@ jobs: echo "Publishing $VERSION under $DIST_TAG" echo "dist-tag=$DIST_TAG" >> "$GITHUB_OUTPUT" + # Leaves every other package out of this publish, so a version that an earlier push brought + # is never published from this commit's tree. + - name: Publish only the checked packages + env: + PACKAGES: ${{ needs.check.outputs.packages }} + run: | + set -euo pipefail + node -e ' + const fs = require("node:fs") + const keep = new Set(process.argv[1].split(" ").filter(Boolean)) + for (const directory of fs.readdirSync("packages")) { + const path = `packages/${directory}/package.json` + if (!fs.existsSync(path)) continue + const manifest = JSON.parse(fs.readFileSync(path, "utf8")) + if (manifest.private || keep.has(manifest.name)) continue + manifest.private = true + fs.writeFileSync(path, `${JSON.stringify(manifest, null, 2)}\n`) + console.log(`Not publishing ${manifest.name}@${manifest.version} from this commit`) + } + ' "$PACKAGES" + - name: Publish packages run: pnpm release "$DIST_TAG" env: @@ -269,11 +339,11 @@ jobs: fi # Nightly on schedule, nightly or experimental by hand, from main only. A nightly runs in the - # npm-nightly environment; an experimental release, which is rare, waits for the npm-release approval. + # npm-nightly environment; an experimental release, which is rare, runs in npm-release. manual-cron-release: name: Manual & Cron Release needs: nightly-changes - if: ${{ !cancelled() && (github.event_name == 'schedule' || github.event_name == 'workflow_dispatch') && github.ref_name == 'main' && needs.nightly-changes.outputs.changed != 'false' }} + if: ${{ !cancelled() && (github.event_name == 'schedule' || (github.event_name == 'workflow_dispatch' && github.event.inputs.tag != 'release')) && github.ref_name == 'main' && needs.nightly-changes.outputs.changed != 'false' }} runs-on: ubuntu-latest environment: ${{ github.event.inputs.tag == 'experimental' && 'npm-release' || 'npm-nightly' }} permissions: From 3964e3b6dc35eb5a1dd1fa458aca74abc5726a06 Mon Sep 17 00:00:00 2001 From: Craig Martin Date: Wed, 18 Nov 2026 11:37:16 -0500 Subject: [PATCH 2/4] Limit a manual release to the versions its head commit changed A manual run published every unpublished version at the branch's head, so a version whose push was followed by later commits went out from the newer tree. It now publishes only the versions the head commit changed against its first parent, and fails with the reason otherwise. Co-Authored-By: Claude Opus 5.5 --- .github/workflows/release.yml | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 944b272024b..64419695cfd 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -21,8 +21,8 @@ on: options: - nightly - experimental - # Publishes the current commit's versions on main or stable/*, for a release whose push - # started no run, or whose run can no longer be re-run. + # On main or stable/*: publishes the versions that the branch's head commit itself changed, + # for a release whose push started no run, or whose run can no longer be re-run. - release concurrency: @@ -67,8 +67,8 @@ jobs: # Decides, without an npm credential, whether a push has anything to publish. Only versions this # push changed count, and the publish job publishes only those. A version that an earlier push # brought, which npm still lacks, is finished by re-running that push's run, which builds the same - # commit, or by the `release` option of a manual run. A later push never publishes it from a - # newer tree that wasn't released under that version. + # commit, or by the `release` option of a manual run while that commit is still the branch's head. + # A later commit never publishes it from a newer tree that wasn't released under that version. check: name: Check for unpublished versions needs: version-packages @@ -91,8 +91,9 @@ jobs: run: | set -euo pipefail if [ "$MANUAL" = true ]; then - # A manual release counts every version at this commit. - BEFORE=all + # A manual release counts only the versions this commit changed against its first parent. + git fetch --no-tags --depth=2 origin "$GITHUB_SHA" + BEFORE=$(git rev-parse "$GITHUB_SHA^1") elif [[ "$BEFORE" =~ ^0*$ ]]; then # A push that creates the branch has no earlier commit, so it changes no version. BEFORE=none @@ -119,8 +120,8 @@ jobs: if (!fs.existsSync(path)) continue const manifest = JSON.parse(fs.readFileSync(path, "utf8")) if (manifest.private) continue - let pushed = before === "all" - if (before !== "all" && before !== "none") { + let pushed = false + if (before !== "none") { const previous = manifestAt(path) pushed = !previous || previous.private === true || previous.version !== manifest.version } @@ -143,10 +144,14 @@ jobs: echo "$PACKAGE is not on npm, and this run publishes it" UNPUBLISHED=true else - echo "::warning::$PACKAGE is not on npm, but an earlier push brought that version, so this run doesn't publish it. If that push's Release run failed, re-run its failed jobs; if it can't be re-run, start this workflow by hand with the release option." + echo "::warning::$PACKAGE is not on npm, but an earlier push brought that version, so this run doesn't publish it. If that push's Release run failed, re-run its failed jobs; if it can't be re-run and that commit is still the branch's head, start this workflow by hand with the release option." fi done <<< "$LINES" echo "Version $VERSION, unpublished $UNPUBLISHED, packages:$PUSHED" + if [ "$MANUAL" = true ] && [ -z "$PUSHED" ]; then + echo "::error::$GITHUB_SHA didn't change any public package's version against its first parent, so a manual release has nothing it may publish. Re-run the failed jobs of the Release run for the commit that changed the version, or publish a new version." + exit 1 + fi { echo "version=$VERSION" echo "unpublished=$UNPUBLISHED" From c6a4913d97a96f7f3b89d4386827f261fba74861 Mon Sep 17 00:00:00 2001 From: Craig Martin Date: Wed, 18 Nov 2026 12:14:12 -0500 Subject: [PATCH 3/4] Release from stable branches only main no longer publishes releases: its check fails when a version on it is missing from npm, and releases ship from stable/* through a merged Version Packages pull request. The publish job checks that the merge's tree is the pull request head's, version-packages refuses a version npm already has, and a new manual workflow builds the release tarball of a given commit for testing. The stable-branch creation steps are removed: Dev Experience creates stable/X.Y by hand. Co-Authored-By: Claude Opus 5.5 --- .github/workflows/release-qa-package.yml | 118 ++++++++++++++++++++ .github/workflows/release.yml | 130 +++++++++++++---------- 2 files changed, 191 insertions(+), 57 deletions(-) create mode 100644 .github/workflows/release-qa-package.yml diff --git a/.github/workflows/release-qa-package.yml b/.github/workflows/release-qa-package.yml new file mode 100644 index 00000000000..fc74715d9f8 --- /dev/null +++ b/.github/workflows/release-qa-package.yml @@ -0,0 +1,118 @@ +name: Release QA package + +# Builds the @shopify/cli tarball that a release of a commit would publish, so it can be tested +# before that commit is merged and released. Nothing is published. +on: + workflow_dispatch: + inputs: + sha: + description: 'Full commit SHA to build, normally the head of a "Version Packages - stable/X.Y" pull request' + type: string + required: true + +permissions: + contents: read + +concurrency: + group: release-qa-package-${{ inputs.sha }} + cancel-in-progress: false + +env: + PNPM_VERSION: '10.11.1' + +jobs: + package: + name: Build the release tarball + runs-on: ubuntu-latest + steps: + - name: Validate the SHA + env: + SHA: ${{ inputs.sha }} + run: | + set -euo pipefail + # A full SHA names one commit; a branch name or short SHA could resolve to a different one. + if [[ ! "$SHA" =~ ^[0-9a-f]{40}$ ]]; then + echo "::error::sha must be a full commit SHA: 40 lowercase hexadecimal characters." + exit 1 + fi + # Only the head of one of this repository's branches, such as a Version Packages pull + # request's branch, so the job never builds a fork's code with this repository's cache. + if ! git ls-remote --heads "https://github.com/$GITHUB_REPOSITORY" | cut -f 1 | grep -qx "$SHA"; then + echo "::error::$SHA isn't the head of a branch in $GITHUB_REPOSITORY." + exit 1 + fi + + - uses: actions/checkout@v6 + with: + ref: ${{ inputs.sha }} + persist-credentials: false + + - name: Verify the checked-out commit + env: + SHA: ${{ inputs.sha }} + run: | + set -euo pipefail + HEAD_SHA=$(git rev-parse HEAD) + if [ "$HEAD_SHA" != "$SHA" ]; then + echo "::error::Checked out $HEAD_SHA instead of $SHA." + exit 1 + fi + + - name: Setup deps + uses: ./.github/actions/setup-cli-deps + with: + node-version: 24.22.1 + + # The same build the release runs, before it publishes. + - name: Bundle + run: pnpm bundle-for-release + env: + SHOPIFY_CLI_BUILD_REPO: ${{ github.repository }} + + # The release's prepack also generates the manifest and copies the README. Its error-reporting + # source map upload is left out, and the tarball excludes source maps either way. + - name: Pack @shopify/cli + id: pack + working-directory: packages/cli + run: | + set -euo pipefail + pnpm oclif manifest + cp ../../README.md README.md + TARBALL=$(npm pack --ignore-scripts | tail -n 1) + echo "tarball=$TARBALL" >> "$GITHUB_OUTPUT" + + - name: Upload the tarball + uses: actions/upload-artifact@v4 + with: + name: shopify-cli-${{ inputs.sha }} + path: packages/cli/${{ steps.pack.outputs.tarball }} + if-no-files-found: error + # The tarball is already compressed. + compression-level: 0 + + - name: Summarize + working-directory: packages/cli + env: + SHA: ${{ inputs.sha }} + TARBALL: ${{ steps.pack.outputs.tarball }} + ARTIFACT: shopify-cli-${{ inputs.sha }} + run: | + set -euo pipefail + CHECKSUM=$(sha256sum "$TARBALL" | cut -d ' ' -f 1) + VERSION=$(tar -xzOf "$TARBALL" package/package.json | node -p 'JSON.parse(require("node:fs").readFileSync(0, "utf8")).version') + { + echo "### @shopify/cli $VERSION" + echo + echo "| | |" + echo "| --- | --- |" + echo "| Commit | \`$SHA\` |" + echo "| Tarball | \`$TARBALL\` |" + echo "| SHA-256 | \`$CHECKSUM\` |" + echo "| Version | \`$VERSION\` |" + echo + echo "Download it with:" + echo + echo '```sh' + echo "gh run download $GITHUB_RUN_ID -R $GITHUB_REPOSITORY -n $ARTIFACT" + echo '```' + } >> "$GITHUB_STEP_SUMMARY" diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 64419695cfd..fff8224a825 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -1,8 +1,9 @@ name: Release on: - # Publishes the versions a push brings: on main, World's Version Packages commit, which the public - # mirror publishes here; on stable/*, a merged "Version Packages - stable/X.Y" pull request. + # Releases ship from stable/*: a merged "Version Packages - stable/X.Y" pull request publishes the + # versions it changed. main doesn't publish releases; its check fails if a version on it isn't on + # npm. push: branches: - main @@ -21,8 +22,8 @@ on: options: - nightly - experimental - # On main or stable/*: publishes the versions that the branch's head commit itself changed, - # for a release whose push started no run, or whose run can no longer be re-run. + # On stable/*: publishes the versions that the branch's head commit itself changed, for a + # release whose push started no run, or whose run can no longer be re-run. - release concurrency: @@ -34,8 +35,8 @@ env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} jobs: - # Opens or updates a stable line's Version Packages pull request. main's versions come from World - # through the public mirror, so main gets no Version Packages pull request here. + # Opens or updates a stable line's Version Packages pull request. main gets the released versions + # back after each release, so it has no Version Packages pull request. version-packages: name: Version Packages if: github.event_name == 'push' && startsWith(github.ref_name, 'stable/') @@ -63,6 +64,28 @@ jobs: createGithubReleases: false env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + # A line cut from a main that hasn't caught up with the last release would compute a version + # npm already has, and its release would then publish nothing. + - name: Refuse a version npm already has + if: ${{ !cancelled() }} + run: | + set -euo pipefail + BRANCH="changeset-release/$GITHUB_REF_NAME" + if ! git fetch --no-tags --depth=1 origin "$BRANCH"; then + echo "No $BRANCH branch, so there's no new version to check" + exit 0 + fi + CURRENT=$(node -p "require('./packages/cli/package.json').version") + VERSION=$(git show FETCH_HEAD:packages/cli/package.json | node -e 'let s = ""; process.stdin.on("data", (d) => (s += d)).on("end", () => console.log(JSON.parse(s).version))') + if [ "$VERSION" = "$CURRENT" ]; then + echo "$BRANCH has this line's current version, $CURRENT" + exit 0 + fi + if [ "$(npm view "@shopify/cli@$VERSION" version --registry=https://registry.npmjs.org/ 2>/dev/null || true)" = "$VERSION" ]; then + echo "::error::$BRANCH proposes @shopify/cli $VERSION, which npm already has. The line was cut before main got that release back: bring the release back to main, then into this line, so its next version is new." + exit 1 + fi + echo "$BRANCH proposes $VERSION, which npm doesn't have yet" # Decides, without an npm credential, whether a push has anything to publish. Only versions this # push changed count, and the publish job publishes only those. A version that an earlier push @@ -90,6 +113,10 @@ jobs: MANUAL: ${{ github.event_name == 'workflow_dispatch' }} run: | set -euo pipefail + if [ "$MANUAL" = true ] && [ "$GITHUB_REF_NAME" = main ]; then + echo "::error::main doesn't publish releases. Releases ship from stable/*." + exit 1 + fi if [ "$MANUAL" = true ]; then # A manual release counts only the versions this commit changed against its first parent. git fetch --no-tags --depth=2 origin "$GITHUB_SHA" @@ -130,6 +157,7 @@ jobs: } ' "$BEFORE") UNPUBLISHED=false + MISSING="" PUSHED="" while read -r STATE PACKAGE; do [ -n "$PACKAGE" ] || continue @@ -140,6 +168,11 @@ jobs: # already has, so publishing a pushed version that npm does have is harmless. if [ "$(npm view "$PACKAGE" version 2>/dev/null || true)" = "${PACKAGE##*@}" ]; then echo "$PACKAGE is on npm" + continue + fi + MISSING="$MISSING $PACKAGE" + if [ "$GITHUB_REF_NAME" = main ]; then + echo "$PACKAGE is not on npm" elif [ "$STATE" = pushed ]; then echo "$PACKAGE is not on npm, and this run publishes it" UNPUBLISHED=true @@ -148,6 +181,11 @@ jobs: fi done <<< "$LINES" echo "Version $VERSION, unpublished $UNPUBLISHED, packages:$PUSHED" + if [ "$GITHUB_REF_NAME" = main ] && [ -n "$MISSING" ]; then + # main only gets versions back after a stable line published them. + echo "::error::main has versions that npm doesn't:$MISSING. main doesn't publish them; releases ship from stable/*." + exit 1 + fi if [ "$MANUAL" = true ] && [ -z "$PUSHED" ]; then echo "::error::$GITHUB_SHA didn't change any public package's version against its first parent, so a manual release has nothing it may publish. Re-run the failed jobs of the Release run for the commit that changed the version, or publish a new version." exit 1 @@ -165,7 +203,7 @@ jobs: needs: check # check's own skipped dependency (version-packages, on main) would skip this job under the # implicit success(), so the condition names check's result instead. - if: ${{ !cancelled() && needs.check.result == 'success' && needs.check.outputs.unpublished == 'true' }} + if: ${{ !cancelled() && needs.check.result == 'success' && needs.check.outputs.unpublished == 'true' && startsWith(github.ref_name, 'stable/') }} runs-on: ubuntu-latest environment: npm-release # Approved runs on one branch publish one at a time, in order; none is cancelled. @@ -178,6 +216,23 @@ jobs: id-token: write steps: - uses: actions/checkout@v6 + # The release is the merge of the Version Packages pull request that was tested. A merge commit + # whose tree differs from that pull request's head means the line moved after the pull request + # was made, so the release would carry changes nobody tested with it. + - name: Check the release is the tested pull request head + run: | + set -euo pipefail + git fetch --no-tags --depth=2 origin "$GITHUB_SHA" + if [ "$(git rev-list --parents -n 1 "$GITHUB_SHA" | wc -w)" -ne 3 ]; then + echo "::error::$GITHUB_SHA isn't a merge commit. A release publishes only from merging its Version Packages pull request with a merge commit." + exit 1 + fi + HEAD_SHA=$(git rev-parse "$GITHUB_SHA^2") + if [ "$(git rev-parse "$GITHUB_SHA^{tree}")" != "$(git rev-parse "$HEAD_SHA^{tree}")" ]; then + echo "::error::The merge's files differ from the pull request head $HEAD_SHA, so the line moved after the pull request was made. Let the Version Packages pull request update, test its new head and merge that." + exit 1 + fi + echo "Publishing the files of $HEAD_SHA, the merged pull request's head" - name: Setup deps uses: ./.github/actions/setup-cli-deps with: @@ -190,18 +245,16 @@ jobs: VERSION: ${{ needs.check.outputs.version }} run: | set -euo pipefail - # A stable line's patch that is older than npm's `latest` goes under stable-X.Y, so it - # doesn't move `latest` backwards. main always publishes under `latest`. + # A release older than npm's `latest`, such as an older line's patch, goes under stable-X.Y, + # so it doesn't move `latest` backwards. DIST_TAG=latest - if [ "$GITHUB_REF_NAME" != main ]; then - LATEST=$(npm view @shopify/cli dist-tags.latest) - if ! node -e ' - const [version, latest] = process.argv.slice(1).map((v) => v.split(".").map(Number)) - const difference = version.map((part, i) => part - latest[i]).find((d) => d !== 0) ?? 0 - process.exit(difference >= 0 ? 0 : 1) - ' "$VERSION" "$LATEST"; then - DIST_TAG="stable-${VERSION%.*}" - fi + LATEST=$(npm view @shopify/cli dist-tags.latest) + if ! node -e ' + const [version, latest] = process.argv.slice(1).map((v) => v.split(".").map(Number)) + const difference = version.map((part, i) => part - latest[i]).find((d) => d !== 0) ?? 0 + process.exit(difference >= 0 ? 0 : 1) + ' "$VERSION" "$LATEST"; then + DIST_TAG="stable-${VERSION%.*}" fi echo "Publishing $VERSION under $DIST_TAG" echo "dist-tag=$DIST_TAG" >> "$GITHUB_OUTPUT" @@ -249,43 +302,6 @@ jobs: git push origin "$TAG" echo "Created tag $TAG" - - name: Create stable branch - id: stable-branch - if: github.ref_name == 'main' && endsWith(needs.check.outputs.version, '.0') - # Only Dev Experience members can create stable/* branches, so this push can be refused. - # The release goes on, and the next step asks Dev Experience to create the branch. - continue-on-error: true - env: - VERSION: ${{ needs.check.outputs.version }} - run: | - set -euo pipefail - MINOR=${VERSION%.0} - BRANCH="stable/$MINOR" - if git ls-remote --exit-code --heads origin "$BRANCH" >/dev/null 2>&1; then - echo "Branch $BRANCH already exists, skipping" - exit 0 - fi - git push origin "HEAD:refs/heads/$BRANCH" - echo "Created branch $BRANCH" - - - name: Ask Dev Experience to create the stable branch - if: steps.stable-branch.outcome == 'failure' - env: - VERSION: ${{ needs.check.outputs.version }} - run: | - MINOR=${VERSION%.0} - MESSAGE="Create stable/$MINOR from tag $VERSION; only Dev Experience can." - echo "::warning title=stable/$MINOR was not created::$MESSAGE" - { - echo "### stable/$MINOR was not created" - echo - echo "$MESSAGE" - echo - echo '```sh' - echo "git push origin refs/tags/$VERSION:refs/heads/stable/$MINOR" - echo '```' - } >> "$GITHUB_STEP_SUMMARY" - - name: Create GitHub release if: ${{ !endsWith(needs.check.outputs.version, '.0.0') }} env: @@ -305,8 +321,8 @@ jobs: echo "Release $TAG already exists; ensured make_latest=legacy" exit 0 fi - # The public repository's pull requests are mirror publishes from World, so the notes come - # from the version's changelog entries rather than from GitHub's generated notes. + # The notes come from the version's changelog entries. GitHub's generated notes would list + # only the Version Packages pull request. node .github/scripts/release-notes.js "$TAG" > "$RUNNER_TEMP/release-notes.md" gh api \ --method POST \ From 34cd2ee2b932f496aacb9b60c2fc71af994da988 Mon Sep 17 00:00:00 2001 From: Craig Martin Date: Wed, 18 Nov 2026 12:20:56 -0500 Subject: [PATCH 4/4] Publish only from a merged Version Packages pull request A merge commit whose files equal its second parent's proves the line didn't move, not that the merged head was the tested pull request: a hand-made merge pushed directly also passes. The publish job now also requires the commit to be the merge of a pull request from changeset-release/ into the line, with that head. npm reads are retried so a registry blip doesn't read as missing. Co-Authored-By: Claude Opus 5.5 --- .github/workflows/release.yml | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index fff8224a825..2c0916f4ffe 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -156,6 +156,14 @@ jobs: for (const name of names) console.log(`${pushed ? "pushed" : "carried"} ${name}@${manifest.version}`) } ' "$BEFORE") + # npm view, retried, so a brief registry error doesn't read as a missing version. + on_npm() { + for attempt in 1 2 3; do + if [ "$(npm view "$1" version 2>/dev/null || true)" = "${1##*@}" ]; then return 0; fi + [ "$attempt" = 3 ] || sleep 5 + done + return 1 + } UNPUBLISHED=false MISSING="" PUSHED="" @@ -166,7 +174,7 @@ jobs: fi # An npm error counts as unpublished. `changeset publish` skips every version npm # already has, so publishing a pushed version that npm does have is harmless. - if [ "$(npm view "$PACKAGE" version 2>/dev/null || true)" = "${PACKAGE##*@}" ]; then + if on_npm "$PACKAGE"; then echo "$PACKAGE is on npm" continue fi @@ -214,12 +222,15 @@ jobs: permissions: contents: write id-token: write + pull-requests: read steps: - uses: actions/checkout@v6 - # The release is the merge of the Version Packages pull request that was tested. A merge commit - # whose tree differs from that pull request's head means the line moved after the pull request + # The release is the merge of this line's Version Packages pull request, whose head was tested. + # A merge commit whose tree differs from that head means the line moved after the pull request # was made, so the release would carry changes nobody tested with it. - name: Check the release is the tested pull request head + env: + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} run: | set -euo pipefail git fetch --no-tags --depth=2 origin "$GITHUB_SHA" @@ -228,11 +239,16 @@ jobs: exit 1 fi HEAD_SHA=$(git rev-parse "$GITHUB_SHA^2") + PULL=$(gh api "repos/$GITHUB_REPOSITORY/commits/$GITHUB_SHA/pulls" --jq "[.[] | select(.merged_at != null and .merge_commit_sha == \"$GITHUB_SHA\" and .base.ref == \"$GITHUB_REF_NAME\" and .head.sha == \"$HEAD_SHA\" and .head.ref == \"changeset-release/$GITHUB_REF_NAME\")] | first | .number // empty") + if [ -z "$PULL" ]; then + echo "::error::$GITHUB_SHA isn't the merge of a Version Packages pull request from changeset-release/$GITHUB_REF_NAME into $GITHUB_REF_NAME, so nothing publishes from it." + exit 1 + fi if [ "$(git rev-parse "$GITHUB_SHA^{tree}")" != "$(git rev-parse "$HEAD_SHA^{tree}")" ]; then echo "::error::The merge's files differ from the pull request head $HEAD_SHA, so the line moved after the pull request was made. Let the Version Packages pull request update, test its new head and merge that." exit 1 fi - echo "Publishing the files of $HEAD_SHA, the merged pull request's head" + echo "Publishing the files of $HEAD_SHA, the head of #$PULL" - name: Setup deps uses: ./.github/actions/setup-cli-deps with: