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