Skip to content

Publish NPM package

Publish NPM package #6

Workflow file for this run

name: Publish NPM package
on:
push:
tags:
- v*.*.*
- v*.*.*-*-*
jobs:
publish:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Setup Node.js
uses: actions/setup-node@v3
with:
registry-url: https://npm.pkg.github.com
cache: npm
- name: Check tag version with package.json version
run: |
TAG_VERSION=$(echo $GITHUB_REF | sed -n 's/refs\/tags\/v\([0-9]*\.[0-9]*\.[0-9]*\(-[a-zA-Z0-9]*\)\?\)/\1/p')
PACKAGE_VERSION=$(node -p "require('./package.json').version")
if [ "$TAG_VERSION" != "$PACKAGE_VERSION" ]; then
echo "Tag version ($TAG_VERSION) does not match package.json version ($PACKAGE_VERSION)"
exit 1
fi
- name: Install dependencies
run: npm ci
- name: Update version
run: npm version $TAG_VERSION --allow-same-version
- name: Publish to GitHub Packages
run: npm publish --access public
env:
NODE_AUTH_TOKEN: ${{ secrets.GITHUB_TOKEN }}