Skip to content

Publish

Publish #1

Workflow file for this run

name: Publish
on:
release:
types: [published]
workflow_dispatch:
inputs:
dist-tag:
description: npm dist-tag
default: beta
type: choice
options:
- beta
- latest
bump:
description: Version bump (manual runs only; releases use the Git tag)
default: patch
type: choice
options:
- patch
- minor
- major
- none
jobs:
publish:
runs-on: ubuntu-latest
permissions:
contents: write
id-token: write
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: "20"
registry-url: https://registry.npmjs.org
- name: Set package version
id: version
run: |
set -euo pipefail
if [ "${{ github.event_name }}" = "release" ]; then
VERSION="${{ github.event.release.tag_name }}"
VERSION="${VERSION#v}"
npm version "$VERSION" --no-git-tag-version --allow-same-version
elif [ "${{ inputs.bump }}" != "none" ]; then
npm version "${{ inputs.bump }}" --no-git-tag-version
VERSION=$(node -p "require('./package.json').version")
else
VERSION=$(node -p "require('./package.json').version")
fi
echo "version=$VERSION" >> "$GITHUB_OUTPUT"
echo "Publishing v$VERSION"
- name: Install dependencies
run: npm ci
- name: Build
run: npm run build
- name: Publish to npm
run: npm publish --tag ${{ github.event_name == 'workflow_dispatch' && inputs.dist-tag || 'beta' }} --access public
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
- name: Commit version bump
if: github.event_name == 'workflow_dispatch' && inputs.bump != 'none'
run: |
git config user.name "github-actions[bot]"
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
git add package.json package-lock.json
git commit -m "chore: release v${{ steps.version.outputs.version }}"
git tag v${{ steps.version.outputs.version }}
git push --tags