Skip to content

Prevents publishing already released npm versions #2

Prevents publishing already released npm versions

Prevents publishing already released npm versions #2

Workflow file for this run

name: Publish to npm
on:
push:
branches:
- main
workflow_dispatch:
permissions:
id-token: write
contents: read
jobs:
publish:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Check if package version is unpublished on npm
id: version-check
run: |
VERSION=$(jq -r '.version' package.json)
NAME=$(jq -r '.name' package.json)
echo "Package: $NAME"
echo "Version: $VERSION"
if npm view "$NAME@$VERSION" version > /dev/null 2>&1; then
echo "Version $VERSION of $NAME is already published on npm. Aborting."
exit 1
else
echo "Version $VERSION of $NAME is NOT published. Continuing workflow."
fi
- uses: actions/setup-node@v4
with:
node-version: '25'
registry-url: 'https://registry.npmjs.org'
scope: \@${{ github.repository_owner }}
- name: Update npm
run: npm install -g npm@latest
- run: npm ci
- run: npm run build
- run: npm publish --access public