From 7e848316fbf1b1d0cd08a1532b2b9970cbdf86a0 Mon Sep 17 00:00:00 2001 From: Claude Date: Fri, 20 Nov 2026 02:52:58 +0000 Subject: [PATCH 1/2] Add a manual workflow that publishes main to npm Run from the Actions tab. It refuses to run off main or to republish a version that is already on npm, runs the Jest, WordPress and stream wrapper checks, publishes with npm trusted publishing (no stored token, provenance attached) and creates a GitHub release tagged v. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01FkTtrKVDL3kpMPM3eAFY5X --- .github/workflows/publish.yml | 68 +++++++++++++++++++++++++++++++++++ 1 file changed, 68 insertions(+) create mode 100644 .github/workflows/publish.yml diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml new file mode 100644 index 0000000..fec7a5b --- /dev/null +++ b/.github/workflows/publish.yml @@ -0,0 +1,68 @@ +name: Publish to npm +# Publishes the package as it is on main, at the version in package.json. +# Run it from the Actions tab after merging a version bump (the Update PHP +# PRs bump the patch version). +# +# Uses npm trusted publishing: no npm token is stored here. On npmjs.com, +# under the serverlesswp package's Settings > Trusted Publisher, add GitHub +# Actions with repository mitchmac/serverlesswp-node and workflow publish.yml. + +on: + workflow_dispatch: + +permissions: + contents: write # create the release and its tag + id-token: write # npm trusted publishing and provenance + +concurrency: + group: publish + cancel-in-progress: false + +jobs: + publish: + name: publish + # The bundled php links libxml2.so.2, which ubuntu-latest (26.04) lacks. + runs-on: ubuntu-24.04 + if: github.ref == 'refs/heads/main' + steps: + - name: Checkout + uses: actions/checkout@v4 + + - uses: actions/setup-node@v4 + with: + node-version: 22 + registry-url: 'https://registry.npmjs.org' + cache: 'npm' + cache-dependency-path: 'package-lock.json' + + # Trusted publishing needs npm 11.5.1 or later; Node 22 ships npm 10. + - name: Update npm + run: npm install -g npm@11 + + - name: Check the version is unpublished + id: version + run: | + name=$(node -p "require('./package.json').name") + version=$(node -p "require('./package.json').version") + if npm view "$name@$version" version > /dev/null 2>&1; then + echo "$name@$version is already on npm. Bump the version in package.json first." >&2 + exit 1 + fi + echo "version=$version" >> "$GITHUB_OUTPUT" + + - run: npm ci + + - run: npm run test + - run: npm run test:wordpress + + - name: Check the bundled stream wrapper matches its source + run: ./packages/serverlesswp-stream-wrapper/build-plugin.sh --check + + - name: Publish + run: npm publish --provenance --access public + + - name: Create GitHub release + env: + GH_TOKEN: ${{ github.token }} + VERSION: ${{ steps.version.outputs.version }} + run: gh release create "v$VERSION" --target "$GITHUB_SHA" --title "v$VERSION" --generate-notes From 10d8f5028bfd22588ffa1d6ea1b9894a919ccefa Mon Sep 17 00:00:00 2001 From: Claude Date: Fri, 20 Nov 2026 03:12:04 +0000 Subject: [PATCH 2/2] Stage releases on npm instead of publishing directly The trusted publisher is set up stage-only, so the workflow now runs npm stage publish and a maintainer approves the version with 2FA before it goes live. The GitHub release is created as a draft, so there is no tag for a version that has not been approved, and the run summary lists the approval steps. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01FkTtrKVDL3kpMPM3eAFY5X --- .github/workflows/publish.yml | 42 +++++++++++++++++++++++++---------- 1 file changed, 30 insertions(+), 12 deletions(-) diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index fec7a5b..8e58718 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -1,17 +1,22 @@ name: Publish to npm -# Publishes the package as it is on main, at the version in package.json. -# Run it from the Actions tab after merging a version bump (the Update PHP -# PRs bump the patch version). +# Stages the package as it is on main, at the version in package.json, for +# release on npm. Run it from the Actions tab after merging a version bump +# (the Update PHP PRs bump the patch version). # -# Uses npm trusted publishing: no npm token is stored here. On npmjs.com, -# under the serverlesswp package's Settings > Trusted Publisher, add GitHub -# Actions with repository mitchmac/serverlesswp-node and workflow publish.yml. +# Uses npm trusted publishing with staged publishing: no npm token is stored +# here, and the workflow cannot release on its own. Nothing goes live until a +# maintainer approves the staged version with 2FA, in the package's Staged +# Packages tab on npmjs.com or with `npm stage approve `. +# +# On npmjs.com, under the serverlesswp package's Settings > Trusted Publisher, +# add GitHub Actions with repository mitchmac/serverlesswp-node and workflow +# publish.yml, leaving "Allow npm publish" unchecked. on: workflow_dispatch: permissions: - contents: write # create the release and its tag + contents: write # create the draft release id-token: write # npm trusted publishing and provenance concurrency: @@ -35,7 +40,7 @@ jobs: cache: 'npm' cache-dependency-path: 'package-lock.json' - # Trusted publishing needs npm 11.5.1 or later; Node 22 ships npm 10. + # Staged publishing needs npm 11.15.0 or later; Node 22 ships npm 10. - name: Update npm run: npm install -g npm@11 @@ -58,11 +63,24 @@ jobs: - name: Check the bundled stream wrapper matches its source run: ./packages/serverlesswp-stream-wrapper/build-plugin.sh --check - - name: Publish - run: npm publish --provenance --access public + - name: Stage on npm + run: npm stage publish --access public - - name: Create GitHub release + # A draft, so there is no tag or release for a version that has not been + # approved. Publish it from the Releases page after approving on npm. + - name: Create draft GitHub release env: GH_TOKEN: ${{ github.token }} VERSION: ${{ steps.version.outputs.version }} - run: gh release create "v$VERSION" --target "$GITHUB_SHA" --title "v$VERSION" --generate-notes + run: gh release create "v$VERSION" --draft --target "$GITHUB_SHA" --title "v$VERSION" --generate-notes + + - name: Summary + env: + VERSION: ${{ steps.version.outputs.version }} + run: | + { + echo "serverlesswp@$VERSION is staged on npm and is not live yet." + echo + echo "1. Approve it in the Staged Packages tab at https://www.npmjs.com/package/serverlesswp (2FA required)." + echo "2. Then publish the draft release v$VERSION from the Releases page." + } >> "$GITHUB_STEP_SUMMARY"