|
| 1 | +# Publish v1.x releases when a v1.* tag is pushed |
| 2 | +# This allows releasing from the v1.x branch without switching GitHub's default branch |
| 3 | +# |
| 4 | +# Automatic (latest v1.x): |
| 5 | +# git checkout v1.x |
| 6 | +# npm version patch # bumps version and creates tag |
| 7 | +# git push origin v1.x --tags |
| 8 | +# |
| 9 | +# Manual (for older minor versions like v1.23.x): |
| 10 | +# 1. Create a release branch: git checkout -b release/1.23 v1.23.1 |
| 11 | +# 2. Apply your fixes |
| 12 | +# 3. Bump version: npm version patch # creates v1.23.2 tag |
| 13 | +# 4. Push: git push origin release/1.23 --tags |
| 14 | +# 5. Run this workflow manually from GitHub Actions, specifying the tag |
| 15 | +# |
| 16 | +# The workflow will automatically build, test, and publish to npm. |
| 17 | + |
| 18 | +name: Publish v1.x |
| 19 | + |
| 20 | +on: |
| 21 | + push: |
| 22 | + tags: |
| 23 | + - 'v1.*' |
| 24 | + workflow_dispatch: |
| 25 | + inputs: |
| 26 | + ref: |
| 27 | + description: 'Git ref to release (tag, e.g., v1.23.2)' |
| 28 | + required: true |
| 29 | + type: string |
| 30 | + |
| 31 | +permissions: |
| 32 | + contents: read |
| 33 | + |
| 34 | +concurrency: ${{ github.workflow }}-${{ inputs.ref || github.ref }} |
| 35 | + |
| 36 | +jobs: |
| 37 | + build: |
| 38 | + runs-on: ubuntu-latest |
| 39 | + |
| 40 | + steps: |
| 41 | + - uses: actions/checkout@v4 |
| 42 | + with: |
| 43 | + ref: ${{ inputs.ref || github.ref }} |
| 44 | + - uses: actions/setup-node@v4 |
| 45 | + with: |
| 46 | + node-version: 24 |
| 47 | + cache: npm |
| 48 | + |
| 49 | + - run: npm ci |
| 50 | + - run: npm run check |
| 51 | + - run: npm run build |
| 52 | + |
| 53 | + test: |
| 54 | + runs-on: ubuntu-latest |
| 55 | + strategy: |
| 56 | + fail-fast: false |
| 57 | + matrix: |
| 58 | + node-version: [18, 24] |
| 59 | + |
| 60 | + steps: |
| 61 | + - uses: actions/checkout@v4 |
| 62 | + with: |
| 63 | + ref: ${{ inputs.ref || github.ref }} |
| 64 | + - uses: actions/setup-node@v4 |
| 65 | + with: |
| 66 | + node-version: ${{ matrix.node-version }} |
| 67 | + cache: npm |
| 68 | + |
| 69 | + - run: npm ci |
| 70 | + - run: npm test |
| 71 | + |
| 72 | + publish: |
| 73 | + runs-on: ubuntu-latest |
| 74 | + needs: [build, test] |
| 75 | + environment: release |
| 76 | + |
| 77 | + permissions: |
| 78 | + contents: read |
| 79 | + id-token: write |
| 80 | + |
| 81 | + steps: |
| 82 | + - uses: actions/checkout@v4 |
| 83 | + with: |
| 84 | + ref: ${{ inputs.ref || github.ref }} |
| 85 | + - uses: actions/setup-node@v4 |
| 86 | + with: |
| 87 | + node-version: 24 |
| 88 | + cache: npm |
| 89 | + registry-url: 'https://registry.npmjs.org' |
| 90 | + |
| 91 | + - run: npm ci |
| 92 | + |
| 93 | + - name: Determine npm tag |
| 94 | + id: npm-tag |
| 95 | + run: | |
| 96 | + VERSION=$(node -p "require('./package.json').version") |
| 97 | + # Use "release-X.Y" as tag for v1.x releases |
| 98 | + # This allows users to install specific minor versions: |
| 99 | + # npm install @modelcontextprotocol/sdk@release-1.25 |
| 100 | + MAJOR_MINOR=$(echo "$VERSION" | cut -d. -f1,2) |
| 101 | + echo "tag=release-${MAJOR_MINOR}" >> $GITHUB_OUTPUT |
| 102 | +
|
| 103 | + - run: npm publish --provenance --access public --tag ${{ steps.npm-tag.outputs.tag }} |
| 104 | + env: |
| 105 | + NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} |
0 commit comments