Skip to content

Commit 77ae0ae

Browse files
authored
Merge pull request #97 from wp-cli/update-bundle-skill
Add an update-bundle skill for releasing the bundle end to end
2 parents 735b320 + 03a89e0 commit 77ae0ae

19 files changed

Lines changed: 1812 additions & 19 deletions
Lines changed: 317 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,317 @@
1+
---
2+
name: update-bundle
3+
description: Release every bundled WP-CLI package that has unreleased changes, then refresh the wp-cli/wp-cli-bundle lockfile and the automated tests until they are green. Use when asked to "update the bundle", cut package releases across the bundle, or refresh the bundle's lock files. Asks the maintainer every milestone question in one go, then gets a single approval before tagging anything.
4+
---
5+
6+
# Update the bundle
7+
8+
Takes the bundle from "packages have unreleased changes" to "every package is
9+
tagged, the bundle lockfile ships those tags, and the automated tests are
10+
green". Stops and hands over to the maintainer when something bigger than a
11+
routine fix turns up.
12+
13+
Run everything from the root of this `wp-cli-dev` checkout, where any `wp`
14+
executable picks up the `wp maintenance` commands through `wp-cli.yml`. Set
15+
`NO_COLOR=1` for every command whose output you read back.
16+
17+
The run has four phases. **Nothing is written to GitHub before the
18+
maintainer's answers in phase 2. Nothing is tagged before their approval in
19+
phase 3.**
20+
21+
1. Survey (read-only)
22+
2. Milestone questions, then milestone changes
23+
3. Release proposal, approval, then tagging
24+
4. Lockfiles and tests: framework, bundle, automated tests
25+
26+
Keep a running log in a scratch file, such as `update-bundle-state.md` in the
27+
session's scratch or temp folder (not in this repository). Record the answers,
28+
the tags created, and the PRs and workflow runs you are watching. Re-read it
29+
after a context compaction instead of re-asking the maintainer. `$SCRATCH`
30+
below stands for that folder.
31+
32+
## Phase 1: Survey
33+
34+
```bash
35+
wp maintenance doctor
36+
wp maintenance release plan --bundle --format=json > "$SCRATCH/plan.json"
37+
```
38+
39+
Stop if `doctor` reports a failed check. Stop as well if it reports `gh`,
40+
`jq` or `composer` as missing: `doctor` only warns about them, but this skill
41+
needs all three, and finding out in phase 4 would leave tags without lockfile
42+
updates. The plan takes a few hundred API requests, so the rate limit `doctor`
43+
shows should leave room for that.
44+
45+
`--bundle` covers every package in the composer.lock of wp-cli/wp-cli-bundle:
46+
the `*-command` packages, plus wp-cli-tests, php-cli-tools, spyc and
47+
wp-config-transformer. The wp-cli/wp-cli framework is not tagged here. The
48+
bundle tracks its `main` branch, see phase 4.
49+
50+
For each repository, the JSON holds:
51+
52+
| Field | Meaning |
53+
| --- | --- |
54+
| `status` | `up_to_date`, `ready` (`release.tag` can be generated as is) or `needs_human` |
55+
| `latest_tag` | The tag the default branch is compared against |
56+
| `pull_requests` | Merged since `latest_tag` that call for a release. Leaves out Dependabot and GitHub Actions PRs unless they are on a milestone, and PRs that only touch `.github/`, `README.md`, `AGENTS.md`, `.actrc` or `.editorconfig`. |
57+
| `blockers` | What `needs_human` is about, by `code`, see below |
58+
| `open_items` | Issues/PRs still open on the milestone the unreleased changes are on |
59+
| `open_pull_requests` | Open, non-draft, non-bot PRs that have no open milestone |
60+
| `direct_commits` | Commits pushed without a PR that change more than those development files. `null` when there are too many commits since `latest_tag` for GitHub to compare; check those by hand |
61+
| `open_milestones` | Open milestones that are a version newer than `latest_tag`, lowest first |
62+
63+
## Phase 2: Milestone questions
64+
65+
Work out every question first, across all repositories. Then ask them all,
66+
grouped into as few `AskUserQuestion` calls as possible: up to 4 questions
67+
per call and up to 4 options per question, with "Other" always added
68+
automatically. Put the repository and PR numbers in every question, since the
69+
maintainer may see only the dialog. Only start the next call once the previous
70+
one has its answers, and make no change until every question is answered.
71+
72+
Name the milestones like this:
73+
74+
- **R**, the release milestone of a repository: `release.milestone` when
75+
`ready`. Otherwise the milestone the unreleased `pull_requests` are on.
76+
Otherwise the lowest of `open_milestones`. Otherwise a new milestone, one
77+
patch version above `latest_tag`.
78+
- **N**, the next milestone after R: the lowest of `open_milestones` above R.
79+
Otherwise a new milestone, one patch version above R.
80+
81+
Choosing a version is the maintainer's call. Propose the patch bump, and offer
82+
a minor bump as a second option when a merged PR adds a command, a subcommand
83+
or a flag.
84+
85+
Questions by blocker or field:
86+
87+
- **`no_milestone`** (merged PRs without one): "Ship #A, #B of `<repo>` in R?"
88+
The options are *Put on R* or *Skip this repo's release*. They are merged
89+
already, so a tag ships them either way, and leaving them off R only drops
90+
them from the release notes.
91+
- **`released_milestone`** (merged PRs on a milestone that is closed or tagged
92+
already): the same question. Answering *Put on R* moves them.
93+
- **`open_items`**: "`<repo>` R still has #X (open PR, by …) open. Wait for it
94+
or defer it?" The options are *Defer to N and release R now* or *Wait, so
95+
no release of `<repo>`*. Mention drafts and issues as such.
96+
- **`several_milestones`**: "The unreleased changes of `<repo>` are on X and
97+
Y. Which one should the release be?" The options are each milestone, plus
98+
*Skip*. All the PRs end up on the chosen one.
99+
- **`open_pull_requests`**: one multi-select question per repository, with up
100+
to 4 PRs per question (split longer lists): "Which open PRs of `<repo>`
101+
should go on M?" M is N when R is released in this run, and R otherwise.
102+
Leaving a PR unchecked leaves it alone. Open PRs never block a release.
103+
- **`direct_commits`**: "`<repo>` has commits pushed without a PR, which R
104+
would ship without mentioning them: `<sha> <message>`. Release anyway?" A
105+
*no* excludes the repository from phase 3, even though its plan stays
106+
`ready`. Record the exclusion in the log. If a repository has direct commits
107+
but no merged PR, `release generate` can't release it. Report it for the
108+
maintainer to handle by hand.
109+
- **`invalid_version`, `no_version_tag`**: no question. List them in the final
110+
report as needing manual attention.
111+
112+
Then apply the answers. One call puts any number of items on a milestone, and
113+
creates it if needed:
114+
115+
```bash
116+
wp maintenance milestone assign <repo> <milestone> <number>... --create
117+
```
118+
119+
Then re-run `wp maintenance release plan <repo>... --format=json` for the
120+
repositories you changed. A repository the maintainer wanted released that is
121+
still not `ready` points to a misread answer or a new blocker. Ask about it
122+
instead of working around it.
123+
124+
## Phase 3: Release proposal and approval
125+
126+
Every repository that is now `ready` and that the maintainer did not exclude
127+
in phase 2 gets a proposal. Save its plan JSON in the log as the approved
128+
snapshot. Gather all of them
129+
before asking. For each one, preview the notes:
130+
131+
```bash
132+
wp maintenance release-notes <repo> <milestone> --source=pull-request
133+
```
134+
135+
Then show a single overview as a table, with these columns: repository,
136+
`latest_tag` → new tag, number of PRs, a one-line summary of the notes, and
137+
anything notable such as direct commits or deferred items. Below it, list what
138+
phase 4 will do. Then ask for approval in one `AskUserQuestion` call, which
139+
also settles how to merge in phase 4:
140+
141+
1. "Tag and release these N packages?" *Release all* / *Release all except…
142+
(say which in Other)* / *Cancel*.
143+
2. "The bundle requires a review before merging. How should the lockfile PRs
144+
be merged once green?" *Approve the bot's PR and merge; admin-merge my own*
145+
/ *Approve the bot's PR and merge; ask a reviewer for mine* / *Leave all
146+
merges to me*.
147+
148+
Then release each approved package. Right before each one, re-run
149+
`wp maintenance release plan <repo> --format=json` and compare it with the
150+
approved snapshot: the same `latest_tag`, `release`, `pull_requests` and
151+
`direct_commits`. If anything was merged or pushed since, don't tag it. Ask
152+
again about that repository once the others are released.
153+
154+
```bash
155+
wp maintenance release generate <repo> --milestone=<milestone> --yes
156+
```
157+
158+
The command re-checks the plan and skips the release, with a warning, if
159+
anything changed in the meantime. Report every skip. Do not force it. Check
160+
each release afterwards with `gh release view v<milestone> --repo <repo>`.
161+
162+
Before phase 4, wait until Packagist lists every new version, or Composer
163+
won't find them. It usually takes a minute or two:
164+
165+
```bash
166+
curl -fsS "https://repo.packagist.org/p2/wp-cli/<package>.json" | jq -r '.packages[][].version' | head -3
167+
```
168+
169+
The package name can differ from the repository: wp-cli/spyc is
170+
`wp-cli/mustangostang-spyc`. If a version is missing after about 15 minutes,
171+
report it to the maintainer.
172+
173+
## Phase 4: Lockfiles and tests
174+
175+
Do the steps in this order. Each one updates `composer.lock` of the bundle,
176+
and running them at the same time makes the PRs conflict.
177+
178+
### 4a. Framework: the "Update wp-cli framework" workflow of the bundle
179+
180+
The wp-cli/wp-cli repository has no lockfile of its own. Its "lock refresh" is
181+
the `update-framework.yml` workflow of wp-cli/wp-cli-bundle. It runs
182+
`composer update wp-cli/wp-cli --with-all-dependencies`, which also brings in
183+
new releases of php-cli-tools and spyc, and opens or updates the
184+
`update-framework` PR. It runs daily and on every push to the bundle's `main`.
185+
186+
First note the commit the lockfile should end up with:
187+
188+
```bash
189+
gh api repos/wp-cli/wp-cli/commits/main --jq .sha
190+
```
191+
192+
Then pick a run that started after the last tag from phase 3, active or
193+
finished. If there is none, trigger one:
194+
195+
```bash
196+
gh run list --repo wp-cli/wp-cli-bundle --workflow update-framework.yml --limit 5 \
197+
--json databaseId,event,status,conclusion,createdAt
198+
gh workflow run update-framework.yml --repo wp-cli/wp-cli-bundle --ref main
199+
```
200+
201+
Either way, wait for that run to finish, and look at nothing else until it
202+
does. A run still in progress may be rewriting the PR. If it fails, read its
203+
log and bring the maintainer in.
204+
205+
Once it has succeeded, find the PR with `gh pr list --repo
206+
wp-cli/wp-cli-bundle --head update-framework --state open`. Check that its
207+
lockfile pins `wp-cli/wp-cli` at the commit you noted, or main's lockfile
208+
does when there is no PR:
209+
210+
```bash
211+
gh api "repos/wp-cli/wp-cli-bundle/contents/composer.lock?ref=<update-framework|main>" \
212+
--jq '.content | @base64d | fromjson | .packages[] | select(.name == "wp-cli/wp-cli") | .source.reference'
213+
```
214+
215+
A run's start time does not prove it saw a commit, since a commit can reach
216+
`main` after the run started even when it is dated earlier. So if the pinned
217+
commit differs, trigger one more run and repeat. No PR, with the commit you
218+
noted on main, means the lockfile was up to date already. Otherwise babysit
219+
the PR, see below.
220+
221+
### 4b. Bundle: bundled packages in the bundle's composer.lock
222+
223+
Start this only after the framework PR is merged or turned out to be
224+
unnecessary. Nothing in the bundle updates the bundled packages as a whole on
225+
its own. Dependabot opens one PR per package, and they close themselves once
226+
the lockfile has caught up. Preview, then open the PR:
227+
228+
```bash
229+
.maintenance/refresh-bundle-lock.sh --dry-run
230+
.maintenance/refresh-bundle-lock.sh
231+
```
232+
233+
The script moves only the `wp-cli/*` packages, never the framework or
234+
third-party dependencies, and only touches `composer.lock`. If its
235+
`update-bundled-packages` PR is open already, the script updates that PR and
236+
prints its URL. No output on stdout means the lockfile is up to date already.
237+
Each package should end up on the tag created in phase 3. If one doesn't,
238+
find out why before merging, usually a constraint in the bundle's
239+
`composer.json`.
240+
241+
If Composer cannot resolve the update, for example because a new release
242+
needs a newer third-party dependency, that is a bigger issue. Stop and report
243+
it.
244+
245+
### 4c. Automated tests: wp-cli/automated-tests
246+
247+
Check `config.lock` in its `composer.json` first.
248+
249+
- **`false`, as is the case today**: there is no lockfile. Every run resolves
250+
the bundle's `dev-main` afresh, so refreshing means running the suite once
251+
the bundle PR is merged:
252+
253+
```bash
254+
gh workflow run testing.yml --repo wp-cli/automated-tests --ref main
255+
```
256+
257+
Then babysit that run the way a PR is babysat. It fans out to about 150 jobs
258+
and takes a while.
259+
- **A committed `composer.lock`**: update it on a branch with
260+
`composer update 'wp-cli/*' --no-install`, open a PR, and babysit it.
261+
262+
## Babysitting a PR or run
263+
264+
**Waiting.** Use the harness's own facility to watch PRs or wait on background
265+
work if it has one. Otherwise run `gh pr checks <n> --repo <repo> --watch`, or
266+
`gh run watch <run-id> --repo <repo> --exit-status`, in the background. Don't
267+
poll in a tight loop.
268+
269+
**Triaging each failing check.** Read the job log first, with `gh run view
270+
<run-id> --repo <repo> --log-failed`, and classify the failure:
271+
272+
- **Pre-existing**: the same check fails on the latest run of the default
273+
branch too, so the PR didn't cause it. Example: "Audit locked dependencies"
274+
flagging an advisory in a third-party package. To tell, compare
275+
`wp maintenance dependencies audit --ref=<pr-branch>` with a run of the
276+
same command against the default branch. It also shows whether the affected
277+
packages ship in the Phar or are only needed for development. Ask the
278+
maintainer whether to merge anyway. Don't fix it as part of this run.
279+
- **Flaky**: a network timeout, a failed download from WordPress.org or
280+
GitHub, MySQL not starting, a rate limit, or a runner lost mid-job. Re-run
281+
the failed jobs once with `gh run rerun <run-id> --repo <repo> --failed`. A
282+
second identical failure is real.
283+
- **Minor, fix it**: the PR is out of date or conflicts with `main`, which
284+
re-running the workflow or the script fixes. Also small fixes confined to
285+
the PR's own files. Push the fix to the PR branch.
286+
- **Bigger, rope the human in**: a Behat or PHPUnit failure in a package's
287+
behaviour, which may be a regression in a new release, a Composer
288+
resolution failure, an audit failure that would need a third-party update
289+
past the Dependabot cooldown, or anything that needs a code change in
290+
another repository or another release.
291+
292+
Stop the run there. Report the PR or run link, the failing jobs, a short
293+
log excerpt, the package and PR most likely responsible, and the fixes you
294+
see. Phases that don't depend on the blocked one may go on, but 4a → 4b →
295+
4c depend on each other.
296+
297+
**Merging.** Only with every required check green, or with the maintainer's
298+
explicit go-ahead on a pre-existing failure. Follow the merge choice from
299+
phase 3:
300+
301+
```bash
302+
gh pr review <n> --repo <repo> --approve # bot-authored PRs only
303+
gh pr merge <n> --repo <repo> --squash # add --admin only for the maintainer's own PRs, if allowed
304+
```
305+
306+
Never approve a PR the authenticated account wrote itself. If merging is left
307+
to the maintainer, or a reviewer is needed, say so in the report and wait.
308+
309+
## Final report
310+
311+
End with:
312+
313+
- the releases, with tags and links, and every repository skipped, with the
314+
reason,
315+
- the milestone changes made,
316+
- the PRs merged and the automated-tests run, with links and conclusions,
317+
- anything waiting on the maintainer, and what exactly is needed.

