Skip to content

Commit 236cc8a

Browse files
Preserve existing release dates and preamble in changelog generation script; fix typos in changelog entries.
1 parent 36e75c0 commit 236cc8a

File tree

2 files changed

+43
-9
lines changed

2 files changed

+43
-9
lines changed

.github/scripts/generate-changelog.sh

Lines changed: 40 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,19 +8,46 @@
88
#
99
# Optional environment variables:
1010
# PREVIOUS_TAG - Tag to compare from (defaults to latest tag on branch).
11-
# RELEASE_DATE - Release date in YYYY-MM-DD format (defaults to today).
11+
# RELEASE_DATE - Release date in YYYY-MM-DD format (defaults to existing value in changelog, then calculated).
1212
# CHANGELOG_FILE - Path to the changelog file (defaults to changelog.md).
1313

1414
set -euo pipefail
1515

1616
VERSION="${VERSION:?VERSION is required}"
1717
CHANGELOG_FILE="${CHANGELOG_FILE:-changelog.md}"
1818

19-
# Calculate release date using the same logic as the Grunt task:
20-
# - Patch releases (x.y.z where z > 0): today's date.
21-
# - Minor/major releases: next Tuesday ~2 weeks out (today + 2 + 14 - dayOfWeek).
22-
# - Beta releases: add an extra 7 days (~3 weeks out).
23-
if [ -z "${RELEASE_DATE:-}" ]; then
19+
# If the version section already exists in the changelog file, extract its release
20+
# date and any copy between the release date line and the first #### heading
21+
# (the "preamble"). These are preserved as-is when regenerating.
22+
EXISTING_RELEASE_DATE=""
23+
EXISTING_PREAMBLE=""
24+
if [ -f "$CHANGELOG_FILE" ]; then
25+
# Extract the section for the requested version (between its ## header and the next ## header or footer).
26+
VERSION_SECTION=$(sed -n "/^## ${VERSION}\$/,/^## [0-9]/{ /^## ${VERSION}\$/d; /^## [0-9]/d; p; }" "$CHANGELOG_FILE" \
27+
| sed '/^### Earlier versions/,$ d' || true)
28+
29+
if [ -n "$VERSION_SECTION" ]; then
30+
# Extract the existing release date.
31+
EXISTING_RELEASE_DATE=$(echo "$VERSION_SECTION" | grep -oP '(?<=Release date: ).*' | head -1 || true)
32+
33+
# Extract preamble: lines after the release date line and before the first #### heading.
34+
EXISTING_PREAMBLE=$(echo "$VERSION_SECTION" \
35+
| sed -n '/^Release date:/,/^####/{/^Release date:/d; /^####/d; p;}' \
36+
| sed -e '/./,$!d' -e :a -e '/^\n*$/{$d;N;ba;}' || true)
37+
fi
38+
fi
39+
40+
# Use the provided RELEASE_DATE env var if set, otherwise preserve the existing
41+
# release date from the changelog, otherwise calculate a new one.
42+
if [ -n "${RELEASE_DATE:-}" ]; then
43+
: # RELEASE_DATE already set via environment.
44+
elif [ -n "$EXISTING_RELEASE_DATE" ]; then
45+
RELEASE_DATE="$EXISTING_RELEASE_DATE"
46+
else
47+
# Calculate release date using the same logic as the Grunt task:
48+
# - Patch releases (x.y.z where z > 0): today's date.
49+
# - Minor/major releases: next Tuesday ~2 weeks out (today + 2 + 14 - dayOfWeek).
50+
# - Beta releases: add an extra 7 days (~3 weeks out).
2451
BASE_VERSION=$(echo "$VERSION" | cut -d'-' -f1)
2552
PATCH=$(echo "$BASE_VERSION" | awk -F. '{ print ($3 != "" ? $3 : 0) }')
2653
SUFFIX=$(echo "$VERSION" | grep -oP '(?<=-).*' || true)
@@ -120,6 +147,13 @@ SECTION="## $VERSION
120147
Release date: $RELEASE_DATE
121148
"
122149

150+
# Insert preserved preamble (copy between release date and first #### heading).
151+
if [ -n "$EXISTING_PREAMBLE" ]; then
152+
SECTION+="
153+
$EXISTING_PREAMBLE
154+
"
155+
fi
156+
123157
if [ -n "$ENHANCEMENTS" ]; then
124158
SECTION+="
125159
#### Enhancements

changelog.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,19 +22,19 @@ Release date: 2026-03-09
2222
* Fixes a bug where the block editor button were not styled if the admin bar links where not present.
2323
* Fixes a bug where Rewrite & Republish copies could remain orphaned, blocking editors from creating a new Rewrite & Republish copy for the original post.
2424
* Fixes a bug where cloning an attachment did not copy its caption and description as expected. Props to @masteradhoc.
25-
* Fixes a bug where notices would not be appearing in the block editor, throwing console errors, with some locales.
25+
* Fixes a bug where notices were not appearing in the block editor, throwing console errors, with some locales.
2626
* Fixes a bug where translations where missing in the buttons and the notices in the Block Editor. Props to @petitphp.
27-
* Fixes a bug where using regular expressions in "Do not copy these fields" would not work as expected. Props to @ikuno9233.
27+
* Fixes a bug where using regular expressions in "Do not copy these fields" were not working as expected. Props to @ikuno9233.
2828

2929
#### Other
3030

3131
* Improves security of the Bulk Clone action and the republishing of a copy.
3232
* Adds `duplicate_post_before_republish` and `duplicate_post_after_republish` action hooks fired before and after republishing. Props to @piscis.
3333
* Deprecates the `dp_duplicate_post` and `dp_duplicate_page` hooks and introduces a new unified `duplicate_post_after_duplicated` action hook that replaces them. The new hook includes the post type as a fourth parameter for flexible filtering.
3434
* Sets the minimum supported WordPress version to 6.8.
35+
* Verified compatibility with PHP up to version 8.5.
3536
* Sets the WordPress tested up to version to 6.9.
3637
* Drops compatibility with PHP < 7.4.
37-
* Verified compatibility with PHP up to version 8.5.
3838
* Fixes the Developer Guide link that was leading to a non-existent page. Props to @masteradhoc.
3939
* Fixes the documentation link to use a shortlink. Props to @masteradhoc.
4040
* Improves how the translations are loaded by relying on the WordPress mechanism for that. Props to @swissspidy.

0 commit comments

Comments
 (0)