Skip to content

Commit 03a89e0

Browse files
schlesseraclaude
andcommitted
Address review feedback on the update-bundle skill
- Report unknown direct commits as null instead of an empty list when a comparison is too long to check. - Classify renamed files by their previous name as well, so moving code into .github/ still counts as a change. - Check every number passed to `milestone assign` before any write, and reject zero and out-of-range values. - In the skill: require gh, jq and composer up front, drop repositories whose direct commits the maintainer declined, re-check each plan against the approved snapshot before tagging, wait for an active framework run, and verify the framework commit pinned in the lockfile rather than trusting run and commit dates. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
1 parent 98133e2 commit 03a89e0

8 files changed

Lines changed: 135 additions & 42 deletions

File tree

‎.claude/skills/update-bundle/SKILL.md‎

Lines changed: 43 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,11 @@ wp maintenance doctor
3636
wp maintenance release plan --bundle --format=json > "$SCRATCH/plan.json"
3737
```
3838

39-
Stop if `doctor` reports a failed check. The plan takes a few hundred API
40-
requests, so the rate limit `doctor` shows should leave room for that.
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.
4144

4245
`--bundle` covers every package in the composer.lock of wp-cli/wp-cli-bundle:
4346
the `*-command` packages, plus wp-cli-tests, php-cli-tools, spyc and
@@ -54,7 +57,7 @@ For each repository, the JSON holds:
5457
| `blockers` | What `needs_human` is about, by `code`, see below |
5558
| `open_items` | Issues/PRs still open on the milestone the unreleased changes are on |
5659
| `open_pull_requests` | Open, non-draft, non-bot PRs that have no open milestone |
57-
| `direct_commits` | Commits pushed without a PR that change more than those development files |
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 |
5861
| `open_milestones` | Open milestones that are a version newer than `latest_tag`, lowest first |
5962

6063
## Phase 2: Milestone questions
@@ -98,9 +101,11 @@ Questions by blocker or field:
98101
should go on M?" M is N when R is released in this run, and R otherwise.
99102
Leaving a PR unchecked leaves it alone. Open PRs never block a release.
100103
- **`direct_commits`**: "`<repo>` has commits pushed without a PR, which R
101-
would ship without mentioning them: `<sha> <message>`. Release anyway?" If a
102-
repository has direct commits but no merged PR, `release generate` can't
103-
release it. Report it for the maintainer to handle by hand.
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.
104109
- **`invalid_version`, `no_version_tag`**: no question. List them in the final
105110
report as needing manual attention.
106111

@@ -118,7 +123,9 @@ instead of working around it.
118123

119124
## Phase 3: Release proposal and approval
120125

121-
Every repository that is now `ready` gets a proposal. Gather all of them
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
122129
before asking. For each one, preview the notes:
123130

124131
```bash
@@ -138,7 +145,11 @@ also settles how to merge in phase 4:
138145
/ *Approve the bot's PR and merge; ask a reviewer for mine* / *Leave all
139146
merges to me*.
140147

141-
Then release each approved package:
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.
142153

