Skip to content

Publish NPM Packages #142

Publish NPM Packages

Publish NPM Packages #142

Workflow file for this run

name: Publish NPM Packages
on:
push:
tags:
- 'v*' # Triggers on version tags like v3.0.1, v3.0.1-pre.0, etc.
workflow_dispatch:
inputs:
dist_tag:
description: 'npm dist-tag to publish under (latest, pre, next, canary, beta, alpha)'
required: false
default: 'latest'
type: choice
options:
- latest
- pre
- next
- canary
- beta
- alpha
jobs:
publish:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 1
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: '20.x'
registry-url: 'https://registry.npmjs.org'
- name: Install dependencies
run: npm ci
- name: Build packages
run: npm run build
- name: Determine dist-tag
id: dist-tag
run: |
# If triggered manually, use the input value
if [[ "${{ github.event_name }}" == "workflow_dispatch" ]]; then
echo "tag=${{ inputs.dist_tag }}" >> $GITHUB_OUTPUT
echo "Using manual dist-tag: ${{ inputs.dist_tag }}"
exit 0
fi
TAG_NAME=${GITHUB_REF#refs/tags/}
echo "Publishing tag: $TAG_NAME"
if [[ "$TAG_NAME" == *"-pre"* ]]; then
echo "tag=pre" >> $GITHUB_OUTPUT
elif [[ "$TAG_NAME" == *"-next"* ]]; then
echo "tag=next" >> $GITHUB_OUTPUT
elif [[ "$TAG_NAME" == *"-canary"* ]]; then
echo "tag=canary" >> $GITHUB_OUTPUT
elif [[ "$TAG_NAME" == *"-beta"* ]]; then
echo "tag=beta" >> $GITHUB_OUTPUT
elif [[ "$TAG_NAME" == *"-alpha"* ]]; then
echo "tag=alpha" >> $GITHUB_OUTPUT
else
echo "tag=latest" >> $GITHUB_OUTPUT
fi
- name: Publish to npm
run: npx lerna publish from-package --yes --no-verify-access --dist-tag ${{ steps.dist-tag.outputs.tag }}
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}