Skip to content

Commit b4c7923

Browse files
committed
fix: release script notes
1 parent d8a6d9b commit b4c7923

1 file changed

Lines changed: 38 additions & 7 deletions

File tree

tools/release.php

Lines changed: 38 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,9 @@
4444
$overrides = array_merge($overrides, json_decode($repoMap, true));
4545
}
4646

47-
// Determine bump type
47+
// Determine bump type and PR info
4848
$bump = getenv('RELEASE_BUMP') ?: null;
49+
$pr = null;
4950

5051
if (! $bump) {
5152
$response = $http->get(sprintf('/repos/%s/commits/%s/pulls', $repository, $commitSha));
@@ -56,14 +57,20 @@
5657
}
5758

5859
$pr = $response->json()[0];
59-
$bump = collect($pr['labels'] ?? [])
60-
->pluck('name')
60+
$labels = collect($pr['labels'] ?? [])->pluck('name');
61+
62+
$bump = $labels
6163
->filter(fn (string $label) => str_starts_with($label, 'release:'))
6264
->map(fn (string $label) => str_replace('release:', '', $label))
6365
->first();
66+
67+
// new-provider label triggers an initial release
68+
if (! $bump && $labels->contains('new-provider')) {
69+
$bump = 'new-provider';
70+
}
6471
}
6572

66-
if (! $bump || ! in_array($bump, ['major', 'minor', 'patch'])) {
73+
if (! $bump || ! in_array($bump, ['major', 'minor', 'patch', 'new-provider'])) {
6774
echo "No release label found on PR, skipping\n";
6875
exit(0);
6976
}
@@ -103,20 +110,22 @@
103110
$response = $http->get(sprintf('/repos/%s/%s/releases/latest', $org, $repo));
104111
$latest = $response->successful() ? $response->json('tag_name') : null;
105112

106-
if (! $latest) {
107-
echo sprintf("[release] No existing release for %s, starting at 1.0.0\n", $repo);
113+
if ($bump === 'new-provider' || ! $latest) {
108114
$newVersion = '1.0.0';
115+
echo sprintf("[release] Initial release for %s at %s\n", $repo, $newVersion);
109116
} else {
110117
$newVersion = bumpVersion(ltrim($latest, 'v'), $bump, $parser);
111118
}
112119

113120
echo sprintf("[release] %s: %s -> %s\n", $repo, $latest ?? 'none', $newVersion);
114121

122+
$body = generateReleaseBody($newVersion, $latest, $pr, $repository);
123+
115124
$response = $http->post(sprintf('/repos/%s/%s/releases', $org, $repo), [
116125
'tag_name' => $newVersion,
117126
'target_commitish' => 'master',
118127
'name' => $newVersion,
119-
'body' => sprintf('Release %s', $newVersion),
128+
'body' => $body,
120129
]);
121130

122131
if ($response->failed()) {
@@ -130,6 +139,28 @@
130139

131140
echo "All releases complete.\n";
132141

142+
function generateReleaseBody(string $newVersion, ?string $previousVersion, ?array $pr, string $repository): string
143+
{
144+
$lines = ["## What's Changed"];
145+
146+
if ($pr) {
147+
$lines[] = sprintf(
148+
'* %s by @%s in https://github.com/%s/pull/%d',
149+
$pr['title'],
150+
$pr['user']['login'],
151+
$repository,
152+
$pr['number']
153+
);
154+
}
155+
156+
if ($previousVersion) {
157+
$lines[] = '';
158+
$lines[] = sprintf('**Full Changelog**: https://github.com/%s/compare/%s...%s', $repository, $previousVersion, $newVersion);
159+
}
160+
161+
return implode("\n", $lines);
162+
}
163+
133164
function bumpVersion(string $version, string $type, VersionParser $parser): string
134165
{
135166
$normalized = $parser->normalize($version);

0 commit comments

Comments
 (0)