Skip to content

Publish to NPM

Publish to NPM #6

Workflow file for this run

name: Publish to NPM
on:
release:
types: [published]
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout code
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'
cache: 'npm'
- name: Validate package version
run: |
PACKAGE_VERSION=$(node -p "require('./package.json').version")
RELEASE_VERSION=${GITHUB_REF#refs/tags/v}
if [ "$PACKAGE_VERSION" != "$RELEASE_VERSION" ]; then
echo "Package version ($PACKAGE_VERSION) does not match release version ($RELEASE_VERSION)"
exit 1
fi
- name: Install dependencies
run: npm ci
- name: Run tests
run: npm test
- name: Build package
run: npm run build
- name: Publish to NPM
run: npm publish --access public
env:
NODE_AUTH_TOKEN: ${{secrets.NPM_TOKEN}}