name: Publish API to MCP to npm
on:
push:
tags:
- "v*" # Trigger on tags like v1.0.0, v1.1.0, etc.
permissions:
contents: read # Needed to check out the repository
jobs:
publish-npm:
name: Publish package to npm
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Extract version from tag
id: extract_version
run: |
# Remove 'v' prefix from tag (e.g., v1.0.0 -> 1.0.0)
VERSION="${GITHUB_REF#refs/tags/v}"
echo "VERSION=$VERSION" >> $GITHUB_ENV
echo "Extracted version: $VERSION"
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: "20" # Updated to Node.js 20 to support minimatch@10.0.1
registry-url: "https://registry.npmjs.org/"
# To use a custom scope, uncomment and modify the next line
# scope: "@your-org"
# The token is implicitly used by setup-node to configure .npmrc
# No need to explicitly pass NODE_AUTH_TOKEN to setup-node
- name: Install dependencies
run: |
# Clear npm cache to avoid any corruption
npm cache clean --force
# Install dependencies with no legacy peer deps to avoid compatibility issues
npm install --no-fund --no-audit --prefer-offline --no-package-lock
- name: Update package version
run: |
# Update version in package.json without creating a git tag
npm version ${{ env.VERSION }} --no-git-tag-version
echo "Updated package.json to version ${{ env.VERSION }}"
- name: Build package
run: npm run build # Ensure the data directory is prepared
- name: Publish to npm
run: npm publish --access public
env:
# Use the secret token for the publish command
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}