Skip to content

Commit 38569bd

Browse files
authored
Merge pull request #5146 from modelcontextprotocol/v2/chore/5110-version-pr-ci
ci: dispatch TypeScript and Python CI on automated version PRs
2 parents e92e82f + 521ddb2 commit 38569bd

7 files changed

Lines changed: 305 additions & 6 deletions

File tree

‎.claude/skills/release/SKILL.md‎

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -177,8 +177,15 @@ Then, on the PR:
177177
1. **Tie it to the release issue with a comment**, `Part of #N`. The action
178178
rewrites the PR's body on every push to `v2/main`, so a `Closes` line there
179179
would not survive; this is the exception `AGENTS.md` names.
180-
2. **Close and reopen it to start CI.** A PR opened with the workflow token
181-
does not trigger workflows.
180+
2. **Wait for its CI to pass.** The workflow token's push starts no workflow,
181+
so the Version Packages workflow dispatches the TypeScript and Python
182+
workflows on `changeset-release/v2/main` after each update. A PR does not
183+
list dispatched checks, so the result shows as two commit statuses,
184+
`TypeScript (dispatched)` and `Python (dispatched)`. Closing and reopening
185+
the PR does not start them (that fires `pull_request`; they run on `push`).
186+
If neither status appears, run them by hand:
187+
`gh workflow run typescript.yml --ref changeset-release/v2/main` (and
188+
`python.yml`).
182189
3. **Read it**: each bump matches the semver policy in `RELEASING.md`, each
183190
`CHANGELOG.md` entry says what a user of the server needs to know, the
184191
consumed changeset files are deleted, and `package-lock.json` records the
@@ -195,8 +202,10 @@ gh workflow run prepare-python-release.yml --repo modelcontextprotocol/servers \
195202
```
196203

197204
It opens a PR that starts with `Closes #N`, on a branch named
198-
`v2/chore/<N>-python-calver-<date>`, labeled `v2`. Close and reopen it to start
199-
CI, check that each stamped package really changed, and a maintainer merges it.
205+
`v2/chore/<N>-python-calver-<date>`, labeled `v2`, and dispatches the
206+
TypeScript and Python workflows on that branch, as the Version Packages
207+
workflow does. Wait for its two `(dispatched)` statuses to pass, check that each stamped package really
208+
changed, and a maintainer merges it.
200209
No PR means no Python server has a shipped change since its last stamp.
201210

202211
⚠️ GitHub only dispatches a workflow that exists on the default branch. Until

‎.github/workflows/prepare-python-release.yml‎

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,12 @@
1313
# milestone's release issue (the `issue` input), its branch is named for that
1414
# issue, and it is labeled `v2`. The link is only a cross-reference on
1515
# `v2/main`; the release issue stays open until the Release is published.
16+
#
17+
# It pushes the branch with the workflow token, and a push made with that
18+
# token starts no workflow, so the PR would get no TypeScript or Python CI
19+
# (#5110); a close and reopen fires only `pull_request`, which those workflows
20+
# do not run on. So it dispatches both on the branch once the PR is open:
21+
# `workflow_dispatch` is the one event the workflow token can start.
1622

1723
name: Prepare Python Release
1824

@@ -32,6 +38,8 @@ jobs:
3238
permissions:
3339
contents: write
3440
pull-requests: write
41+
# To dispatch the TypeScript and Python workflows on the PR's branch.
42+
actions: write
3543
steps:
3644
# The ref this was dispatched on becomes the PR's base, and every PR
3745
# targets `v2/main`. A run from `main` would open a version PR straight
@@ -100,7 +108,7 @@ jobs:
100108
echo "Generated by the **Prepare Python Release** workflow. Nothing is published until a maintainer publishes a GitHub Release."
101109
echo
102110
echo "> [!NOTE]"
103-
echo "> A PR opened with the workflow token does not trigger CI. Close and reopen this PR to run it."
111+
echo "> A push made with the workflow token starts no CI, so the workflow dispatched the TypeScript and Python workflows on this branch. Their results show on this PR as the \`TypeScript (dispatched)\` and \`Python (dispatched)\` statuses. To run them again: \`gh workflow run python.yml --ref $BRANCH\` (and \`typescript.yml\`)."
104112
} > "$RUNNER_TEMP/pr-body.md"
105113
# A second run on the same day force-updates the branch, and may
106114
# stamp a different set of packages; the open PR's body is rewritten
@@ -117,3 +125,9 @@ jobs:
117125
--title "chore: stamp Python CalVer versions for $DATE" \
118126
--body-file "$RUNNER_TEMP/pr-body.md"
119127
fi
128+
# The push above starts no workflow (see the header), so CI is
129+
# dispatched on the branch explicitly, after a first run and a rerun
130+
# alike.
131+
for workflow in typescript.yml python.yml; do
132+
gh workflow run "$workflow" --ref "$BRANCH"
133+
done

