Skip to content

Publish to npm

Publish to npm #2

Workflow file for this run

name: Publish to npm
on:
release:
types: [created]
workflow_dispatch:
inputs:
version_type:
description: 'Version bump type (patch, minor, major)'
required: true
type: choice
options:
- patch
- minor
- major
jobs:
publish:
runs-on: ubuntu-latest
permissions:
contents: write
id-token: write # Required for provenance signing
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0 # Fetch all history for version bumping
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: '20'
registry-url: 'https://registry.npmjs.org'
- name: Install dependencies
run: npm ci
- name: Run tests
run: npm test
- name: Build package
run: npm run build
- name: Bump version (if workflow_dispatch)
if: github.event_name == 'workflow_dispatch'
run: |
npm version ${{ github.event.inputs.version_type }} --no-git-tag-version
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
git add package.json
git commit -m "chore: bump version to $(node -p "require('./package.json').version")"
git push
- name: Get version
id: package-version
run: echo "version=$(node -p "require('./package.json').version")" >> $GITHUB_OUTPUT
- name: Publish to npm with provenance
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
run: |
npm publish --access public --provenance
- name: Create Git tag (if workflow_dispatch)
if: github.event_name == 'workflow_dispatch'
run: |
git tag "v${{ steps.package-version.outputs.version }}"
git push origin "v${{ steps.package-version.outputs.version }}"
- name: Summary
run: |
echo "## ✅ Package Published Successfully" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "- **Package**: @return-0/mcp-server@${{ steps.package-version.outputs.version }}" >> $GITHUB_STEP_SUMMARY
echo "- **Published with**: GitHub Actions" >> $GITHUB_STEP_SUMMARY
echo "- **Provenance**: ✅ Enabled" >> $GITHUB_STEP_SUMMARY
echo "- **Install**: \`npm install -g @return-0/mcp-server\`" >> $GITHUB_STEP_SUMMARY