name: Publish NPM Package
on:
push:
tags:
- 'v*'
workflow_dispatch:
inputs:
version_type:
description: 'Version bump type'
required: true
type: choice
options:
- patch
- minor
- major
default: 'patch'
env:
NODE_VERSION: '20'
PNPM_VERSION: '8'
jobs:
build-and-test:
name: Build and Test
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: ${{ env.NODE_VERSION }}
- name: Setup pnpm
uses: pnpm/action-setup@v2
with:
version: ${{ env.PNPM_VERSION }}
- name: Get pnpm store directory
shell: bash
run: |
echo "STORE_PATH=$(pnpm store path --silent)" >> $GITHUB_ENV
- name: Setup pnpm cache
uses: actions/cache@v4
with:
path: ${{ env.STORE_PATH }}
key: ${{ runner.os }}-pnpm-store-${{ hashFiles('**/pnpm-lock.yaml') }}
restore-keys: |
${{ runner.os }}-pnpm-store-
- name: Install dependencies
run: pnpm install
- name: Type check
run: pnpm run type-check
- name: Build
run: pnpm run build
- name: Run tests
run: pnpm test || echo "Tests not blocking release"
- name: Upload build artifacts
uses: actions/upload-artifact@v4
with:
name: dist
path: dist/
retention-days: 1
publish-npm:
name: Publish to NPM
runs-on: ubuntu-latest
needs: build-and-test
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
with:
node-version: ${{ env.NODE_VERSION }}
registry-url: 'https://registry.npmjs.org'
- name: Setup pnpm
uses: pnpm/action-setup@v2
with:
version: ${{ env.PNPM_VERSION }}
- name: Download build artifacts
uses: actions/download-artifact@v4
with:
name: dist
path: dist/
- name: Install dependencies
run: pnpm install --frozen-lockfile --prod
- name: Get version from package.json
id: package-version
run: |
VERSION=$(node -p "require('./package.json').version")
echo "version=$VERSION" >> $GITHUB_OUTPUT
echo "Package version: $VERSION"
- name: Check if version exists on npm
id: check-version
run: |
PACKAGE_NAME="@sparesparrow/mcp-prompts"
VERSION="${{ steps.package-version.outputs.version }}"
if npm view $PACKAGE_NAME@$VERSION version 2>/dev/null; then
echo "exists=true" >> $GITHUB_OUTPUT
echo "Version $VERSION already exists on npm"
else
echo "exists=false" >> $GITHUB_OUTPUT
echo "Version $VERSION is new"
fi
- name: Publish to NPM
if: steps.check-version.outputs.exists == 'false'
run: pnpm publish --access public --no-git-checks
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
- name: Create GitHub Release
if: steps.check-version.outputs.exists == 'false' && startsWith(github.ref, 'refs/tags/')
uses: actions/create-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: ${{ github.ref_name }}
release_name: Release ${{ github.ref_name }}
body: |
## Changes in version ${{ steps.package-version.outputs.version }}
### Features
- MCP Prompts Server with full protocol support
- Multiple storage backends (Memory, File, AWS)
- Template system with variable substitution
- REST API and CLI tools
### Installation
```bash
npm install @sparesparrow/mcp-prompts@${{ steps.package-version.outputs.version }}
```
### Docker
```bash
docker pull ghcr.io/sparesparrow/mcp-prompts:${{ steps.package-version.outputs.version }}
```
draft: false
prerelease: false
- name: Version already published
if: steps.check-version.outputs.exists == 'true'
run: |
echo "::notice::Version ${{ steps.package-version.outputs.version }} already exists on npm. Skipping publish."
publish-github-packages:
name: Publish to GitHub Packages
runs-on: ubuntu-latest
needs: build-and-test
permissions:
contents: read
packages: write
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: ${{ env.NODE_VERSION }}
registry-url: 'https://npm.pkg.github.com'
scope: '@sparesparrow'
- name: Setup pnpm
uses: pnpm/action-setup@v2
with:
version: ${{ env.PNPM_VERSION }}
- name: Download build artifacts
uses: actions/download-artifact@v4
with:
name: dist
path: dist/
- name: Install dependencies
run: pnpm install --frozen-lockfile --prod
- name: Publish to GitHub Packages
run: pnpm publish --registry https://npm.pkg.github.com --no-git-checks || echo "Already published or error"
env:
NODE_AUTH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
notify:
name: Notify on Success
runs-on: ubuntu-latest
needs: [publish-npm, publish-github-packages]
if: success()
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Get version
id: version
run: |
VERSION=$(node -p "require('./package.json').version")
echo "version=$VERSION" >> $GITHUB_OUTPUT
- name: Success notification
run: |
echo "✅ Successfully published @sparesparrow/mcp-prompts@${{ steps.version.outputs.version }}"
echo "📦 NPM: https://www.npmjs.com/package/@sparesparrow/mcp-prompts"
echo "🐳 Docker: https://github.com/sparesparrow/mcp-prompts/pkgs/container/mcp-prompts"