Skip to content

ci: skip npm publish when the version is already on the registry #8

ci: skip npm publish when the version is already on the registry

ci: skip npm publish when the version is already on the registry #8

Workflow file for this run

name: release
on:
push:
tags: ["v*"]
permissions:
id-token: write # OIDC trusted publishing + npm provenance
contents: write # create the GitHub Release
jobs:
release:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- run: corepack enable
- uses: actions/setup-node@v4
with:
node-version: 22
cache: pnpm
registry-url: "https://registry.npmjs.org"
- run: pnpm install --frozen-lockfile
- run: pnpm lint
- run: pnpm check
- run: pnpm build
- run: pnpm test
- run: pnpm smoke
# OIDC trusted publishing (tokenless) requires npm >= 11.5.1
- run: npm install -g npm@latest
# Idempotent: skip when this exact version is already on the registry (e.g. a manual
# bootstrap publish, or a re-run of a released tag) so the tag still produces the GitHub
# release below instead of failing on "cannot publish over existing 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 already published — skipping npm publish."
else
npm publish --provenance --access public
fi
- run: npx changelogen@latest github release --token "$GITHUB_TOKEN"
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}