Skip to content

Commit 567a4be

Browse files
committed
chore: add scripts for release process
1 parent b576cd9 commit 567a4be

File tree

2 files changed

+148
-0
lines changed

2 files changed

+148
-0
lines changed

admin/create-new-changelog.php

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
function replace_file_content(string $path, string $pattern, string $replace): void
6+
{
7+
$file = file_get_contents($path);
8+
$output = preg_replace($pattern, $replace, $file);
9+
file_put_contents($path, $output);
10+
}
11+
12+
// Main.
13+
chdir(__DIR__ . '/..');
14+
15+
if ($argc !== 3) {
16+
echo "Usage: php {$argv[0]} <current_version> <new_version>" . PHP_EOL;
17+
echo "E.g.,: php {$argv[0]} 4.4.3 4.4.4" . PHP_EOL;
18+
19+
exit(1);
20+
}
21+
22+
// Gets version number from argument.
23+
$versionCurrent = $argv[1]; // e.g., '4.4.3'
24+
$versionCurrentParts = explode('.', $versionCurrent);
25+
$minorCurrent = $versionCurrentParts[0] . '.' . $versionCurrentParts[1];
26+
$version = $argv[2]; // e.g., '4.4.4'
27+
$versionParts = explode('.', $version);
28+
$minor = $versionParts[0] . '.' . $versionParts[1];
29+
$isMinorUpdate = ($minorCurrent !== $minor);
30+
31+
// Creates a branch for release.
32+
system('git switch develop');
33+
system('git switch -c docs-changelog-' . $version);
34+
system('git switch docs-changelog-' . $version);
35+
36+
// Copy changelog
37+
$changelog = "./user_guide_src/source/changelogs/v{$version}.rst";
38+
$changelogIndex = './user_guide_src/source/changelogs/index.rst';
39+
if ($isMinorUpdate) {
40+
copy('./admin/next-changelog-minor.rst', $changelog);
41+
} else {
42+
copy('./admin/next-changelog-patch.rst', $changelog);
43+
}
44+
// Add changelog to index.rst.
45+
replace_file_content(
46+
$changelogIndex,
47+
'/\.\. toctree::\n :titlesonly:\n/u',
48+
".. toctree::\n :titlesonly:\n\n v{$version}"
49+
);
50+
// Replace {version}
51+
$length = mb_strlen("Version {$version}");
52+
$underline = str_repeat('#', $length);
53+
replace_file_content(
54+
$changelog,
55+
'/#################\nVersion {version}\n#################/u',
56+
"{$underline}\nVersion {$version}\n{$underline}"
57+
);
58+
replace_file_content(
59+
$changelog,
60+
'/{version}/u',
61+
"{$version}"
62+
);
63+
64+
// Copy upgrading
65+
$versionWithoutDots = str_replace('.', '', $version);
66+
$upgrading = "./user_guide_src/source/installation/upgrade_{$versionWithoutDots}.rst";
67+
$upgradingIndex = './user_guide_src/source/installation/upgrading.rst';
68+
copy('./admin/next-upgrading-guide.rst', $upgrading);
69+
// Add upgrading to upgrading.rst.
70+
replace_file_content(
71+
$upgradingIndex,
72+
'/ backward_compatibility_notes\n/u',
73+
" backward_compatibility_notes\n\n upgrade_{$versionWithoutDots}"
74+
);
75+
// Replace {version}
76+
$length = mb_strlen("Upgrading from {$versionCurrent} to {$version}");
77+
$underline = str_repeat('#', $length);
78+
replace_file_content(
79+
$upgrading,
80+
'/##############################\nUpgrading from {version} to {version}\n##############################/u',
81+
"{$underline}\nUpgrading from {$versionCurrent} to {$version}\n{$underline}"
82+
);
83+
84+
// Commits
85+
system("git add {$changelog} {$changelogIndex}");
86+
system("git add {$upgrading} {$upgradingIndex}");
87+
system('git commit -m "docs: add changelog and upgrade for v' . $version . '"');

admin/prepare-release.php

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
function replace_file_content(string $path, string $pattern, string $replace): void
6+
{
7+
$file = file_get_contents($path);
8+
$output = preg_replace($pattern, $replace, $file);
9+
file_put_contents($path, $output);
10+
}
11+
12+
// Main.
13+
chdir(__DIR__ . '/..');
14+
15+
if ($argc !== 2) {
16+
echo "Usage: php {$argv[0]} <version>" . PHP_EOL;
17+
echo "E.g.,: php {$argv[0]} 4.4.3" . PHP_EOL;
18+
19+
exit(1);
20+
}
21+
22+
// Gets version number from argument.
23+
$version = $argv[1]; // e.g., '4.4.3'
24+
$versionParts = explode('.', $version);
25+
$minor = $versionParts[0] . '.' . $versionParts[1];
26+
27+
// Creates a branch for release.
28+
system('git switch develop');
29+
system('git switch -c release-' . $version);
30+
system('git switch docs-changelog-' . $version);
31+
32+
// Updates version number in "CodeIgniter.php".
33+
replace_file_content(
34+
'./system/CodeIgniter.php',
35+
'/public const CI_VERSION = \'.*?\';/u',
36+
"public const CI_VERSION = '{$version}';"
37+
);
38+
39+
// Updates version number in "conf.py".
40+
replace_file_content(
41+
'./user_guide_src/source/conf.py',
42+
'/^version = \'.*?\'/mu',
43+
"version = '{$minor}'"
44+
);
45+
replace_file_content(
46+
'./user_guide_src/source/conf.py',
47+
'/^release = \'.*?\'/mu',
48+
"release = '{$version}'"
49+
);
50+
51+
// Updates release date in changelogs.
52+
$date = date('F j, Y');
53+
replace_file_content(
54+
"./user_guide_src/source/changelogs/v{$version}.rst",
55+
'/^Release Date: .*/mu',
56+
"Release Date: {$date}"
57+
);
58+
59+
// Commits
60+
system('git add -u');
61+
system('git commit -m "Prep for ' . $version . ' release"');

0 commit comments

Comments
 (0)