1+ # Publishes every package whose version the registry does not have yet, when a
2+ # maintainer publishes a GitHub Release (#4472). The procedure is RELEASING.md.
3+ #
4+ # No job here computes, stamps or tags a version. The version in each
5+ # package.json / pyproject.toml on the released ref is the source of truth: it
6+ # got there through a reviewed PR (changesets' "Version Packages" for the
7+ # TypeScript servers, "Prepare Python Release" for the Python ones), and the
8+ # release tag is only a label on tested code. So a tag can never disagree with
9+ # a version, and there is nothing to push back to a branch.
10+ #
11+ # Every package is a matrix leg, and each leg decides for itself: a version
12+ # already on the registry is SKIPPED, not failed. That makes a release
13+ # idempotent and self-healing. A package whose publish failed is picked up by
14+ # the next release with no special handling, and one that did not change costs
15+ # a skipped leg.
16+ #
17+ # The trigger is `release: published` and nothing else, so editing a
18+ # published Release's notes never re-runs publishing. A release event runs the
19+ # workflow as it is AT THE TAG, which is why the fix for a broken publish step
20+ # has to reach `main` and be released again rather than re-run.
21+ #
22+ # Authentication is OIDC trusted publishing on both registries: there are no
23+ # registry tokens. Each trusted publisher is bound to this workflow's filename
24+ # (`release.yml`) and the `release` environment, so the publish jobs must stay
25+ # in this file and keep that environment.
26+
127name : Release
228
329on :
4- workflow_dispatch :
30+ release :
31+ types : [published]
532
633jobs :
7- create-metadata :
8- timeout-minutes : 10
34+ detect-packages :
35+ timeout-minutes : 5
936 runs-on : ubuntu-latest
1037 if : github.repository_owner == 'modelcontextprotocol'
1138 outputs :
12- hash : ${{ steps.last-release.outputs.hash }}
13- version : ${{ steps.create-version.outputs.version}}
14- npm_packages : ${{ steps.create-npm-packages.outputs.npm_packages}}
15- pypi_packages : ${{ steps.create-pypi-packages.outputs.pypi_packages}}
39+ npm_packages : ${{ steps.find-packages.outputs.npm_packages }}
40+ pypi_packages : ${{ steps.find-packages.outputs.pypi_packages }}
1641 steps :
42+ # On a release event the default ref is the release's tag: the exact
43+ # commit the maintainer released.
1744 - uses : actions/checkout@v6
18- with :
19- fetch-depth : 0
20-
21- - name : Get last release hash
22- id : last-release
23- run : |
24- HASH=$(git rev-list --tags --max-count=1 || echo "HEAD~1")
25- echo "hash=${HASH}" >> $GITHUB_OUTPUT
26- echo "Using last release hash: ${HASH}"
27-
28- - name : Install uv
29- uses : astral-sh/setup-uv@v7
3045
31- - name : Create version name
32- id : create-version
46+ - name : Find all packages
47+ id : find-packages
48+ working-directory : src
3349 run : |
34- VERSION=$(uv run --script scripts/release.py generate-version)
35- echo "version $VERSION"
36- echo "version=$VERSION" >> $GITHUB_OUTPUT
50+ NPM=$(find . -name package.json -not -path "*/node_modules/*" -exec dirname {} \; | sed 's/^\.\///' | jq -R -s -c 'split("\n")[:-1]')
51+ PYPI=$(find . -name pyproject.toml -exec dirname {} \; | sed 's/^\.\///' | jq -R -s -c 'split("\n")[:-1]')
52+ echo "npm_packages=$NPM" >> "$GITHUB_OUTPUT"
53+ echo "pypi_packages=$PYPI" >> "$GITHUB_OUTPUT"
3754
38- - name : Create notes
39- run : |
40- HASH="${{ steps.last-release.outputs.hash }}"
41- uv run --script scripts/release.py generate-notes --directory src/ $HASH > RELEASE_NOTES.md
42- cat RELEASE_NOTES.md
43-
44- - name : Release notes
45- uses : actions/upload-artifact@v7
46- with :
47- name : release-notes
48- path : RELEASE_NOTES.md
49-
50- - name : Create python matrix
51- id : create-pypi-packages
52- run : |
53- HASH="${{ steps.last-release.outputs.hash }}"
54- PYPI=$(uv run --script scripts/release.py generate-matrix --pypi --directory src $HASH)
55- echo "pypi_packages $PYPI"
56- echo "pypi_packages=$PYPI" >> $GITHUB_OUTPUT
57-
58- - name : Create npm matrix
59- id : create-npm-packages
60- run : |
61- HASH="${{ steps.last-release.outputs.hash }}"
62- NPM=$(uv run --script scripts/release.py generate-matrix --npm --directory src $HASH)
63- echo "npm_packages $NPM"
64- echo "npm_packages=$NPM" >> $GITHUB_OUTPUT
65-
66- update-packages :
67- timeout-minutes : 10
68- needs : [create-metadata]
69- if : ${{ needs.create-metadata.outputs.npm_packages != '[]' || needs.create-metadata.outputs.pypi_packages != '[]' }}
70- runs-on : ubuntu-latest
55+ publish-npm :
56+ timeout-minutes : 15
57+ needs : [detect-packages]
58+ if : ${{ needs.detect-packages.outputs.npm_packages != '[]' }}
59+ strategy :
60+ fail-fast : false
61+ matrix :
62+ package : ${{ fromJson(needs.detect-packages.outputs.npm_packages) }}
63+ name : Publish ${{ matrix.package }} (npm)
7164 environment : release
7265 permissions :
73- contents : write
74- outputs :
75- changes_made : ${{ steps.commit.outputs.changes_made }}
66+ contents : read
67+ id-token : write # Required for npm trusted publishing (OIDC)
68+ runs-on : ubuntu-latest
7669 steps :
7770 - uses : actions/checkout@v6
71+
72+ - uses : actions/setup-node@v7
7873 with :
79- fetch-depth : 0
74+ node-version : 22
75+ cache : npm
76+ registry-url : " https://registry.npmjs.org"
8077
81- - name : Install uv
82- uses : astral-sh/setup-uv@v7
78+ # OIDC trusted publishing requires npm >=11.5.1; Node 22's bundled npm is 10.x.
79+ - name : Ensure npm CLI supports OIDC trusted publishing
80+ run : npm install -g npm@^11.5.1
8381
84- - name : Update packages
85- run : |
86- HASH="${{ needs.create-metadata.outputs.hash }}"
87- uv run --script scripts/release.py update-packages --directory src/ $HASH
82+ # The registry-diff guard: skip (not fail) a version that is already
83+ # published, and treat a never-published package as "publish it".
84+ - name : Check whether this version is already on npm
85+ id : guard
86+ run : node scripts/npm-publish-guard.mjs "src/${{ matrix.package }}"
8887
89- - name : Configure git
90- run : |
91- git config --global user.name "GitHub Actions"
92- git config --global user.email "actions@github.com"
88+ - name : Install dependencies
89+ if : steps.guard.outputs.skip != 'true'
90+ working-directory : src/${{ matrix.package }}
91+ run : npm ci
9392
94- - name : Commit changes
95- id : commit
96- run : |
97- VERSION="${{ needs.create-metadata.outputs.version }}"
98- git add -u
99- if git diff-index --quiet HEAD; then
100- echo "changes_made=false" >> $GITHUB_OUTPUT
101- else
102- git commit -m 'Automatic update of packages'
103- git tag -a "$VERSION" -m "Release $VERSION"
104- git push origin "$VERSION"
105- echo "changes_made=true" >> $GITHUB_OUTPUT
106- fi
93+ # Defense in depth: CI already validated the branch, but this tests the
94+ # exact ref being published, whatever path the tag took to get here.
95+ - name : Run tests
96+ if : steps.guard.outputs.skip != 'true'
97+ working-directory : src/${{ matrix.package }}
98+ run : npm test --if-present
99+
100+ - name : Build package
101+ if : steps.guard.outputs.skip != 'true'
102+ working-directory : src/${{ matrix.package }}
103+ run : npm run build
104+
105+ # Authenticates via OIDC trusted publishing (no token): each package's
106+ # npm trusted publisher is bound to this workflow + the release environment.
107+ - name : Publish package
108+ if : steps.guard.outputs.skip != 'true'
109+ working-directory : src/${{ matrix.package }}
110+ run : npm publish --access public
111+ env :
112+ NPM_CONFIG_PROVENANCE : " true"
107113
108114 publish-pypi :
109115 timeout-minutes : 15
110- needs : [update -packages, create-metadata ]
111- if : ${{ needs.create-metadata .outputs.pypi_packages != '[]' && needs.create-metadata.outputs.pypi_packages != ' ' }}
116+ needs : [detect -packages]
117+ if : ${{ needs.detect-packages .outputs.pypi_packages != '[]' }}
112118 strategy :
113119 fail-fast : false
114120 matrix :
115- package : ${{ fromJson(needs.create-metadata .outputs.pypi_packages) }}
116- name : Build ${{ matrix.package }}
121+ package : ${{ fromJson(needs.detect-packages .outputs.pypi_packages) }}
122+ name : Publish ${{ matrix.package }} (PyPI)
117123 environment : release
118124 permissions :
125+ contents : read
119126 id-token : write # Required for trusted publishing
120127 runs-on : ubuntu-latest
121128 steps :
122129 - uses : actions/checkout@v6
123- with :
124- ref : ${{ needs.create-metadata.outputs.version }}
125130
126131 - name : Install uv
127132 uses : astral-sh/setup-uv@v7
@@ -139,6 +144,8 @@ jobs:
139144 working-directory : src/${{ matrix.package }}
140145 run : uv run --frozen pyright
141146
147+ # Defense in depth: CI already validated the branch, but this tests the
148+ # exact ref being published, whatever path the tag took to get here.
142149 - name : Run tests
143150 working-directory : src/${{ matrix.package }}
144151 run : |
@@ -152,97 +159,10 @@ jobs:
152159 working-directory : src/${{ matrix.package }}
153160 run : uv build
154161
162+ # `skip-existing` is the PyPI side of the registry-diff guard: an
163+ # already-published version is skipped, not failed.
155164 - name : Publish package to PyPI
156165 uses : pypa/gh-action-pypi-publish@release/v1
157166 with :
158167 packages-dir : src/${{ matrix.package }}/dist
159- skip-existing : true # re-runs tolerate already-uploaded files
160-
161- publish-npm :
162- timeout-minutes : 15
163- needs : [update-packages, create-metadata]
164- if : ${{ needs.create-metadata.outputs.npm_packages != '[]' && needs.create-metadata.outputs.npm_packages != '' }}
165- strategy :
166- fail-fast : false
167- matrix :
168- package : ${{ fromJson(needs.create-metadata.outputs.npm_packages) }}
169- name : Build ${{ matrix.package }}
170- environment : release
171- permissions :
172- contents : read
173- id-token : write # Required for npm trusted publishing (OIDC)
174- runs-on : ubuntu-latest
175- steps :
176- - uses : actions/checkout@v6
177- with :
178- ref : ${{ needs.create-metadata.outputs.version }}
179-
180- - uses : actions/setup-node@v7
181- with :
182- node-version : 22
183- cache : npm
184- registry-url : ' https://registry.npmjs.org'
185-
186- # OIDC trusted publishing requires npm >=11.5.1; Node 22's bundled npm is 10.x.
187- - name : Ensure npm CLI supports OIDC trusted publishing
188- run : npm install -g npm@^11.5.1
189-
190- - name : Install dependencies
191- working-directory : src/${{ matrix.package }}
192- run : npm ci
193-
194- - name : Check if version exists on npm
195- working-directory : src/${{ matrix.package }}
196- run : |
197- VERSION=$(jq -r .version package.json)
198- if npm view --json | jq -e --arg version "$VERSION" '[.[]][0].versions | contains([$version])'; then
199- echo "Version $VERSION already exists on npm"
200- exit 1
201- fi
202- echo "Version $VERSION is new, proceeding with publish"
203-
204- - name : Run tests
205- working-directory : src/${{ matrix.package }}
206- run : npm test --if-present
207-
208- - name : Build package
209- working-directory : src/${{ matrix.package }}
210- run : npm run build
211-
212- # Authenticates via OIDC trusted publishing (no token) — each package's
213- # npm trusted publisher is bound to this workflow + the release environment
214- - name : Publish package
215- working-directory : src/${{ matrix.package }}
216- run : |
217- npm publish --access public
218- env :
219- NPM_CONFIG_PROVENANCE : " true"
220-
221- create-release :
222- timeout-minutes : 10
223- needs : [update-packages, create-metadata, publish-pypi, publish-npm]
224- if : |
225- always() &&
226- needs.update-packages.outputs.changes_made == 'true' &&
227- (needs.publish-pypi.result == 'success' || needs.publish-npm.result == 'success')
228- runs-on : ubuntu-latest
229- environment : release
230- permissions :
231- contents : write
232- steps :
233- - uses : actions/checkout@v6
234-
235- - name : Download release notes
236- uses : actions/download-artifact@v8
237- with :
238- name : release-notes
239-
240- - name : Create release
241- env :
242- GH_TOKEN : ${{ secrets.GITHUB_TOKEN}}
243- run : |
244- VERSION="${{ needs.create-metadata.outputs.version }}"
245- gh release create "$VERSION" \
246- --title "Release $VERSION" \
247- --notes-file RELEASE_NOTES.md
248-
168+ skip-existing : true
0 commit comments