name: Publish to NPM
on:
release:
types: [created]
workflow_dispatch:
inputs:
version:
description: 'Version to publish (leave empty for current package.json version)'
required: false
type: string
dry-run:
description: 'Perform a dry run (do not actually publish)'
required: false
type: boolean
default: false
permissions:
contents: read
id-token: write
jobs:
publish-npm:
name: Publish to NPM Registry
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: 20
registry-url: 'https://registry.npmjs.org'
- name: Setup pnpm
uses: pnpm/action-setup@v4
with:
version: latest
run_install: false
- name: Install dependencies
run: pnpm install --frozen-lockfile
- name: Run tests
run: pnpm run test:coverage
env:
CLOCKIFY_API_KEY: test-key-12345678
- name: Build package
run: pnpm run build
- name: Update version if specified
if: github.event.inputs.version != ''
run: pnpm version ${{ github.event.inputs.version }} --no-git-tag-version
- name: Verify package contents
run: |
pnpm pack --dry-run
echo "Package contents:"
tar -tzf "$(pnpm pack --silent)" | head -20
- name: Publish to NPM (dry run)
if: github.event.inputs.dry-run == 'true'
run: pnpm publish --dry-run
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
- name: Publish to NPM
if: github.event.inputs.dry-run != 'true'
run: pnpm publish
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
- name: Create GitHub release notes
if: github.event_name == 'release' && github.event.inputs.dry-run != 'true'
uses: actions/github-script@v7
with:
script: |
const package = require('./package.json');
const version = package.version;
await github.rest.repos.updateRelease({
owner: context.repo.owner,
repo: context.repo.repo,
release_id: context.payload.release.id,
body: `## Clockify Master MCP v${version}
📦 **Published to NPM**: \`@hongkongkiwi/clockify-master-mcp@${version}\`
### Installation
\`\`\`bash
npm install -g @hongkongkiwi/clockify-master-mcp
\`\`\`
### Quick Setup
\`\`\`json
{
"mcpServers": {
"clockify": {
"command": "npx",
"args": ["@hongkongkiwi/clockify-master-mcp"],
"env": {
"CLOCKIFY_API_KEY": "your_api_key_here"
}
}
}
}
\`\`\`
${context.payload.release.body || ''}
`
});
notify-success:
name: Notify Success
runs-on: ubuntu-latest
needs: publish-npm
if: success() && github.event.inputs.dry-run != 'true'
steps:
- name: Notify deployment success
run: |
echo "✅ Successfully published Clockify Master MCP to NPM!"
echo "📦 Package: @hongkongkiwi/clockify-master-mcp"
echo "🚀 Users can now install with: npx @hongkongkiwi/clockify-master-mcp"