Skip to content

Publish

Publish #16

Workflow file for this run

name: Publish
on:
workflow_run:
workflows: ["CI"]
types:
- completed
branches:
- main
jobs:
publish:
runs-on: ubuntu-latest
# Explicit permissions for this workflow
permissions:
contents: write # Allows reading and writing repository contents (for git push)
pull-requests: read # Allows reading PR information
actions: read # Allows reading workflow information
# Only run if CI workflow succeeded and the last commit was not made by GitHub Actions
if: >
github.event.workflow_run.conclusion == 'success' &&
github.event.workflow_run.head_commit.author.email != 'action@github.com' &&
!contains(github.event.workflow_run.head_commit.message, '[skip publish]')
steps:
- name: Checkout
uses: actions/checkout@v4
with:
token: ${{ secrets.GITHUB_TOKEN }}
fetch-depth: 0
ref: main
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: "22"
cache: "npm"
registry-url: "https://registry.npmjs.org"
- name: Install dependencies
run: npm ci
- name: Configure Git
run: |
git config --local user.email "action@github.com"
git config --local user.name "GitHub Action"
- name: Bump version
run: |
# Get current version
CURRENT_VERSION=$(node -p "require('./package.json').version")
echo "Current version: $CURRENT_VERSION"
# Bump patch version
npm version patch --no-git-tag-version
# Get new version
NEW_VERSION=$(node -p "require('./package.json').version")
echo "New version: $NEW_VERSION"
# Commit the version bump
git add package.json
git add package-lock.json
git commit -m "chore: bump version to $NEW_VERSION [skip publish]"
# Push the changes
git push origin main
- name: Build
run: npm run build
- name: Verify NPM Authentication
run: |
echo "Verifying NPM authentication..."
npm whoami
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
- name: Publish to NPM
run: |
echo "Publishing to NPM..."
npm publish --dry-run
echo "Dry run successful, proceeding with actual publish..."
npm publish
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}