‎.github/workflows/python.yml‎

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,14 @@ on:
55
# PR branch ran each workflow twice (once per event). PR checks still report
66
# from the push run of the head commit.
77
push:
8+
# A push made with the workflow token starts no workflow, so the version PRs
9+
# that automation opens (Version Packages, Prepare Python Release) get no
10+
# push run. Their workflows dispatch this one on the PR's branch instead
11+
# (#5110): `workflow_dispatch` is the one event that token can start, and its
12+
# run's checks attach to the branch's head commit. The rollup a PR reads
13+
# leaves dispatched checks out, so the `dispatch-status` jobs below report
14+
# the run as a commit status instead.
15+
workflow_dispatch:
816

917
# Superseded runs on the same ref are cancelled (e.g. rapid amend-pushes),
1018
# except on main, where every merge keeps its own CI run
@@ -174,3 +182,78 @@ jobs:
174182
with:
175183
name: dist-${{ matrix.package }}
176184
path: src/${{ matrix.package }}/dist/
185+
186+
# A dispatched run's checks attach to the branch's head commit but are left
187+
# out of its status rollup, which is what a pull request reads (verified on
188+
# #5110: 29 successful dispatched check runs, a rollup of null). So on a
189+
# dispatch, which is how a version PR opened by automation gets CI, these two
190+
# jobs mirror the run onto the commit as a status, which the rollup does
191+
# include: pending at the start, then the result of every job above. A push
192+
# run reports through its own checks and skips both.
193+
dispatch-status-pending:
194+
name: Report the dispatched run as pending
195+
if: github.event_name == 'workflow_dispatch'
196+
timeout-minutes: 5
197+
runs-on: ubuntu-latest
198+
permissions:
199+
statuses: write
200+
steps:
201+
- name: Set the commit status to pending
202+
env:
203+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
204+
run: |
205+
gh api "repos/$GITHUB_REPOSITORY/statuses/$GITHUB_SHA" \
206+
-f state=pending -f context="Python (dispatched)" \
207+
-f description="Dispatched run in progress" \
208+
-f target_url="$GITHUB_SERVER_URL/$GITHUB_REPOSITORY/actions/runs/$GITHUB_RUN_ID"
209+
210+
# `always()`, so a cancelled run cannot leave the status pending. A run that
211+
# was cancelled because a newer dispatch on the same commit superseded it
212+
# posts nothing, and the newer run reports instead; any other cancellation
213+
# is reported as an error. A job skipped by its own `if:` counts as passed.
214+
dispatch-status:
215+
name: Report the dispatched run's result
216+
if: github.event_name == 'workflow_dispatch' && always()
217+
needs:
218+
[
219+
dispatch-status-pending,
220+
detect-packages,
221+
script-tests,
222+
test,
223+
coverage,
224+
test-windows,
225+
build,
226+
]
227+
timeout-minutes: 5
228+
runs-on: ubuntu-latest
229+
permissions:
230+
statuses: write
231+
# To look for a newer dispatched run of this workflow on the commit.
232+
actions: read
233+
steps:
234+
- name: Set the commit status to the run's result
235+
env:
236+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
237+
GH_REPO: ${{ github.repository }}
238+
NEEDS: ${{ toJSON(needs) }}
239+
run: |
240+
if jq -e 'all(.[]; .result == "success" or .result == "skipped")' <<<"$NEEDS" >/dev/null; then
241+
STATE=success DESCRIPTION="Every job passed"
242+
elif jq -e 'any(.[]; .result == "failure")' <<<"$NEEDS" >/dev/null; then
243+
STATE=failure DESCRIPTION="A job failed; open the run for details"
244+
else
245+
NEWER=$(gh run list --workflow python.yml --event workflow_dispatch \
246+
--commit "$GITHUB_SHA" --json databaseId \
247+
--jq "[.[] | select(.databaseId > $GITHUB_RUN_ID)] | length") || NEWER=0
248+
# A failed lookup counts as no newer run: an error status is
249+
# better than one left pending.
250+
if [ "${NEWER:-0}" -gt 0 ]; then
251+
echo "Superseded by a newer dispatched run, which reports instead"
252+
exit 0
253+
fi
254+
STATE=error DESCRIPTION="The run was cancelled; dispatch it again"
255+
fi
256+
gh api "repos/$GITHUB_REPOSITORY/statuses/$GITHUB_SHA" \
257+
-f state="$STATE" -f context="Python (dispatched)" \
258+
-f description="$DESCRIPTION" \
259+
-f target_url="$GITHUB_SERVER_URL/$GITHUB_REPOSITORY/actions/runs/$GITHUB_RUN_ID"

