Skip to content

Publish to npm

Publish to npm #5

Workflow file for this run

name: Publish to npm
on:
push:
tags:
- "v*"
jobs:
publish:
name: Publish package
runs-on: ubuntu-latest
permissions:
contents: read
id-token: write
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: "20"
cache: "npm"
registry-url: https://registry.npmjs.org
scope: "@programinglive"
- name: Install dependencies
run: npm ci
- name: Build package
run: npm run build
- name: Verify tag matches package version
run: |
EXPECTED_TAG="${GITHUB_REF#refs/tags/}"
PACKAGE_VERSION=$(node -p "require('./package.json').version")
if [ "v${PACKAGE_VERSION}" != "${EXPECTED_TAG}" ]; then
echo "Package version ${PACKAGE_VERSION} does not match tag ${EXPECTED_TAG}"
exit 1
fi
- name: Publish to npm
run: npm publish --provenance