|
8 | 8 | # |
9 | 9 | # Optional environment variables: |
10 | 10 | # 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). |
12 | 12 | # CHANGELOG_FILE - Path to the changelog file (defaults to changelog.md). |
13 | 13 |
|
14 | 14 | set -euo pipefail |
15 | 15 |
|
16 | 16 | VERSION="${VERSION:?VERSION is required}" |
17 | 17 | CHANGELOG_FILE="${CHANGELOG_FILE:-changelog.md}" |
18 | 18 |
|
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). |
24 | 51 | BASE_VERSION=$(echo "$VERSION" | cut -d'-' -f1) |
25 | 52 | PATCH=$(echo "$BASE_VERSION" | awk -F. '{ print ($3 != "" ? $3 : 0) }') |
26 | 53 | SUFFIX=$(echo "$VERSION" | grep -oP '(?<=-).*' || true) |
@@ -120,6 +147,13 @@ SECTION="## $VERSION |
120 | 147 | Release date: $RELEASE_DATE |
121 | 148 | " |
122 | 149 |
|
| 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 | + |
123 | 157 | if [ -n "$ENHANCEMENTS" ]; then |
124 | 158 | SECTION+=" |
125 | 159 | #### Enhancements |
|
0 commit comments