feat: Improve file content retrieval and error handling in Azure DevO… #6
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Publish to npm | |
on: | |
push: | |
branches: [ "main" ] | |
# Exclude paths that shouldn't trigger a build/release | |
paths-ignore: | |
- '**.md' | |
- '.github/**' | |
- '.vscode/**' | |
- '.gitignore' | |
- 'LICENSE' | |
- 'docs/**' | |
release: | |
types: [created] | |
workflow_dispatch: | |
inputs: | |
force_publish: | |
description: 'Force publish even if version exists' | |
required: false | |
type: boolean | |
default: false | |
jobs: | |
publish: | |
runs-on: ubuntu-latest | |
permissions: | |
contents: write | |
packages: write | |
steps: | |
- uses: actions/checkout@v3 | |
with: | |
fetch-depth: 0 | |
- name: Use Node.js | |
uses: actions/setup-node@v3 | |
with: | |
node-version: '20.x' | |
cache: 'npm' | |
registry-url: 'https://registry.npmjs.org' | |
- name: Setup Git | |
run: | | |
git config user.name "GitHub Actions Bot" | |
git config user.email "[email protected]" | |
- name: Install dependencies | |
run: npm ci | |
- name: Run checks | |
run: npm run check | |
- name: Run security check | |
run: npm run security-check | |
- name: Build | |
run: npm run build | |
# This only runs on main branch pushes that have modified package.json or are from a release event | |
- name: Extract version from package.json | |
id: extract_version | |
run: echo "version=$(node -p "require('./package.json').version")" >> $GITHUB_OUTPUT | |
- name: Check if version exists | |
id: version_check | |
run: | | |
if npm view cursor-azure-devops-mcp@${{ steps.extract_version.outputs.version }} version &> /dev/null; then | |
echo "exists=true" >> $GITHUB_OUTPUT | |
echo "Version ${{ steps.extract_version.outputs.version }} already exists on npm" | |
else | |
echo "exists=false" >> $GITHUB_OUTPUT | |
echo "Version ${{ steps.extract_version.outputs.version }} doesn't exist yet" | |
fi | |
continue-on-error: true | |
# Auto bump version if it already exists and force_publish is true or triggered by push | |
- name: Auto bump version if needed | |
id: auto_bump | |
if: | | |
(steps.version_check.outputs.exists == 'true') && | |
((github.event_name == 'push') || (github.event_name == 'workflow_dispatch' && inputs.force_publish)) | |
run: | | |
echo "Auto-bumping version because version ${{ steps.extract_version.outputs.version }} already exists" | |
npm version patch -m "Auto bump version to %s [skip ci]" | |
echo "new_version=$(node -p "require('./package.json').version")" >> $GITHUB_OUTPUT | |
# Get final version to use | |
- name: Determine final version | |
id: final_version | |
run: | | |
if [[ "${{ steps.auto_bump.outputs.new_version }}" != "" ]]; then | |
echo "version=${{ steps.auto_bump.outputs.new_version }}" >> $GITHUB_OUTPUT | |
echo "Using auto-bumped version: ${{ steps.auto_bump.outputs.new_version }}" | |
else | |
echo "version=${{ steps.extract_version.outputs.version }}" >> $GITHUB_OUTPUT | |
echo "Using original version: ${{ steps.extract_version.outputs.version }}" | |
fi | |
# Debug event info | |
echo "==== Debug Information ====" | |
echo "Event name: ${{ github.event_name }}" | |
echo "Current version: ${{ steps.extract_version.outputs.version }}" | |
echo "Version exists: ${{ steps.version_check.outputs.exists }}" | |
echo "Auto-bump triggered: ${{ steps.auto_bump.outputs.new_version != '' }}" | |
echo "Final version for publishing: ${{ steps.final_version.outputs.version }}" | |
echo "===========================" | |
# Push changes if version was bumped | |
- name: Push changes if version was bumped | |
if: steps.auto_bump.outputs.new_version != '' | |
run: | | |
git push | |
git push --tags | |
# Create GitHub release if version was bumped or if the version doesn't exist (for manual releases) | |
- name: Create GitHub Release | |
if: | | |
(steps.auto_bump.outputs.new_version != '') || | |
(steps.version_check.outputs.exists == 'false') | |
uses: softprops/action-gh-release@v1 | |
with: | |
tag_name: v${{ steps.final_version.outputs.version }} | |
name: Release v${{ steps.final_version.outputs.version }} | |
generate_release_notes: true | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
# Debug publishing conditions | |
- name: Debug publishing conditions | |
run: | | |
echo "==== Publishing Conditions ====" | |
echo "Version doesn't exist: ${{ steps.version_check.outputs.exists == 'false' }}" | |
echo "Auto-bumped version: ${{ steps.auto_bump.outputs.new_version != '' }}" | |
echo "Should publish: ${{ (steps.version_check.outputs.exists == 'false') || (steps.auto_bump.outputs.new_version != '') }}" | |
echo "===============================" | |
# Publish to npm if: | |
# 1. The version doesn't exist on npm, OR | |
# 2. We auto-bumped to a new version | |
- name: Publish to npm | |
if: | | |
(steps.version_check.outputs.exists == 'false') || | |
(steps.auto_bump.outputs.new_version != '') | |
run: | | |
echo "Publishing version ${{ steps.final_version.outputs.version }} to npm" | |
npm publish | |
env: | |
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} |