name: Publish to npm
on:
release:
types: [created]
workflow_dispatch:
inputs:
version:
description: 'Version type (patch, minor, major)'
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:
token: ${{ secrets.GITHUB_TOKEN }}
- 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
run: npm run build
- name: Run tests
run: |
echo '{"jsonrpc":"2.0","method":"tools/list","id":1}' | timeout 5s node dist/index.js > test_output.json || true
grep -q '"jsonrpc":"2.0"' test_output.json || exit 1
- name: Version bump (manual trigger only)
if: github.event_name == 'workflow_dispatch'
run: |
git config --local user.email "action@github.com"
git config --local user.name "GitHub Action"
npm version ${{ github.event.inputs.version }} -m "Release v%s [skip ci]"
git push
git push --tags
- name: Publish to npm
run: npm publish --access public
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}