name: Publish to NPM
on:
push:
tags:
- 'v*'
workflow_dispatch:
inputs:
version:
description: 'Version to publish (e.g., patch, minor, major)'
required: true
default: 'patch'
type: choice
options:
- patch
- minor
- major
jobs:
publish:
runs-on: ubuntu-latest
permissions:
contents: write
id-token: write
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Setup Node.js
uses: actions/setup-node@v4.0.2
with:
node-version: '22'
registry-url: 'https://registry.npmjs.org'
- name: Install dependencies
run: npm ci
- name: Run tests
run: npm test
- name: Build project
run: npm run build
- name: Bump version (if triggered manually)
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 }}
git push origin HEAD:${{ github.ref_name }}
git push --tags
- name: Get package version
id: package-version
run: echo "version=$(node -p "require('./package.json').version")" >> $GITHUB_OUTPUT
- name: Check if version exists on npm
id: check-version
run: |
PACKAGE_NAME=$(node -p "require('./package.json').name")
VERSION="${{ steps.package-version.outputs.version }}"
if npm view "$PACKAGE_NAME@$VERSION" version >/dev/null 2>&1; then
echo "exists=true" >> $GITHUB_OUTPUT
echo "Version $VERSION already exists on npm"
else
echo "exists=false" >> $GITHUB_OUTPUT
echo "Version $VERSION does not exist on npm, proceeding with publish"
fi
- name: Publish to NPM with appropriate tag
if: steps.check-version.outputs.exists == 'false'
run: |
PACKAGE_VERSION="${{ steps.package-version.outputs.version }}"
# Check if this is a prerelease version (contains -, like v1.3.0-beta.0)
if [[ "$PACKAGE_VERSION" == *"-"* ]]; then
echo "Publishing prerelease version $PACKAGE_VERSION with beta tag"
npm publish --provenance --access public --tag beta
else
echo "Publishing stable version $PACKAGE_VERSION with latest tag"
npm publish --provenance --access public
fi
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
- name: Skip publish (version exists)
if: steps.check-version.outputs.exists == 'true'
run: |
echo "⚠️ Version ${{ steps.package-version.outputs.version }} already exists on npm, skipping publish"
echo "If you intended to publish a new version, please bump the version number first"
- name: Create GitHub Release
if: startsWith(github.ref, 'refs/tags/') && steps.check-version.outputs.exists == 'false'
uses: softprops/action-gh-release@v2
with:
name: Release ${{ github.ref_name }}
body: |
## Changes in this Release
- Package published to npm as `@cocal/google-calendar-mcp@${{ steps.package-version.outputs.version }}`
- Can be installed with: `npx @cocal/google-calendar-mcp@${{ steps.package-version.outputs.version }}`
### Installation
```bash
# Install globally
npm install -g @cocal/google-calendar-mcp@${{ steps.package-version.outputs.version }}
# Run directly with npx
npx @cocal/google-calendar-mcp@${{ steps.package-version.outputs.version }}
```
See the [CHANGELOG](CHANGELOG.md) for detailed changes.
draft: false
prerelease: ${{ contains(github.ref_name, '-') }}
generate_release_notes: true