Skip to content

Commit 98bf1a2

Browse files
authored
chore: update release script (#1398)
1 parent e56cb6d commit 98bf1a2

File tree

1 file changed

+51
-28
lines changed

1 file changed

+51
-28
lines changed

bin/release

Lines changed: 51 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ use Composer\Semver\VersionParser;
1818
use Tempest\Console\Console;
1919
use Tempest\Console\ConsoleApplication;
2020
use Tempest\Console\Exceptions\InterruptException;
21+
use Tempest\Http\Response;
2122
use Tempest\Http\Status;
2223
use Tempest\HttpClient\HttpClient;
2324
use Tempest\Support\Json;
@@ -168,28 +169,51 @@ function performPreReleaseChecks(string $remote, string $branch): void
168169
}
169170
}
170171

171-
/**
172+
/**
172173
* Disables the protection ruleset, so the release branch can be pushed to without a pull request.
173174
*/
174175
function updateBranchProtection(bool $enabled): void
175176
{
176177
// https://github.com/tempestphp/tempest-framework/settings/rules/1879240
177178
$ruleset = '1879240';
178179
$token = Tempest\env('RELEASE_GITHUB_TOKEN');
179-
$url = "https://api.github.com/repos/tempestphp/tempest-framework/rulesets/{$ruleset}";
180+
$uri = "https://api.github.com/repos/tempestphp/tempest-framework/rulesets/{$ruleset}";
180181

181182
$httpClient = Tempest\get(HttpClient::class);
182183
$response = $httpClient->put(
183-
uri: $url,
184+
uri: $uri,
184185
headers: ['Authorization' => "Bearer {$token}"],
185-
body: Json\encode(['enforcement' => $enabled ? 'active' : 'disabled'])
186+
body: Json\encode(['enforcement' => $enabled ? 'active' : 'disabled']),
187+
);
188+
189+
if ($response->status->isSuccessful()) {
190+
throw new Exception('Failed to update branch ruleset.');
191+
}
192+
}
193+
194+
function triggerSubsplit(): Response
195+
{
196+
$token = Tempest\env('RELEASE_GITHUB_TOKEN');
197+
$uri = 'https://api.github.com/repos/tempestphp/tempest-framework/actions/workflows/subsplit-packages.yml/dispatches';
198+
199+
$httpClient = Tempest\get(HttpClient::class);
200+
201+
$response = $httpClient->post(
202+
uri: $uri,
203+
headers: [
204+
'Authorization' => "Bearer {$token}",
205+
'Accept' => 'application/vnd.github+json',
206+
'X-GitHub-Api-Version' => '2022-11-28',
207+
],
208+
body: Json\encode(['ref' => 'main']),
186209
);
187210

188-
if ($response->status !== Status::OK) {
211+
if ($response->status->isSuccessful()) {
189212
throw new Exception('Failed to update branch ruleset.');
190213
}
191214
}
192215

216+
193217
/**
194218
* Gets the current version.
195219
*/
@@ -210,9 +234,9 @@ function suggestNextVersions(string $current): array
210234
}
211235

212236
$isStable = ! isset($matches[4]);
213-
$major = (int) $matches[1];
214-
$minor = (int) $matches[2];
215-
$patch = (int) $matches[3];
237+
$major = (int)$matches[1];
238+
$minor = (int)$matches[2];
239+
$patch = (int)$matches[3];
216240

217241
// Current version is stable
218242
if ($isStable) {
@@ -280,8 +304,8 @@ function updateJsonFile(string $path, Closure $callback): void
280304
$content = $callback(json_decode($content, associative: true), $indent);
281305
$content = preg_replace_callback(
282306
'/^ +/m',
283-
fn ($m) => str_repeat($indent, \strlen($m[0]) / 4),
284-
json_encode($content, \JSON_PRETTY_PRINT | \JSON_UNESCAPED_SLASHES),
307+
fn ($m) => str_repeat($indent, strlen($m[0]) / 4),
308+
json_encode($content, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES),
285309
);
286310

287311
file_put_contents($path, $content . "\n");
@@ -329,13 +353,13 @@ try {
329353
$new = $console->ask(
330354
question: 'What should the new version be?',
331355
options: arr(suggestNextVersions($current))
332-
->map(fn (string $version, string $type) => (string) str($type)->replace('_', ' ')->append(': ', $version))
356+
->map(fn (string $version, string $type) => (string)str($type)->replace('_', ' ')->append(': ', $version))
333357
->values()
334358
->toArray(),
335359
);
336360

337361
$isMajor = str_contains($new, 'major');
338-
$version = (string) str($new)->afterLast(': ');
362+
$version = (string)str($new)->afterLast(': ');
339363
$tag = "v{$version}";
340364

341365
// Check the tag
@@ -349,10 +373,10 @@ try {
349373
// Bump PHP packages
350374
$console->task(
351375
label: 'Bumping PHP packages',
352-
handler: fn () => [
353-
bumpKernelVersion($version),
354-
bumpPhpPackages($version, $isMajor),
355-
],
376+
handler: function () use ($version, $isMajor) {
377+
bumpKernelVersion($version);
378+
bumpPhpPackages($version, $isMajor);
379+
},
356380
);
357381

358382
// Bump JavaScript packages
@@ -373,28 +397,27 @@ try {
373397
// Push tags
374398
$console->task(
375399
label: 'Releasing',
376-
handler: fn () => [
377-
commit("chore: release {$tag}"),
400+
handler: function () use ($tag) {
401+
commit("chore: release {$tag}");
378402
executeCommands([
379403
"git tag {$tag}",
380404
"git push origin tag {$tag}",
381-
]),
382-
],
405+
]);
406+
},
383407
);
384408

385409
// Clean up
386410
$console->task(
387411
label: 'Cleaning up',
388-
handler: fn () => [
389-
cleanUpAfterRelease(),
390-
commit('chore: post-release clean up'),
391-
executeCommands('git push'),
392-
],
412+
handler: function () {
413+
cleanUpAfterRelease();
414+
commit('chore: post-release clean up');
415+
executeCommands('git push');
416+
updateBranchProtection(enabled: true);
417+
triggerSubsplit();
418+
},
393419
);
394420

395-
// Re-enable protection
396-
updateBranchProtection(enabled: true);
397-
398421
$console->success(sprintf(
399422
'Released <em>%1$s</em>. The <href="https://github.com/tempestphp/tempest-framework/releases/tag/%1$s">GitHub release</href> will be created automatically in a few seconds.',
400423
$tag,

0 commit comments

Comments
 (0)