From 56fd91795265ac3ea2330a760341bdad9e03df36 Mon Sep 17 00:00:00 2001 From: Aukevanoost Date: Sun, 15 Nov 2026 09:33:43 +0100 Subject: [PATCH] chore(release): Stage npm releases from CI for security-key approval Add a tag-triggered release workflow that verifies, builds and packs dist/ once, checks the tarball against an allowlist and runs `npm stage publish --provenance` through a stage-only trusted publisher. The tag sets the released version. --- .github/workflows/release.yml | 116 ++++++++++++++++++++++++++++++++++ 1 file changed, 116 insertions(+) create mode 100644 .github/workflows/release.yml diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000..7ddb124 --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,116 @@ +name: Release +on: + push: + tags: ['v*.*.*'] + +permissions: + contents: read + +concurrency: + group: release-${{ github.ref }} + cancel-in-progress: false + +jobs: + stage: + name: Stage on npm + runs-on: ubuntu-latest + # Must match the npm trusted-publisher config (stage-only, bound to this file + environment). + environment: npm-release + permissions: + contents: read + id-token: write + steps: + - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7 + with: + persist-credentials: false + + - uses: actions/setup-node@949feb2413d6458794dcd2491c4babbbce0c15c1 # v7 + with: + node-version: "24.x" + registry-url: "https://registry.npmjs.org" + package-manager-cache: false + + - name: Setup PNPM + uses: pnpm/action-setup@b906affcce14559ad1aafd4ab0e942779e9f58b1 # v4 + with: + version: 11 + + # npm stage needs >=11.15; the bundled npm of Node 24 may be older. + - name: Pin npm CLI + run: npm install -g npm@11.21.1 && npm --version + + # The tag is the source of truth: post-build.mjs copies the version into dist/package.json. + - name: Use the tag's version + run: npm version "${GITHUB_REF_NAME#v}" --no-git-tag-version --allow-same-version + + - name: Dependencies OK + run: pnpm install --frozen-lockfile + + - name: Typecheck OK + run: pnpm typecheck + + - name: Build OK + run: pnpm build + + - name: Lint OK + run: pnpm lint + + - name: Knip OK + run: pnpm knip + + - name: Test OK + run: pnpm test + + - name: Audit OK + run: pnpm audit --audit-level high + env: + CI: true + + - name: Pack once + id: pack + run: | + mkdir -p out + (cd dist && npm pack --json --pack-destination ../out) > out/pack.json + # Without ./ npm reads "out/.tgz" as a GitHub user/repo shorthand. + TGZ="./out/$(node -p "require('./out/pack.json')[0].filename")" + SHASUM=$(node -p "require('./out/pack.json')[0].shasum") + INTEGRITY=$(node -p "require('./out/pack.json')[0].integrity") + echo "tgz=$TGZ" >> "$GITHUB_OUTPUT" + + tar -tzf "$TGZ" | sort > out/contents.txt + UNEXPECTED=$(grep -vE '^package/(package\.json|README\.md|LICENSE|collection\.json|generators\.json|builders\.json|migration-collection\.json|src/.+)$' out/contents.txt || true) + if [ -n "$UNEXPECTED" ]; then + echo "::error::Unexpected files in tarball:"; echo "$UNEXPECTED"; exit 1 + fi + + { + echo "### Tarball \`$(basename "$TGZ")\`" + echo "- shasum: \`$SHASUM\`" + echo "- integrity: \`$INTEGRITY\`" + echo + echo "
Contents ($(wc -l < out/contents.txt) files)" + echo + echo '```' + cat out/contents.txt + echo '```' + echo "
" + } >> "$GITHUB_STEP_SUMMARY" + + - name: Choose dist-tag + id: dist + run: | + if [[ "$GITHUB_REF_NAME" == *-* ]]; then echo "tag=next" >> "$GITHUB_OUTPUT"; else echo "tag=latest" >> "$GITHUB_OUTPUT"; fi + + - name: Stage on npm + run: | + npm stage publish "${{ steps.pack.outputs.tgz }}" --provenance --access public --tag "${{ steps.dist.outputs.tag }}" + { + echo + echo "### Staged as \`${{ steps.dist.outputs.tag }}\`, not live yet" + echo "Compare the shasum above with npmjs.com → Staged Packages (or \`npm stage view \`), then approve with your security key." + } >> "$GITHUB_STEP_SUMMARY" + + - uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2 + with: + name: staged-tarball + path: out/