143154
```bash
144155
wp maintenance release generate <repo> --milestone=<milestone> --yes
@@ -172,24 +183,40 @@ the `update-framework.yml` workflow of wp-cli/wp-cli-bundle. It runs
172183
new releases of php-cli-tools and spyc, and opens or updates the
173184
`update-framework` PR. It runs daily and on every push to the bundle's `main`.
174185

175-
It counts as triggered already when one of its runs started after both the
176-
latest commit on wp-cli/wp-cli `main` and the last tag from phase 3:
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:
177194

178195
```bash
179196
gh run list --repo wp-cli/wp-cli-bundle --workflow update-framework.yml --limit 5 \
180197
--json databaseId,event,status,conclusion,createdAt
181-
gh api repos/wp-cli/wp-cli/commits/main --jq '.commit.committer.date'
198+
gh workflow run update-framework.yml --repo wp-cli/wp-cli-bundle --ref main
182199
```
183200

184-
Otherwise trigger it, and wait for the run you started:
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:
185209

186210
```bash
187-
gh workflow run update-framework.yml --repo wp-cli/wp-cli-bundle --ref main
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'
188213
```
189214

190-
Then find the PR with `gh pr list --repo wp-cli/wp-cli-bundle --head
191-
update-framework --state open`. No PR after a successful run means the
192-
lockfile was up to date already. Otherwise babysit it, see below.
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.
193220

194221
### 4b. Bundle: bundled packages in the bundle's composer.lock
195222

‎.maintenance/src/GitHub.php‎

Lines changed: 27 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -452,12 +452,12 @@ public static function get_comparison( $project, $base, $head ) {
452452
* @param object $comparison Comparison of the tag and the branch.
453453
* @param object[] $pull_requests Pull requests merged since the tag.
454454
*
455-
* @return object[] Commits with their `files`, oldest first. Empty when the
456-
* comparison is too long to tell.
455+
* @return object[]|null Commits with their `files`, oldest first. Null when
456+
* the comparison is too long to tell.
457457
*/
458458
public static function get_direct_commits( $project, $comparison, array $pull_requests ) {
459459
if ( count( $comparison->commits ) < $comparison->total_commits ) {
460-
return [];
460+
return null;
461461
}
462462

463463
$merged = [];
@@ -503,20 +503,37 @@ public static function get_open_pull_requests( $project, $branch ) {
503503
}
504504

505505
/**
506-
* Gets the names of the files a pull request changes.
506+
* Gets the names of the files a pull request changes, including the
507+
* previous names of renamed files.
507508
*
508509
* @param string $project
509510
* @param int $number
510511
*
511512
* @return string[]
512513
*/
513514
public static function get_pull_request_files( $project, $number ) {
514-
return array_map(
515-
static function ( $file ) {
516-
return $file->filename;
517-
},
518-
self::request_all( self::API_ROOT . "repos/{$project}/pulls/{$number}/files" )
519-
);
515+
return self::file_names( self::request_all( self::API_ROOT . "repos/{$project}/pulls/{$number}/files" ) );
516+
}
517+
518+
/**
519+
* Gets the names of changed files, including the previous names of
520+
* renamed files.
521+
*
522+
* @param object[] $files Files of a pull request or commit, with
523+
* `filename` and maybe `previous_filename`.
524+
*
525+
* @return string[]
526+
*/
527+
public static function file_names( array $files ) {
528+
$names = [];
529+
foreach ( $files as $file ) {
530+
$names[] = $file->filename;
531+
if ( isset( $file->previous_filename ) ) {
532+
$names[] = $file->previous_filename;
533+
}
534+
}
535+
536+
return $names;
520537
}
521538

522539
/**

‎.maintenance/src/Milestone_Command.php‎

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -40,13 +40,15 @@ final class Milestone_Command {
4040
public function assign( $args, $assoc_args ) {
4141
$repo = GitHub::qualify_repo( array_shift( $args ) );
4242
$title = (string) array_shift( $args );
43-
$numbers = array_map( 'trim', $args );
4443
$create = Utils\get_flag_value( $assoc_args, 'create', false );
44+
$numbers = [];
4545

46-
foreach ( $numbers as $number ) {
47-
if ( ! ctype_digit( ltrim( $number, '#' ) ) ) {
48-
WP_CLI::error( "'{$number}' is not the number of an issue or pull request." );
46+
foreach ( $args as $arg ) {
47+
$number = filter_var( ltrim( trim( $arg ), '#' ), FILTER_VALIDATE_INT, [ 'options' => [ 'min_range' => 1 ] ] );
48+
if ( false === $number ) {
49+
WP_CLI::error( "'{$arg}' is not the number of an issue or pull request." );
4950
}
51+
$numbers[] = $number;
5052
}
5153

5254
$milestone = self::find( GitHub::get_project_milestones( $repo, [ 'state' => 'all' ] ), $title );
@@ -63,7 +65,6 @@ public function assign( $args, $assoc_args ) {
6365
}
6466

6567
foreach ( $numbers as $number ) {
66-
$number = (int) ltrim( $number, '#' );
6768
GitHub::set_milestone( $repo, $number, $milestone->number );
6869
WP_CLI::log( "Added #{$number} to milestone '{$title}'." );
6970
}

‎.maintenance/src/Release_Command.php‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -306,8 +306,9 @@ static function ( $milestone ) use ( $only_milestone ) {
306306
* release without it blocking one: `open_pull_requests` without an open
307307
* milestone, the `open_items` still on the milestone of the unreleased
308308
* changes, `direct_commits` that no pull request brought in and that
309-
* change more than those development files, and the `open_milestones`
310-
* that could still be released.
309+
* change more than those development files (null when there are more
310+
* commits since the latest tag than GitHub compares), and the
311+
* `open_milestones` that could still be released.
311312
*
312313
* Makes no changes.
313314
*

‎.maintenance/src/Release_Plan.php‎

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -120,18 +120,20 @@ static function ( $tag ) {
120120
* `number`, `title`, `user` and `milestone`,
121121
* and the names of the `files` they change
122122
* when known.
123-
* @param object[] $direct_commits Commits on the default branch since the
124-
* latest version tag that no pull request
125-
* brought in, with `sha`, `commit`,
126-
* `author` and `files`.
123+
* @param object[]|null $direct_commits Commits on the default branch
124+
* since the latest version tag that no
125+
* pull request brought in, with `sha`,
126+
* `commit`, `author` and `files`. Null
127+
* when there are too many commits to
128+
* tell.
127129
* @param object[] $open_pull_requests Open pull requests against the
128130
* default branch, with `number`,
129131
* `title`, `user`, `draft` and
130132
* `milestone`.
131133
*
132-
* @return array{repo: string, status: string, latest_tag: string|null, release: array|null, pull_requests: array, blockers: array, direct_commits: array, open_pull_requests: array, open_items: array, open_milestones: array}
134+
* @return array{repo: string, status: string, latest_tag: string|null, release: array|null, pull_requests: array, blockers: array, direct_commits: array|null, open_pull_requests: array, open_items: array, open_milestones: array}
133135
*/
134-
public static function assess( $repo, array $tags, array $milestones, array $pull_requests, array $direct_commits = [], array $open_pull_requests = [] ) {
136+
public static function assess( $repo, array $tags, array $milestones, array $pull_requests, $direct_commits = [], array $open_pull_requests = [] ) {
135137
$latest_tag = self::latest_version_tag( $tags );
136138
$changes = array_values( array_filter( $pull_requests, [ __CLASS__, 'is_change' ] ) );
137139

@@ -144,7 +146,7 @@ public static function assess( $repo, array $tags, array $milestones, array $pul
144146
'blockers' => [],
145147
];
146148

147-
$plan['direct_commits'] = array_values( array_map( [ __CLASS__, 'describe_commit' ], array_filter( $direct_commits, [ __CLASS__, 'is_direct_change' ] ) ) );
149+
$plan['direct_commits'] = null === $direct_commits ? null : array_values( array_map( [ __CLASS__, 'describe_commit' ], array_filter( $direct_commits, [ __CLASS__, 'is_direct_change' ] ) ) );
148150
$plan['open_pull_requests'] = [];
149151
$plan['open_items'] = [];
150152
$plan['open_milestones'] = [];
@@ -358,7 +360,7 @@ private static function is_change( $pull_request ) {
358360
* @return bool
359361
*/
360362
private static function is_direct_change( $commit ) {
361-
return ! self::are_routine_files( array_column( (array) $commit->files, 'filename' ) );
363+
return ! self::are_routine_files( GitHub::file_names( (array) $commit->files ) );
362364
}
363365

364366
/**

‎tests/GitHubApiTest.php‎

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,22 @@ public function test_direct_commits_are_unknown_for_a_truncated_comparison(): vo
196196
$comparison = $this->fixture( 'comparison' );
197197
$comparison->total_commits = 300;
198198

199-
$this->assertSame( [], GitHub::get_direct_commits( 'wp-cli/block-command', $comparison, [] ) );
199+
$this->assertNull( GitHub::get_direct_commits( 'wp-cli/block-command', $comparison, [] ) );
200200
$this->assertSame( [], $this->requests );
201201
}
202+
203+
public function test_file_names_include_the_previous_name_of_a_renamed_file(): void {
204+
$this->assertSame(
205+
[ 'src/New.php', '.github/new.yml', 'src/Old.php' ],
206+
GitHub::file_names(
207+
[
208+
(object) [ 'filename' => 'src/New.php' ],
209+
(object) [
210+
'filename' => '.github/new.yml',
211+
'previous_filename' => 'src/Old.php',
212+
],
213+
]
214+
)
215+
);
216+
}
202217
}

‎tests/MilestoneCommandTest.php‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,4 +126,8 @@ public function test_assign_refuses_a_closed_milestone(): void {
126126
public function test_assign_needs_numbers(): void {
127127
$this->assert_refused( [ 'block-command', '1.0.4', 'abc' ], [], "'abc' is not the number" );
128128
}
129+
130+
public function test_assign_checks_every_number_before_any_write(): void {
131+
$this->assert_refused( [ 'block-command', '1.0.5', '19', '0' ], [ 'create' => true ], "'0' is not the number" );
132+
}
129133
}

‎tests/ReleasePlanTest.php‎

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -287,4 +287,30 @@ static function ( $file ) {
287287
$plan['direct_commits']
288288
);
289289
}
290+
291+
public function test_moving_code_into_development_files_is_a_change(): void {
292+
$renamed = (object) [
293+
'sha' => 'ccc',
294+
'commit' => (object) [
295+
'message' => 'Move the command',
296+
'author' => (object) [ 'name' => 'Jane Doe' ],
297+
],
298+
'author' => null,
299+
'files' => [
300+
(object) [
301+
'filename' => '.github/Legacy_Command.php',
302+
'previous_filename' => 'src/Legacy_Command.php',
303+
],
304+
],
305+
];
306+
307+
$plan = Release_Plan::assess( 'wp-cli/db-command', [ 'v3.0.1' ], [], [], [ $renamed ] );
308+
309+
$this->assertSame( [ 'ccc' ], array_column( $plan['direct_commits'], 'sha' ) );
310+
}
311+
312+
public function test_direct_commits_stay_unknown_when_github_cannot_tell(): void {
313+
$this->assertNull( Release_Plan::assess( 'wp-cli/db-command', [ 'v3.0.1' ], [], [], null )['direct_commits'] );
314+
$this->assertSame( [], Release_Plan::assess( 'wp-cli/db-command', [ 'v3.0.1' ], [], [], [] )['direct_commits'] );
315+
}
290316
}

0 commit comments

Comments
 (0)