@@ -9,81 +9,90 @@ function replace_file_content(string $path, string $pattern, string $replace): v
99 file_put_contents ($ path , $ output );
1010}
1111
12- // Main.
1312chdir (__DIR__ . '/.. ' );
1413
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 ;
14+ if (! isset ( $ argv [ 1 ]) || ! isset ( $ argv [ 2 ]) ) {
15+ echo "Usage: php {$ argv [0 ]} <current_version> <new_version> [--dry-run] \n" ;
16+ echo "E.g. : php {$ argv [0 ]} 4.4.3 4.4.4 --dry-run \n" ;
1817
1918 exit (1 );
2019}
2120
2221// 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- if (! $ isMinorUpdate ) {
33- system ('git switch develop ' );
22+ $ currentVersion = $ argv [1 ]; // e.g., '4.4.3'
23+ $ currentVersionParts = explode ('. ' , $ currentVersion , 3 );
24+ $ currentMinorVersion = $ currentVersionParts [0 ] . '. ' . $ currentVersionParts [1 ];
25+ $ newVersion = $ argv [2 ]; // e.g., '4.4.4'
26+ $ newVersionParts = explode ('. ' , $ newVersion , 3 );
27+ $ newMinorVersion = $ newVersionParts [0 ] . '. ' . $ newVersionParts [1 ];
28+ $ isMinorUpdate = $ currentMinorVersion !== $ newMinorVersion ;
29+
30+ // Creates a branch for release
31+ if (! in_array ('--dry-run ' , $ argv , true )) {
32+ if (! $ isMinorUpdate ) {
33+ system ('git switch develop ' );
34+ }
35+
36+ system ("git switch -c docs-changelog- {$ newVersion }" );
37+ system ("git switch docs-changelog- {$ newVersion }" );
3438}
35- system ('git switch -c docs-changelog- ' . $ version );
36- system ('git switch docs-changelog- ' . $ version );
3739
3840// Copy changelog
39- $ changelog = "./user_guide_src/source/changelogs/v {$ version }.rst " ;
41+ $ newChangelog = "./user_guide_src/source/changelogs/v {$ newVersion }.rst " ;
4042$ changelogIndex = './user_guide_src/source/changelogs/index.rst ' ;
43+
4144if ($ isMinorUpdate ) {
42- copy ('./admin/next-changelog-minor.rst ' , $ changelog );
45+ copy ('./admin/next-changelog-minor.rst ' , $ newChangelog );
4346} else {
44- copy ('./admin/next-changelog-patch.rst ' , $ changelog );
47+ copy ('./admin/next-changelog-patch.rst ' , $ newChangelog );
4548}
49+
50+ // Replace version in CodeIgniter.php to {version}-dev.
51+ replace_file_content (
52+ './system/CodeIgniter.php ' ,
53+ '/public const CI_VERSION = \'.*? \';/u ' ,
54+ "public const CI_VERSION = ' {$ newVersion }-dev'; " ,
55+ );
56+
4657// Add changelog to index.rst.
4758replace_file_content (
4859 $ changelogIndex ,
4960 '/\.\. toctree::\n :titlesonly:\n/u ' ,
50- ".. toctree:: \n :titlesonly: \n\n v {$ version }" ,
61+ ".. toctree:: \n :titlesonly: \n\n v {$ newVersion }" ,
5162);
63+
5264// Replace {version}
53- $ length = mb_strlen ("Version {$ version }" );
54- $ underline = str_repeat ('# ' , $ length );
65+ $ underline = str_repeat ('# ' , mb_strlen ("Version {$ newVersion }" ));
5566replace_file_content (
56- $ changelog ,
67+ $ newChangelog ,
5768 '/#################\nVersion {version}\n#################/u ' ,
58- "{$ underline }\nVersion {$ version }\n{$ underline }" ,
59- );
60- replace_file_content (
61- $ changelog ,
62- '/{version}/u ' ,
63- "{$ version }" ,
69+ "{$ underline }\nVersion {$ newVersion }\n{$ underline }" ,
6470);
71+ replace_file_content ($ newChangelog , '/{version}/u ' , $ newVersion );
6572
6673// Copy upgrading
67- $ versionWithoutDots = str_replace ('. ' , '' , $ version );
68- $ upgrading = "./user_guide_src/source/installation/upgrade_ {$ versionWithoutDots }.rst " ;
74+ $ versionWithoutDots = str_replace ('. ' , '' , $ newVersion );
75+ $ newUpgrading = "./user_guide_src/source/installation/upgrade_ {$ versionWithoutDots }.rst " ;
6976$ upgradingIndex = './user_guide_src/source/installation/upgrading.rst ' ;
70- copy ('./admin/next-upgrading-guide.rst ' , $ upgrading );
77+ copy ('./admin/next-upgrading-guide.rst ' , $ newUpgrading );
78+
7179// Add upgrading to upgrading.rst.
7280replace_file_content (
7381 $ upgradingIndex ,
7482 '/ backward_compatibility_notes\n/u ' ,
7583 " backward_compatibility_notes \n\n upgrade_ {$ versionWithoutDots }" ,
7684);
85+
7786// Replace {version}
78- $ length = mb_strlen ("Upgrading from {$ versionCurrent } to {$ version }" );
79- $ underline = str_repeat ('# ' , $ length );
87+ $ underline = str_repeat ('# ' , mb_strlen ("Upgrading from {$ currentVersion } to {$ newVersion }" ));
8088replace_file_content (
81- $ upgrading ,
89+ $ newUpgrading ,
8290 '/##############################\nUpgrading from {version} to {version}\n##############################/u ' ,
83- "{$ underline }\nUpgrading from {$ versionCurrent } to {$ version }\n{$ underline }" ,
91+ "{$ underline }\nUpgrading from {$ currentVersion } to {$ newVersion }\n{$ underline }" ,
8492);
8593
86- // Commits
87- system ("git add {$ changelog } {$ changelogIndex }" );
88- system ("git add {$ upgrading } {$ upgradingIndex }" );
89- system ('git commit -m "docs: add changelog and upgrade for v ' . $ version . '" ' );
94+ if (! in_array ('--dry-run ' , $ argv , true )) {
95+ system ("git add {$ newChangelog } {$ changelogIndex }" );
96+ system ("git add {$ newUpgrading } {$ upgradingIndex }" );
97+ system ("git commit -m \"docs: add changelog and upgrade for v {$ newVersion }\"" );
98+ }
0 commit comments