Skip to content

Publish to npm

Publish to npm #5

Workflow file for this run

name: Publish to npm
on:
release:
types: [published]
workflow_dispatch:
permissions:
contents: read
id-token: write
jobs:
publish:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v6
- name: Use Node.js
uses: actions/setup-node@v6
with:
node-version: 24.x
registry-url: "https://registry.npmjs.org"
- run: npm ci
- name: Check release tag matches package version
if: github.event_name == 'release'
run: |
package_version="$(node -e "import pkg from './package.json' with {type:'json'};console.log(pkg.default.version)")"
release_version="${GITHUB_REF_NAME#v}"
if [ "$package_version" != "$release_version" ]; then
echo "Release tag ${GITHUB_REF_NAME} does not match package.json version ${package_version}"
exit 1
fi
- name: Publish to npm
run: |
package_version="$(node -e "import pkg from './package.json' with {type:'json'};console.log(pkg.default.version)")"
if npm view "hsluv-sass@${package_version}" version 2>/dev/null; then
echo "hsluv-sass@${package_version} is already published, skipping"
exit 0
fi
if [[ "$package_version" =~ -([a-zA-Z]+) ]]; then
tag="${BASH_REMATCH[1]}"
echo "Publishing prerelease with dist-tag: $tag"
npm publish --provenance --access public --tag "$tag"
else
echo "Publishing stable release"
npm publish --provenance --access public
fi