name: Publish on: push: tags: - 'v*' jobs: publish: runs-on: ubuntu-latest permissions: # contents: write for the auto-generated GitHub release; id-token for # trusted publishing (OIDC) — npm authenticates the workflow itself, # no NPM_TOKEN secret, no long-lived token, no 2FA prompt. contents: write id-token: write steps: - uses: actions/checkout@v4 - uses: pnpm/action-setup@v4 - uses: actions/setup-node@v4 with: node-version: 22 cache: pnpm registry-url: https://registry.npmjs.org # OIDC trusted publishing needs npm >= 11.5.1; the bundled npm on # node 22 predates it and would PUT without credentials (registry # answers 404 to hide the package's existence). - name: Upgrade npm run: npm install -g npm@latest - name: Install run: pnpm install --ignore-scripts --frozen-lockfile - name: Verify tag matches package version run: | PKG_VERSION=$(node -p "require('./package.json').version") if [ "v$PKG_VERSION" != "$GITHUB_REF_NAME" ]; then echo "::error::tag $GITHUB_REF_NAME does not match package.json version v$PKG_VERSION — bump with 'npm version ' before tagging" exit 1 fi - name: Build run: pnpm build - name: Typecheck run: pnpm typecheck - name: Lint run: pnpm lint - name: Test run: pnpm test - name: Publish run: npm publish --access public - name: Create GitHub release run: | if gh release view "$GITHUB_REF_NAME" > /dev/null 2>&1; then echo "Release $GITHUB_REF_NAME already exists — skipping creation" else gh release create "$GITHUB_REF_NAME" --verify-tag --generate-notes fi env: GH_TOKEN: ${{ github.token }}