‎.github/workflows/typescript.yml‎

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,14 @@ on:
55
# PR branch ran each workflow twice (once per event). PR checks still report
66
# from the push run of the head commit.
77
push:
8+
# A push made with the workflow token starts no workflow, so the version PRs
9+
# that automation opens (Version Packages, Prepare Python Release) get no
10+
# push run. Their workflows dispatch this one on the PR's branch instead
11+
# (#5110): `workflow_dispatch` is the one event that token can start, and its
12+
# run's checks attach to the branch's head commit. The rollup a PR reads
13+
# leaves dispatched checks out, so the `dispatch-status` jobs below report
14+
# the run as a commit status instead.
15+
workflow_dispatch:
816

917
# Superseded runs on the same ref are cancelled (e.g. rapid amend-pushes),
1018
# except on main, where every merge keeps its own CI run
@@ -207,3 +215,78 @@ jobs:
207215
208216
- name: Boot every server
209217
run: npm run smoke
218+
219+
# A dispatched run's checks attach to the branch's head commit but are left
220+
# out of its status rollup, which is what a pull request reads (verified on
221+
# #5110: 29 successful dispatched check runs, a rollup of null). So on a
222+
# dispatch, which is how a version PR opened by automation gets CI, these two
223+
# jobs mirror the run onto the commit as a status, which the rollup does
224+
# include: pending at the start, then the result of every job above. A push
225+
# run reports through its own checks and skips both.
226+
dispatch-status-pending:
227+
name: Report the dispatched run as pending
228+
if: github.event_name == 'workflow_dispatch'
229+
timeout-minutes: 5
230+
runs-on: ubuntu-latest
231+
permissions:
232+
statuses: write
233+
steps:
234+
- name: Set the commit status to pending
235+
env:
236+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
237+
run: |
238+
gh api "repos/$GITHUB_REPOSITORY/statuses/$GITHUB_SHA" \
239+
-f state=pending -f context="TypeScript (dispatched)" \
240+
-f description="Dispatched run in progress" \
241+
-f target_url="$GITHUB_SERVER_URL/$GITHUB_REPOSITORY/actions/runs/$GITHUB_RUN_ID"
242+
243+
# `always()`, so a cancelled run cannot leave the status pending. A run that
244+
# was cancelled because a newer dispatch on the same commit superseded it
245+
# posts nothing, and the newer run reports instead; any other cancellation
246+
# is reported as an error. A job skipped by its own `if:` counts as passed.
247+
dispatch-status:
248+
name: Report the dispatched run's result
249+
if: github.event_name == 'workflow_dispatch' && always()
250+
needs:
251+
[
252+
dispatch-status-pending,
253+
root-guards,
254+
detect-packages,
255+
validate,
256+
coverage,
257+
test-windows,
258+
smoke,
259+
]
260+
timeout-minutes: 5
261+
runs-on: ubuntu-latest
262+
permissions:
263+
statuses: write
264+
# To look for a newer dispatched run of this workflow on the commit.
265+
actions: read
266+
steps:
267+
- name: Set the commit status to the run's result
268+
env:
269+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
270+
GH_REPO: ${{ github.repository }}
271+
NEEDS: ${{ toJSON(needs) }}
272+
run: |
273+
if jq -e 'all(.[]; .result == "success" or .result == "skipped")' <<<"$NEEDS" >/dev/null; then
274+
STATE=success DESCRIPTION="Every job passed"
275+
elif jq -e 'any(.[]; .result == "failure")' <<<"$NEEDS" >/dev/null; then
276+
STATE=failure DESCRIPTION="A job failed; open the run for details"
277+
else
278+
NEWER=$(gh run list --workflow typescript.yml --event workflow_dispatch \
279+
--commit "$GITHUB_SHA" --json databaseId \
280+
--jq "[.[] | select(.databaseId > $GITHUB_RUN_ID)] | length") || NEWER=0
281+
# A failed lookup counts as no newer run: an error status is
282+
# better than one left pending.
283+
if [ "${NEWER:-0}" -gt 0 ]; then
284+
echo "Superseded by a newer dispatched run, which reports instead"
285+
exit 0
286+
fi
287+
STATE=error DESCRIPTION="The run was cancelled; dispatch it again"
288+
fi
289+
gh api "repos/$GITHUB_REPOSITORY/statuses/$GITHUB_SHA" \
290+
-f state="$STATE" -f context="TypeScript (dispatched)" \
291+
-f description="$DESCRIPTION" \
292+
-f target_url="$GITHUB_SERVER_URL/$GITHUB_REPOSITORY/actions/runs/$GITHUB_RUN_ID"

