name: CI & Publish
on:
push:
branches: [main]
paths-ignore: ['*.md', 'docs/**', 'LICENSE', '.gitignore']
workflow_dispatch:
inputs:
bump:
description: 'Version bump type'
required: false
type: choice
default: patch
options: [patch, minor, major]
permissions:
contents: write
id-token: write
jobs:
build:
runs-on: ubuntu-latest
if: "!contains(github.event.head_commit.message, '[skip ci]')"
steps:
- uses: actions/checkout@v4
with:
token: ${{ secrets.GITHUB_TOKEN }}
fetch-depth: 0
- uses: actions/setup-node@v4
with:
node-version: 20
registry-url: https://registry.npmjs.org
- run: npm install -g npm@latest
- run: npm ci
- run: npm run build
- name: Check version on npm
id: check
run: |
PKG_NAME=$(node -p "require('./package.json').name")
PKG_VER=$(node -p "require('./package.json').version")
echo "name=$PKG_NAME version=$PKG_VER"
if npm view "${PKG_NAME}@${PKG_VER}" version --registry https://registry.npmjs.org 2>/dev/null; then
echo "exists=true" >> "$GITHUB_OUTPUT"
echo "Version ${PKG_VER} already exists on npm"
else
echo "exists=false" >> "$GITHUB_OUTPUT"
echo "Version ${PKG_VER} not found on npm"
fi
- name: Bump version
id: bump
if: steps.check.outputs.exists == 'true' && github.actor != 'github-actions[bot]'
run: |
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
BUMP="${{ inputs.bump || 'patch' }}"
npm version "$BUMP" -m "chore: bump version to %s [skip ci]"
NEW_VER=$(node -p "require('./package.json').version")
echo "Bumped to ${NEW_VER}"
git push && git push --tags
echo "bumped=true" >> "$GITHUB_OUTPUT"
- name: Publish to npm (OIDC provenance)
if: steps.check.outputs.exists == 'false' || steps.bump.outputs.bumped == 'true'
run: npm publish --access public --provenance