publish-to-npm #26
Workflow file for this run
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# This workflow will run tests using node and then publish a package to GitHub Packages when a release is created | |
# For more information see: https://docs.github.com/en/actions/publishing-packages/publishing-nodejs-packages | |
name: publish-to-npm | |
on: | |
release: | |
types: [published] | |
jobs: | |
build: | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v4 | |
- uses: actions/setup-node@v4 | |
with: | |
node-version: '18.x' | |
registry-url: 'https://registry.npmjs.org' | |
- name: Compare package.json version with tag | |
run: | | |
TAG_VERSION=${GITHUB_REF#refs/tags/} | |
PACKAGE_VERSION=$(cat package.json | jq -r '.version') | |
echo "PACKAGE_VERSION=$PACKAGE_VERSION" >> $GITHUB_ENV | |
# Expects the tag to be in the format v1.0.0 | |
if [ "$TAG_VERSION" != "v$PACKAGE_VERSION" ]; then | |
echo "Tag version $TAG_VERSION does not match the package.json version $PACKAGE_VERSION" | |
exit 1 | |
fi | |
- name: Check if version is a prerelease | |
id: prerelease_check | |
run: | | |
# Explicitly tests for a non-prerelease version, assuming that we're using semver | |
NON_PRERELEASE_VERSION=$(echo $PACKAGE_VERSION | grep -E '^[0-9]+\.[0-9]+\.[0-9]+$') | |
if [ ! -z "$NON_PRERELEASE_VERSION" ]; then | |
echo "is_next=false" >> $GITHUB_ENV | |
else | |
echo "is_next=true" >> $GITHUB_ENV | |
fi | |
- name: Install dependencies | |
run: yarn install --frozen-lockfile | |
- name: Publish package | |
run: | | |
if [ "$is_next" = "true" ]; then | |
yarn publish --tag next | |
else | |
yarn publish | |
fi | |
env: | |
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} |