Skip to content

Publish Package to npmjs #15

Publish Package to npmjs

Publish Package to npmjs #15

Workflow file for this run

name: Publish Package to npmjs
on:
workflow_run:
workflows: [Node.js CI]
types: [completed]
branches: [main]
jobs:
publish_to_npm:
runs-on: ubuntu-latest
if: ${{ github.event.workflow_run.conclusion == 'success' }}
permissions:
actions: write # “andymckay/cancel-action” requires “write” access to the “actions” permission
id-token: write # Provenance generation in GitHub Actions requires “write” access to the “id-token” permission
steps:
-
name: Checkout repository
uses: actions/checkout@v4
-
name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: '18.18.0'
registry-url: 'https://registry.npmjs.org'
-
name: Check if package version has changed
id: check
run: |
LATEST_VERSION=$(npm view . version)
CURRENT_VERSION=$(node -p "require('./package.json').version")
if [ "$LATEST_VERSION" != "$CURRENT_VERSION" ]; then
echo "Version changed from $LATEST_VERSION to $CURRENT_VERSION"
echo "VERSION_CHANGED=true" >> $GITHUB_OUTPUT
else
echo "Version unchanged"
echo "VERSION_CHANGED=false" >> $GITHUB_OUTPUT
fi
-
name: Cancelling
uses: andymckay/[email protected]
if: ${{ steps.check.outputs.VERSION_CHANGED == 'false' }}
-
name: Install dependencies
if: ${{ steps.check.outputs.VERSION_CHANGED == 'true' }}
run: npm ci
-
name: Publish to npm
if: ${{ steps.check.outputs.VERSION_CHANGED == 'true' }}
run: npm publish --provenance --access public
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}