publish.yml•6.23 kB
# This workflow will do a clean installation of node dependencies, cache/restore them, build the source code and run tests across different versions of node
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-nodejs
name: npm-mcp-server
on:
push:
branches: [main]
pull_request:
branches: [main]
jobs:
quality:
runs-on: ${{matrix.os}}
timeout-minutes: 10
strategy:
matrix:
node-version: [20.9.0, lts/*]
os: [ubuntu-latest]
steps:
- uses: actions/checkout@v4
- name: Use Node.js ${{matrix.node-version}}
uses: actions/setup-node@v4
with:
node-version: ${{matrix.node-version}}
cache: 'npm'
- run: npm ci
- name: Handle optional dependencies
run: |
# Force reinstall to handle optional dependencies properly
npm ci --no-optional
# Install optional dependencies separately if needed
npm install --optional
- name: Lint
run: npm run lint --if-present
- name: Test
run: npm run test
- name: Build STDIO
run: npm run build:stdio
- name: Build HTTP
run: npm run build:http
publish:
permissions:
contents: write
id-token: write
runs-on: ubuntu-latest
timeout-minutes: 15
if: ${{github.ref == 'refs/heads/main'}}
needs: [quality]
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Use Node.js 20.9.0
uses: actions/setup-node@v4
with:
node-version: '20.9.0'
cache: 'npm'
registry-url: 'https://registry.npmjs.org'
- run: npm ci
- name: Semantic Release
run: npm run semantic-release
env:
GH_TOKEN: ${{secrets.GH_TOKEN}}
NODE_AUTH_TOKEN: ${{secrets.NPM_TOKEN}}
NPM_TOKEN: ${{secrets.NPM_TOKEN}}
NPM_CONFIG_PROVENANCE: true
# Get the new version from package.json after semantic-release
- name: Get new version
id: get_version
run: |
NEW_VERSION=$(node -p "require('./package.json').version")
echo "new_version=$NEW_VERSION" >> $GITHUB_OUTPUT
echo "📦 New version: $NEW_VERSION"
# Update server.json version and SHA256 (like the example workflow)
- name: Update server.json version and SHA256
run: |
VERSION=$(node -p "require('./package.json').version")
echo "📦 Updating server.json with version: $VERSION"
# Replace {{VERSION}} with actual version in server.json using temp file
sed "s/{{VERSION}}/$VERSION/g" server.json > server.json.tmp
mv server.json.tmp server.json
echo "✅ server.json updated successfully"
echo "📋 Final server.json version:"
cat server.json | jq '.version, .packages[0].version'
# Build STDIO version for npm package (excludes Smithery artifacts)
- name: Build STDIO version for npm package
run: |
npm run build:stdio
# Remove Smithery artifacts to avoid publishing them to npm
rm -rf .smithery/
rm -rf node_modules/@smithery/
# Verify npm package contents
- name: Verify npm package contents
run: |
echo "=== NPM Package Contents ==="
ls -la dist/
echo "=== Excluded Smithery artifacts ==="
ls -la .smithery/ 2>/dev/null || echo "Smithery artifacts removed successfully"
echo "=== Version in compiled code ==="
grep -n "version:" dist/index.js | head -1
# Install MCP Publisher for registry publishing
- name: Install MCP Publisher
run: |
curl -L "https://github.com/modelcontextprotocol/registry/releases/download/v1.0.0/mcp-publisher_1.0.0_$(uname -s | tr '[:upper:]' '[:lower:]')_$(uname -m | sed 's/x86_64/amd64/;s/aarch64/arm64/').tar.gz" | tar xz mcp-publisher
# Login to MCP Registry using GitHub OIDC
- name: Login to MCP Registry
run: ./mcp-publisher login github-oidc
# Publish to MCP Registry
- name: Publish to MCP Registry
run: ./mcp-publisher publish
# Build HTTP version for Smithery deployment (separate from npm)
- name: Build HTTP version for Smithery
run: |
npm run build:http
echo "=== Smithery build artifacts ==="
ls -la .smithery/
# Verify Smithery deployment readiness
- name: Verify Smithery deployment readiness
run: |
echo "=== Required files for Smithery deploy ==="
echo "smithery.yaml:"
cat smithery.yaml
echo ""
echo "package.json module field:"
node -p "require('./package.json').module"
echo ""
echo "Smithery build artifacts:"
ls -la .smithery/
echo ""
echo "✅ Smithery deployment files verified!"
# Set Dockerfile version label from package.json
- name: Set Dockerfile version label from package.json
run: |
VERSION=$(node -p "require('./package.json').version")
sed -i "s/LABEL version=\"[^\"]*\"/LABEL version=\"$VERSION\"/" Dockerfile