Skip to content

Commit 6689079

Browse files
authored
chore: port the release tooling to Markdown (#10716)
1 parent 8e03e03 commit 6689079

12 files changed

Lines changed: 173 additions & 83 deletions

‎.github/scripts/validate-version‎

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,9 @@ if [[ -z $1 ]]; then
66
exit 1
77
fi
88

9-
FILES=("system/CodeIgniter.php" "user_guide_src/source/conf.py")
10-
LENGTH="${#FILES[@]}"
9+
CHANGELOG="docs/changelogs/v$1.md"
1110

12-
for FILE in "${FILES[@]}"; do
13-
COUNT="$((COUNT + $(grep -c "$FILE" -e "'$1'")))"
14-
done
15-
16-
if [[ $COUNT -ne $LENGTH ]]; then
11+
if ! grep -q -e "'$1'" system/CodeIgniter.php || [[ ! -f $CHANGELOG ]] || grep -q -e "^Release Date: Unreleased" "$CHANGELOG"; then
1712
echo "CodeIgniter version is not updated to v"$1""
1813
exit 1
1914
fi

‎admin/RELEASE.md‎

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,7 @@ Lines that start with `D` are removed files. Make sure none of them is needed by
216216

217217
Skip this step if the release has no security fixes.
218218

219-
Merge any security advisory pull requests from the private forks. Each fix must also be documented in the `SECURITY` section of **user_guide_src/source/changelogs/v$VERSION.rst**, because step 7 copies that section into **CHANGELOG.md**.
219+
Merge any security advisory pull requests from the private forks. Each fix must also be documented in the `SECURITY` section of **docs/changelogs/v$VERSION.md**, because step 7 copies that section into **CHANGELOG.md**.
220220

221221
### 7. Generate `CHANGELOG.md`
222222

@@ -244,12 +244,12 @@ Copy the result into **CHANGELOG.md** and match the format of the existing entri
244244

245245
### 8. Update the detailed changelog
246246

247-
Edit **user_guide_src/source/changelogs/v$VERSION.rst**.
247+
Edit **docs/changelogs/v$VERSION.md**.
248248
Remove every section title that has no items under it.
249249

250250
### 9. Update the upgrade guide
251251

252-
Edit the upgrade guide page for the version in **user_guide_src/source/installation/**. The file name is `upgrade_` followed by the version without dots, so `4.7.6` is **upgrade_476.rst**.
252+
Edit the upgrade guide page for the version in **docs/installation/**. The file name is `upgrade_` followed by the version without dots, so `4.7.6` is **upgrade_476.md**.
253253

254254
Preview the generated content:
255255

@@ -284,8 +284,8 @@ The script does the following:
284284

285285
- Creates the branch `release-$VERSION` from `develop`, replacing any local branch of the same name.
286286
- Sets `CI_VERSION` in **system/CodeIgniter.php** to `$VERSION`.
287-
- Sets `version` (for example `4.7`) and `release` (for example `4.7.6`) in **user_guide_src/source/conf.py**.
288-
- Sets the release date in **user_guide_src/source/changelogs/v$VERSION.rst** (format `Release Date: January 31, 2021`).
287+
- Sets the minor version (for example `4.7`) in the title `## Version 4.7` of **docs/changelogs/index.md**.
288+
- Sets the release date in **docs/changelogs/v$VERSION.md** (format `Release Date: January 31, 2021`).
289289
- Updates the title and version in **phpdoc.dist.xml**.
290290
- Updates **admin/starter/builds**: `LATEST_RELEASE` becomes `^<minor>` and `NEXT_MINOR` becomes `^<next minor>-dev`.
291291
- Commits everything, including your uncommitted edits to tracked files, as `Prep for $VERSION release`.
@@ -490,8 +490,9 @@ php admin/create-new-changelog.php $VERSION $NEXT_VERSION
490490

491491
The script does the following:
492492

493-
- Creates **user_guide_src/source/changelogs/v$NEXT_VERSION.rst** from **admin/next-changelog-patch.rst** and adds it to **index.rst**.
494-
- Creates the upgrade guide stub from **admin/next-upgrading-guide.rst** and adds it to **upgrading.rst**.
493+
- Creates **docs/changelogs/v$NEXT_VERSION.md** from **admin/next-changelog-patch.md** and adds it to **index.md**.
494+
- Creates the upgrade guide stub from **admin/next-upgrading-guide.md** and adds it to **upgrading.md**.
495+
- Adds both pages to **docs/.nav.yml**.
495496
- Sets `CI_VERSION` to `$NEXT_VERSION-dev`.
496497
- Creates the branch `docs-changelog-$NEXT_VERSION` from `develop` and commits.
497498

‎admin/create-new-changelog.php‎

Lines changed: 19 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -38,13 +38,13 @@ function replace_file_content(string $path, string $pattern, string $replace): v
3838
}
3939

4040
// Copy changelog
41-
$newChangelog = "./user_guide_src/source/changelogs/v{$newVersion}.rst";
42-
$changelogIndex = './user_guide_src/source/changelogs/index.rst';
41+
$newChangelog = "./docs/changelogs/v{$newVersion}.md";
42+
$changelogIndex = './docs/changelogs/index.md';
4343

4444
if ($isMinorUpdate) {
45-
copy('./admin/next-changelog-minor.rst', $newChangelog);
45+
copy('./admin/next-changelog-minor.md', $newChangelog);
4646
} else {
47-
copy('./admin/next-changelog-patch.rst', $newChangelog);
47+
copy('./admin/next-changelog-patch.md', $newChangelog);
4848
}
4949

5050
// Replace version in CodeIgniter.php to {version}-dev.
@@ -54,46 +54,42 @@ function replace_file_content(string $path, string $pattern, string $replace): v
5454
"public const CI_VERSION = '{$newVersion}-dev';",
5555
);
5656

57-
// Add changelog to index.rst.
57+
// Add changelog to the index, newest first.
5858
replace_file_content(
5959
$changelogIndex,
60-
'/\.\. toctree::\n :titlesonly:\n/u',
61-
".. toctree::\n :titlesonly:\n\n v{$newVersion}",
60+
'/^(See all the changes\.\n\n)/mu',
61+
"\$1- [Version {$newVersion}](v{$newVersion}.md)\n",
6262
);
6363

6464
// Replace {version}
65-
$underline = str_repeat('#', mb_strlen("Version {$newVersion}"));
66-
replace_file_content(
67-
$newChangelog,
68-
'/#################\nVersion {version}\n#################/u',
69-
"{$underline}\nVersion {$newVersion}\n{$underline}",
70-
);
7165
replace_file_content($newChangelog, '/{version}/u', $newVersion);
7266

7367
// Copy upgrading
7468
$versionWithoutDots = str_replace('.', '', $newVersion);
75-
$newUpgrading = "./user_guide_src/source/installation/upgrade_{$versionWithoutDots}.rst";
76-
$upgradingIndex = './user_guide_src/source/installation/upgrading.rst';
77-
copy('./admin/next-upgrading-guide.rst', $newUpgrading);
69+
$newUpgrading = "./docs/installation/upgrade_{$versionWithoutDots}.md";
70+
$upgradingIndex = './docs/installation/upgrading.md';
71+
copy('./admin/next-upgrading-guide.md', $newUpgrading);
7872

79-
// Add upgrading to upgrading.rst.
73+
// Add upgrading to the index, right after the backward compatibility notes.
8074
replace_file_content(
8175
$upgradingIndex,
82-
'/ backward_compatibility_notes\n/u',
83-
" backward_compatibility_notes\n\n upgrade_{$versionWithoutDots}",
76+
'/^(- \[Backward Compatibility Notes\]\(backward_compatibility_notes\.md\)\n)/mu',
77+
"\$1- [Upgrading from {$currentVersion} to {$newVersion}](upgrade_{$versionWithoutDots}.md)\n",
8478
);
8579

8680
// Replace {version}
87-
$underline = str_repeat('#', mb_strlen("Upgrading from {$currentVersion} to {$newVersion}"));
8881
replace_file_content(
8982
$newUpgrading,
90-
'/##############################\nUpgrading from {version} to {version}\n##############################/u',
91-
"{$underline}\nUpgrading from {$currentVersion} to {$newVersion}\n{$underline}",
83+
'/^# Upgrading from {version} to {version}$/mu',
84+
"# Upgrading from {$currentVersion} to {$newVersion}",
9285
);
9386

87+
// Add both pages to the nav.
88+
system('php ./admin/update-docs-nav.php');
89+
9490
if (! in_array('--dry-run', $argv, true)) {
9591
system('git add ./system/CodeIgniter.php');
9692
system("git add {$newChangelog} {$changelogIndex}");
97-
system("git add {$newUpgrading} {$upgradingIndex}");
93+
system("git add {$newUpgrading} {$upgradingIndex} ./docs/.nav.yml");
9894
system("git commit -m \"docs: add changelog and upgrade for v{$newVersion}\"");
9995
}

‎admin/generate-changelog.php‎

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,6 @@
22

33
declare(strict_types=1);
44

5-
/**
6-
* Generates the CHANGELOG.md entry for a new release from GitHub's
7-
* auto-generated release notes and prepends it to CHANGELOG.md.
8-
*
9-
* Requires the authenticated GitHub CLI (`gh`).
10-
*
11-
* Usage: php admin/generate-changelog.php <version> [--dry-run]
12-
*/
135
chdir(__DIR__ . '/..');
146

157
$args = array_slice($argv, 1);
@@ -99,13 +91,13 @@
9991
// Extracts the security fixes from the SECURITY section of the detailed
10092
// changelog, if any. These come from security advisories, not from PRs, so
10193
// they are not part of the generated release notes.
102-
$rstPath = "./user_guide_src/source/changelogs/v{$version}.rst";
103-
$security = '';
94+
$detailedPath = "./docs/changelogs/v{$version}.md";
95+
$security = '';
10496

105-
if (is_file($rstPath)) {
106-
$rst = file_get_contents($rstPath);
97+
if (is_file($detailedPath)) {
98+
$detailed = file_get_contents($detailedPath);
10799

108-
if (preg_match('/^\*+\nSECURITY\n\*+\n(.*?)(?=^\*+$|\z)/msu', $rst, $matches) === 1) {
100+
if (preg_match('/^## SECURITY\n(.*?)(?=^## |\z)/msu', $detailed, $matches) === 1) {
109101
$security = trim($matches[1], "\n");
110102
$security = preg_replace('/^- /mu', '* ', $security);
111103
}

‎admin/next-changelog-minor.md‎

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
# Version {version}
2+
3+
Release Date: Unreleased
4+
5+
**{version} release of CodeIgniter4**
6+
7+
## Highlights
8+
9+
- TBD
10+
11+
## BREAKING
12+
13+
### Behavior Changes
14+
15+
### Interface Changes
16+
17+
### Method Signature Changes
18+
19+
## Enhancements
20+
21+
### Commands
22+
23+
### Testing
24+
25+
### Database
26+
27+
#### Query Builder
28+
29+
#### Forge
30+
31+
#### Others
32+
33+
### Model
34+
35+
### Libraries
36+
37+
### Helpers and Functions
38+
39+
### Others
40+
41+
## Message Changes
42+
43+
## Changes
44+
45+
## Deprecations
46+
47+
## Bugs Fixed
48+
49+
See the repo's [CHANGELOG.md](https://github.com/codeigniter4/CodeIgniter4/blob/develop/CHANGELOG.md) for a complete list of bugs fixed.

‎admin/next-changelog-patch.md‎

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# Version {version}
2+
3+
Release Date: Unreleased
4+
5+
**{version} release of CodeIgniter4**
6+
7+
## BREAKING
8+
9+
## Message Changes
10+
11+
## Changes
12+
13+
## Deprecations
14+
15+
## Bugs Fixed
16+
17+
See the repo's [CHANGELOG.md](https://github.com/codeigniter4/CodeIgniter4/blob/develop/CHANGELOG.md) for a complete list of bugs fixed.

‎admin/next-upgrading-guide.md‎

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
# Upgrading from {version} to {version}
2+
3+
Please refer to the upgrade instructions corresponding to your installation method.
4+
5+
- [Composer Installation App Starter Upgrading](installing_composer.md#upgrading)
6+
- [Composer Installation Adding CodeIgniter4 to an Existing Project Upgrading](installing_composer.md#upgrading_1)
7+
- [Manual Installation Upgrading](installing_manual.md#upgrading)
8+
9+
## Mandatory File Changes
10+
11+
## Breaking Changes
12+
13+
## Breaking Enhancements
14+
15+
## Project Files
16+
17+
Some files in the **project space** (root, app, public, writable) received updates. Due to these files being outside of the **system** scope they will not be changed without your intervention.
18+
19+
!!! note "Note"
20+
There are some third-party CodeIgniter modules available to assist with merging changes to the project space: [Explore on Packagist](https://packagist.org/explore/?query=codeigniter4%20updates).
21+
22+
### Content Changes
23+
24+
The following files received significant changes (including deprecations or visual adjustments) and it is recommended that you merge the updated versions with your application:
25+
26+
#### Config
27+
28+
- @TODO
29+
30+
### All Changes
31+
32+
This is a list of all files in the **project space** that received changes; many will be simple comments or formatting that have no effect on the runtime:
33+
34+
- @TODO

‎admin/prepare-release.php‎

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -39,16 +39,11 @@ function replace_file_content(string $path, string $pattern, string $replace): v
3939
"public const CI_VERSION = '{$version}';",
4040
);
4141

42-
// Updates version number in "conf.py".
42+
// Updates the minor version in the title of the changelog index.
4343
replace_file_content(
44-
'./user_guide_src/source/conf.py',
45-
'/^version = \'.*?\'/mu',
46-
"version = '{$minor}'",
47-
);
48-
replace_file_content(
49-
'./user_guide_src/source/conf.py',
50-
'/^release = \'.*?\'/mu',
51-
"release = '{$version}'",
44+
'./docs/changelogs/index.md',
45+
'/^## Version .*/mu',
46+
"## Version {$minor}",
5247
);
5348

5449
// Updates version number in "phpdoc.dist.xml".
@@ -66,7 +61,7 @@ function replace_file_content(string $path, string $pattern, string $replace): v
6661
// Updates release date in changelogs.
6762
$date = date('F j, Y');
6863
replace_file_content(
69-
"./user_guide_src/source/changelogs/v{$version}.rst",
64+
"./docs/changelogs/v{$version}.md",
7065
'/^Release Date: .*/mu',
7166
"Release Date: {$date}",
7267
);

‎admin/update-upgrade-guide.php‎

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ function bullets(array $items): string
5858
$version = $params[0];
5959
$dryRun = in_array('--dry-run', $options, true);
6060

61-
$upgradePath = sprintf('./user_guide_src/source/installation/upgrade_%s.rst', str_replace('.', '', $version));
61+
$upgradePath = sprintf('./docs/installation/upgrade_%s.md', str_replace('.', '', $version));
6262

6363
if (! is_file($upgradePath)) {
6464
echo sprintf("%s is not found. Run \"php admin/create-new-changelog.php\" first.\n", $upgradePath);
@@ -83,11 +83,13 @@ function bullets(array $items): string
8383
':!admin/',
8484
':!changelogs/',
8585
':!contributing/',
86+
':!docs/',
8687
':!system/',
8788
':!tests/',
8889
':!user_guide_src/',
8990
':!utils/',
9091
':!.*',
92+
':!mkdocs.yml',
9193
':!*.md',
9294
':!*.json',
9395
':!*.xml',
@@ -160,21 +162,21 @@ function bullets(array $items): string
160162
: bullets($allChanges);
161163

162164
if ($dryRun) {
163-
echo "\nConfig\n------\n\n{$configContent}\n";
164-
echo "\nAll Changes\n===========\n\n{$allChangesContent}\n";
165+
echo "\n#### Config\n\n{$configContent}\n";
166+
echo "\n### All Changes\n\n{$allChangesContent}\n";
165167

166168
exit(0);
167169
}
168170

169-
$rst = file_get_contents($upgradePath);
171+
$markdown = file_get_contents($upgradePath);
170172

171173
// Fills the "Config" section, only if it still has the placeholder. Entries
172174
// may have been added ahead of time for changes that need discussion, and
173175
// those must not be overwritten.
174-
if (preg_match('/^Config\n------\n\n(.*?)(?=^[^\s-][^\n]*\n(?:-+|=+)$|\z)/msu', $rst, $matches) !== 1) {
176+
if (preg_match('/^#### Config\n\n(.*?)(?=^#{1,4} |\z)/msu', $markdown, $matches) !== 1) {
175177
echo "Could not find the \"Config\" section in {$upgradePath}. Update it manually.\n";
176178
} elseif (trim($matches[1]) === '- @TODO') {
177-
$rst = str_replace("Config\n------\n\n{$matches[1]}", "Config\n------\n\n{$configContent}\n\n", $rst);
179+
$markdown = str_replace("#### Config\n\n{$matches[1]}", "#### Config\n\n{$configContent}\n\n", $markdown);
178180

179181
echo "The \"Config\" section was updated. Add notes to each entry as needed.\n";
180182
} else {
@@ -195,8 +197,8 @@ function bullets(array $items): string
195197
}
196198

197199
// Fills the "All Changes" section, replacing any previous list.
198-
$pattern = '/^(All Changes\n===========\n\n.*?:\n\n)(.*?)(?=^\*+$|\z)/msu';
199-
$updated = preg_replace($pattern, "\$1{$allChangesContent}\n", $rst, 1, $count);
200+
$pattern = '/^(### All Changes\n\n.*?:\n\n)(.*?)(?=^#{1,3} |\z)/msu';
201+
$updated = preg_replace($pattern, "\$1{$allChangesContent}\n", $markdown, 1, $count);
200202

201203
if ($count !== 1) {
202204
echo "Could not find the \"All Changes\" section in {$upgradePath}. Update it manually.\n";

0 commit comments

Comments
 (0)