Improves publish workflow output for already published versions #3
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 "### 🛑 Deployment aborted" >> $GITHUB_STEP_SUMMARY | |
| echo "Version $VERSION of $NAME is already published on npm." >> $GITHUB_STEP_SUMMARY | |
| echo "Skipping remaining steps." >> $GITHUB_STEP_SUMMARY | |
| exit 0 | |
| 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 |