|
| 1 | +name: Publish to NPM |
| 2 | + |
| 3 | +on: |
| 4 | + # Trigger on version tags (e.g., v1.0.0, v1.2.3) |
| 5 | + push: |
| 6 | + tags: |
| 7 | + - 'v*' |
| 8 | + |
| 9 | + # Allow manual trigger from Actions tab |
| 10 | + workflow_dispatch: |
| 11 | + inputs: |
| 12 | + tag: |
| 13 | + description: 'Tag to publish (e.g., v1.0.0)' |
| 14 | + required: false |
| 15 | + type: string |
| 16 | + |
| 17 | +jobs: |
| 18 | + publish: |
| 19 | + runs-on: ubuntu-latest |
| 20 | + |
| 21 | + permissions: |
| 22 | + contents: read |
| 23 | + id-token: write # Required for NPM provenance |
| 24 | + |
| 25 | + steps: |
| 26 | + - name: Checkout code |
| 27 | + uses: actions/checkout@v4 |
| 28 | + with: |
| 29 | + fetch-depth: 0 |
| 30 | + |
| 31 | + - name: Setup pnpm |
| 32 | + uses: pnpm/action-setup@v4 |
| 33 | + with: |
| 34 | + version: 9.0.0 |
| 35 | + |
| 36 | + - name: Setup Node.js |
| 37 | + uses: actions/setup-node@v4 |
| 38 | + with: |
| 39 | + node-version: '18.20.0' |
| 40 | + cache: 'pnpm' |
| 41 | + registry-url: 'https://registry.npmjs.org' |
| 42 | + |
| 43 | + - name: Install dependencies |
| 44 | + run: pnpm install --frozen-lockfile |
| 45 | + |
| 46 | + - name: Run type check |
| 47 | + run: pnpm run typecheck |
| 48 | + |
| 49 | + - name: Run tests |
| 50 | + run: pnpm test -- run --passWithNoTests |
| 51 | + |
| 52 | + # TODO: Re-enable once ESLint is properly configured for v9 |
| 53 | + # - name: Run linter |
| 54 | + # run: pnpm run lint |
| 55 | + |
| 56 | + - name: Build package |
| 57 | + run: pnpm run build |
| 58 | + |
| 59 | + - name: Verify build outputs |
| 60 | + run: | |
| 61 | + echo "Checking dist/ directory..." |
| 62 | + ls -la dist/ |
| 63 | + echo "Checking mcp/dist/ directory..." |
| 64 | + ls -la mcp/dist/ |
| 65 | +
|
| 66 | + - name: Extract version from tag |
| 67 | + id: extract_version |
| 68 | + run: | |
| 69 | + if [ "${{ github.event_name }}" = "workflow_dispatch" ] && [ -n "${{ inputs.tag }}" ]; then |
| 70 | + TAG="${{ inputs.tag }}" |
| 71 | + else |
| 72 | + TAG="${GITHUB_REF#refs/tags/}" |
| 73 | + fi |
| 74 | + VERSION="${TAG#v}" |
| 75 | + echo "tag=$TAG" >> $GITHUB_OUTPUT |
| 76 | + echo "version=$VERSION" >> $GITHUB_OUTPUT |
| 77 | + echo "Publishing version: $VERSION" |
| 78 | +
|
| 79 | + - name: Verify package.json version matches tag |
| 80 | + run: | |
| 81 | + PACKAGE_VERSION=$(node -p "require('./package.json').version") |
| 82 | + TAG_VERSION="${{ steps.extract_version.outputs.version }}" |
| 83 | + echo "package.json version: $PACKAGE_VERSION" |
| 84 | + echo "Tag version: $TAG_VERSION" |
| 85 | + if [ "$PACKAGE_VERSION" != "$TAG_VERSION" ]; then |
| 86 | + echo "Error: package.json version ($PACKAGE_VERSION) does not match tag version ($TAG_VERSION)" |
| 87 | + exit 1 |
| 88 | + fi |
| 89 | +
|
| 90 | + - name: Create .npmrc |
| 91 | + run: | |
| 92 | + cat << EOF > "$HOME/.npmrc" |
| 93 | + //registry.npmjs.org/:_authToken=\$NPM_TOKEN |
| 94 | + EOF |
| 95 | +
|
| 96 | + - name: Publish to NPM |
| 97 | + env: |
| 98 | + NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} |
| 99 | + NPM_TOKEN: ${{ secrets.NPM_TOKEN }} |
| 100 | + run: | |
| 101 | + # Publish with provenance for supply chain security |
| 102 | + pnpm publish --no-git-checks --access public --provenance |
| 103 | +
|
| 104 | + - name: Create GitHub Release |
| 105 | + uses: softprops/action-gh-release@v2 |
| 106 | + if: startsWith(github.ref, 'refs/tags/') |
| 107 | + with: |
| 108 | + generate_release_notes: true |
| 109 | + draft: false |
| 110 | + prerelease: false |
| 111 | + env: |
| 112 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
0 commit comments