Publish to NPM #1
This file contains hidden or 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
name: Publish to NPM | |
on: | |
release: | |
types: [created] | |
workflow_dispatch: | |
inputs: | |
version: | |
description: 'Version bump type (major, minor, patch)' | |
required: true | |
default: 'patch' | |
type: choice | |
options: | |
- patch | |
- minor | |
- major | |
jobs: | |
publish: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v4 | |
with: | |
fetch-depth: 0 | |
- name: Setup Git | |
run: | | |
git config --local user.email "[email protected]" | |
git config --local user.name "GitHub Action" | |
- name: Setup Node.js | |
uses: actions/setup-node@v4 | |
with: | |
node-version: '18' | |
registry-url: 'https://registry.npmjs.org' | |
- name: Install dependencies | |
run: npm ci | |
- name: Run tests | |
run: npm test | |
continue-on-error: true # Skip if no tests exist | |
- name: Bump version | |
if: github.event_name == 'workflow_dispatch' | |
run: | | |
npm version ${{ github.event.inputs.version }} -m "chore(release): %s" | |
- name: Set version from release | |
if: github.event_name == 'release' | |
run: | | |
VERSION=${GITHUB_REF#refs/tags/v} | |
npm version $VERSION --no-git-tag-version | |
- name: Publish to NPM | |
run: npm publish --access public | |
env: | |
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} | |
- name: Push changes | |
run: | | |
git push | |
git push --tags | |
env: | |
github_token: ${{ secrets.GITHUB_TOKEN }} |