Skip to content

Commit f3d5aef

Browse files
Radoslaw Ziemniewiczclaude
andcommitted
Let a branch alias be ahead of the tags
The check called an alias ahead of the newest tag an error, which is the state every release passes through: the alias is bumped in the commit before the tag exists, so the check was red for exactly as long as a release takes. Behind is the defect — that is a development branch Composer places in a range nobody is asking for. Ahead is dev-main saying what is coming. Compared as numbers rather than as strings, so 0.9 does not come after 0.13. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_012AppuDfzu2xSefw86WcUhJ
1 parent 990c322 commit f3d5aef

2 files changed

Lines changed: 53 additions & 4 deletions

File tree

src/Checks/Manifest.php

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -114,20 +114,37 @@ private function alias(Package $package, array $extra): array
114114
return [];
115115
}
116116

117-
$line = implode('.', array_slice(explode('.', ltrim($tag, 'vV')), 0, 2));
118-
$expected = "{$line}.x-dev";
117+
$line = array_slice(explode('.', ltrim($tag, 'vV')), 0, 2);
118+
$expected = implode('.', $line) . '.x-dev';
119119

120-
if ($alias === $expected) {
120+
// The alias may be ahead of the tags: `dev-main` is the release being prepared, and
121+
// the alias is bumped in the commit before the tag exists. Behind is the defect — that
122+
// is a development branch Composer places in a range nobody is asking for.
123+
if (self::asNumbers($alias) >= self::asNumbers($expected)) {
121124
return [];
122125
}
123126

124127
return [Finding::failed(
125128
$this->name(),
126129
"The branch alias is `{$alias}`, and the newest tag is `{$tag}`.",
127-
"Composer reads the alias to decide what `dev-main` is, so it wants `{$expected}`."
130+
"Composer reads the alias to decide what `dev-main` is, so it wants `{$expected}` "
131+
. 'or the line being prepared.'
128132
)];
129133
}
130134

135+
/**
136+
* A `0.13.x-dev` read as something two numbers can be compared by, so `0.9` does not come
137+
* after `0.13` the way it does alphabetically.
138+
*
139+
* @return array{0: int, 1: int}
140+
*/
141+
private static function asNumbers(string $alias): array
142+
{
143+
$parts = explode('.', $alias);
144+
145+
return [(int) $parts[0], (int) ($parts[1] ?? 0)];
146+
}
147+
131148
/**
132149
* The newest tag here, by version rather than by name — `v0.9.1` sorts after `v0.13.0`
133150
* alphabetically and before it in every way that matters.

tests/Unit/TestManifestAndBadges.php

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,4 +122,36 @@ public function aBranchAliasWhichDoesNotMatchTheTagsIsFound()
122122

123123
$this->assertEqual->equal(0, $this->failures($this->manifest()->run($here)));
124124
}
125+
126+
/**
127+
* An alias ahead of the tags is the release being prepared: it is bumped in the commit
128+
* before the tag exists, and a check which called that an error would be red for the whole
129+
* of every release. Behind is the defect.
130+
*/
131+
public function anAliasAheadOfTheTagsIsTheOneBeingPrepared()
132+
{
133+
$ahead = [self::class, 'aheadAndBehind'];
134+
135+
$this->assertEqual->equal([true, false], $ahead());
136+
}
137+
138+
/**
139+
* @return array{0: bool, 1: bool}
140+
*/
141+
public static function aheadAndBehind(): array
142+
{
143+
$manifest = new Manifest('https://quillstack.org/packages/{name}', [], true, []);
144+
$method = new \ReflectionMethod($manifest, 'asNumbers');
145+
146+
/** @var array{0: int, 1: int} $prepared */
147+
$prepared = $method->invoke(null, '0.7.x-dev');
148+
/** @var array{0: int, 1: int} $tagged */
149+
$tagged = $method->invoke(null, '0.6.x-dev');
150+
/** @var array{0: int, 1: int} $stale */
151+
$stale = $method->invoke(null, '0.9.x-dev');
152+
/** @var array{0: int, 1: int} $line */
153+
$line = $method->invoke(null, '0.13.x-dev');
154+
155+
return [$prepared >= $tagged, $stale >= $line];
156+
}
125157
}

0 commit comments

Comments
 (0)