publish-manual.yml•4.4 kB
name: Manual Publish to NPM
on:
workflow_dispatch:
inputs:
version_bump:
description: 'Version bump type'
required: true
default: 'patch'
type: choice
options:
- patch
- minor
- major
- prerelease
dry_run:
description: 'Dry run (test without publishing)'
required: false
type: boolean
default: false
permissions:
contents: write
packages: write
pull-requests: write
jobs:
manual-publish:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
token: ${{ secrets.GITHUB_TOKEN }}
fetch-depth: 0
- name: Use Node.js 20.x
uses: actions/setup-node@v4
with:
node-version: 20.x
cache: 'npm'
registry-url: 'https://registry.npmjs.org'
- name: Install dependencies
run: npm ci
- name: Run tests and validation
run: |
npm run type-check
npm run lint
npm run test:ci
npm run build
- name: Configure git
run: |
git config --local user.email "action@github.com"
git config --local user.name "GitHub Action"
- name: Version bump
run: |
OLD_VERSION=$(npm pkg get version | tr -d '"')
echo "Current version: $OLD_VERSION"
# Check if we're trying to create a tag that already exists
if [ "${{ inputs.version_bump }}" = "prerelease" ]; then
NEW_VERSION=$(npm version prerelease --preid=beta --no-git-tag-version)
else
NEW_VERSION=$(npm version ${{ inputs.version_bump }} --no-git-tag-version)
fi
NEW_VERSION_CLEAN=$(echo $NEW_VERSION | tr -d '"')
echo "New version: $NEW_VERSION_CLEAN"
echo "NEW_VERSION=$NEW_VERSION_CLEAN" >> $GITHUB_ENV
# Check if tag already exists
if git rev-parse "v$NEW_VERSION_CLEAN" >/dev/null 2>&1; then
echo "❌ Tag v$NEW_VERSION_CLEAN already exists!"
exit 1
fi
- name: Build with new version
run: npm run build
- name: Test package locally
run: |
npm pack
PACKAGE_FILE=$(ls *.tgz)
echo "Testing local installation of $PACKAGE_FILE"
npm install -g "$PACKAGE_FILE"
context-mcp --help
- name: Dry run publish
if: inputs.dry_run
run: |
echo "🧪 Dry run mode - testing publish without actually publishing"
npm publish --dry-run
echo "✅ Dry run completed successfully"
- name: Publish to npm
if: '!inputs.dry_run'
run: npm publish
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
- name: Push version changes
if: '!inputs.dry_run'
run: |
echo "Pushing version changes to repository..."
git add package.json package-lock.json
git commit -m "chore: bump version to v${{ env.NEW_VERSION }}" || echo "No changes to commit"
git tag "v${{ env.NEW_VERSION }}"
# Push with retry logic
for i in {1..3}; do
if git push origin main && git push origin "v${{ env.NEW_VERSION }}"; then
echo "✅ Successfully pushed version changes and tag"
break
else
echo "⚠️ Push attempt $i failed, retrying..."
sleep 5
fi
done
- name: Create GitHub Release
if: '!inputs.dry_run'
uses: actions/create-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: v${{ env.NEW_VERSION }}
release_name: Release v${{ env.NEW_VERSION }}
body: |
Release v${{ env.NEW_VERSION }}
Changes in this release:
- Manual release triggered via workflow dispatch
- Version bump: ${{ inputs.version_bump }}
draft: false
prerelease: ${{ contains(env.NEW_VERSION, 'beta') }}
- name: Verify npm publication
if: '!inputs.dry_run'
run: |
echo "Waiting for npm registry propagation..."
sleep 30
PACKAGE_NAME=$(npm pkg get name | tr -d '"')
npm view "$PACKAGE_NAME@${{ env.NEW_VERSION }}" version
echo "✅ Package successfully published to npm"