‎.gitignore‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,15 @@
11
# Exclude all subfolders...
22
/*/
33
# except for the following.
4+
!/.claude/
45
!/.github/
56
!/.maintenance/
67
!/.readme-partials/
78
!/tests/
89

10+
# Only the skills of .claude/ are shared.
11+
/.claude/*
12+
!/.claude/skills/
13+
914
composer.lock
1015
*.log

‎.maintenance/bootstrap.php‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
WP_CLI::add_command( 'maintenance contrib-list', 'WP_CLI\Maintenance\Contrib_List_Command' );
1010
WP_CLI::add_command( 'maintenance dependencies', 'WP_CLI\Maintenance\Dependencies_Command' );
1111
WP_CLI::add_command( 'maintenance doctor', 'WP_CLI\Maintenance\Doctor_Command' );
12+
WP_CLI::add_command( 'maintenance milestone', 'WP_CLI\Maintenance\Milestone_Command' );
1213
WP_CLI::add_command( 'maintenance milestones-after', 'WP_CLI\Maintenance\Milestones_After_Command' );
1314
WP_CLI::add_command( 'maintenance milestones-since', 'WP_CLI\Maintenance\Milestones_Since_Command' );
1415
WP_CLI::add_command( 'maintenance release', 'WP_CLI\Maintenance\Release_Command' );

0 commit comments

Comments
 (0)