Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
116 changes: 116 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -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/<file>.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 "<details><summary>Contents ($(wc -l < out/contents.txt) files)</summary>"
echo
echo '```'
cat out/contents.txt
echo '```'
echo "</details>"
} >> "$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 <id>\`), then approve with your security key."
} >> "$GITHUB_STEP_SUMMARY"

- uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2
with:
name: staged-tarball
path: out/
Loading