‎.github/workflows/version-packages.yml‎

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,13 @@
1414
# it as an exception and says how it is tied to its release issue instead. The
1515
# `v2` label does survive an update, and this workflow applies it.
1616
#
17+
# The action pushes the PR's branch with the workflow token, and a push made
18+
# with that token starts no workflow, so the PR would get no TypeScript or
19+
# Python CI (#5110). Closing and reopening it does not help either: that fires
20+
# `pull_request`, and those workflows run on `push`. So after each update this
21+
# workflow dispatches both on the PR's branch; `workflow_dispatch` is the one
22+
# event the workflow token can start.
23+
#
1724
# This workflow only ever opens a PR. It gives the action no publish script, so
1825
# it never publishes, tags or creates a Release; that is `release.yml`, on a
1926
# maintainer-published GitHub Release.
@@ -34,6 +41,8 @@ jobs:
3441
permissions:
3542
contents: write
3643
pull-requests: write
44+
# To dispatch the TypeScript and Python workflows on the PR's branch.
45+
actions: write
3746
steps:
3847
- uses: actions/checkout@v6
3948

@@ -68,3 +77,18 @@ jobs:
6877
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
6978
PR: ${{ steps.changesets.outputs.pr-number }}
7079
run: gh pr edit "$PR" --add-label v2
80+
81+
# The action pushed the branch with the workflow token, which starts no
82+
# workflow, so CI is dispatched on it explicitly (see the header). A
83+
# dispatch on every update matches a push run on every push: the CI
84+
# workflows' concurrency groups cancel the superseded run.
85+
- name: Run CI on the Version Packages PR
86+
if: steps.changesets.outputs.pr-number != ''
87+
env:
88+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
89+
PR: ${{ steps.changesets.outputs.pr-number }}
90+
run: |
91+
BRANCH=$(gh pr view "$PR" --json headRefName --jq .headRefName)
92+
for workflow in typescript.yml python.yml; do
93+
gh workflow run "$workflow" --ref "$BRANCH"
94+
done

‎RELEASING.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ node scripts/prepare-python-release.mjs # prints one "name: old -> new" line
3939
### PRs opened by these workflows
4040

4141
> [!NOTE]
42-
> Both workflows open their PR with the workflow token, and GitHub does not start CI for a PR opened that way. Close and reopen the PR to run CI before merging. The Version Packages PR's body is rewritten on every push to `v2/main`, so it is tied to the release issue by a comment (`Part of #N`) instead of a body line. The repository setting **Settings → Actions → General → Allow GitHub Actions to create and approve pull requests** must be on, or the workflows fail at the step that opens the PR.
42+
> Both workflows push their PR's branch with the workflow token, and a push made with that token starts no workflow, so each one then dispatches the TypeScript and Python workflows on that branch (`workflow_dispatch` is the one event the token can start). A PR does not list dispatched checks, so each dispatched run also reports itself on the PR's head commit as a status, `TypeScript (dispatched)` and `Python (dispatched)`; wait for both to pass before merging. Closing and reopening the PR does not start them: that fires `pull_request`, and those workflows run on `push`. To run them again by hand: `gh workflow run typescript.yml --ref <branch>` (and `python.yml`). The Version Packages PR's body is rewritten on every push to `v2/main`, so it is tied to the release issue by a comment (`Part of #N`) instead of a body line. The repository setting **Settings → Actions → General → Allow GitHub Actions to create and approve pull requests** must be on, or the workflows fail at the step that opens the PR.
4343
4444
## How publishing works
4545

0 commit comments

Comments
 (0)