Skip to content

Publish to NPM

Publish to NPM #2

Workflow file for this run

name: Publish to NPM
on:
push:
tags:
- 'v*.*.*'
workflow_dispatch:
jobs:
publish:
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Check if tag is from master
id: check_tag
run: |
BRANCH=$(git branch -r --contains ${{ github.sha }} | grep 'origin/master' || true)
if [ -z "$BRANCH" ]; then
echo "Tag was not created from master. Skipping publish."
exit 1
fi
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: '20'
registry-url: 'https://registry.npmjs.org'
- name: Install dependencies
run: npm ci
- name: Run lint (if present)
run: npm run lint --if-present
continue-on-error: false
- name: Run tests (if present)
run: npm test --if-present
continue-on-error: false
- name: Build package
run: npm run build
- name: Publish to NPM
run: npm publish --access public
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}