Skip to content

Commit 5e58e9d

Browse files
Copilotbrunoborges
andcommitted
feat: add CHANGELOG update script and integrate into release workflow
Co-authored-by: brunoborges <129743+brunoborges@users.noreply.github.com>
1 parent 392c6ef commit 5e58e9d

File tree

2 files changed

+96
-1
lines changed

2 files changed

+96
-1
lines changed
Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
#!/bin/bash
2+
set -e
3+
4+
# Script to update CHANGELOG.md during release process
5+
# Usage: ./update-changelog.sh <version>
6+
# Example: ./update-changelog.sh 1.0.8
7+
8+
if [ -z "$1" ]; then
9+
echo "Error: Version argument required"
10+
echo "Usage: $0 <version>"
11+
exit 1
12+
fi
13+
14+
VERSION="$1"
15+
CHANGELOG_FILE="CHANGELOG.md"
16+
RELEASE_DATE=$(date +%Y-%m-%d)
17+
18+
echo "Updating CHANGELOG.md for version ${VERSION} (${RELEASE_DATE})"
19+
20+
# Check if CHANGELOG.md exists
21+
if [ ! -f "$CHANGELOG_FILE" ]; then
22+
echo "Error: CHANGELOG.md not found"
23+
exit 1
24+
fi
25+
26+
# Check if there's an [Unreleased] section
27+
if ! grep -q "## \[Unreleased\]" "$CHANGELOG_FILE"; then
28+
echo "Error: No [Unreleased] section found in CHANGELOG.md"
29+
exit 1
30+
fi
31+
32+
# Create a temporary file
33+
TEMP_FILE=$(mktemp)
34+
35+
# Process the CHANGELOG
36+
awk -v version="$VERSION" -v date="$RELEASE_DATE" '
37+
BEGIN {
38+
unreleased_found = 0
39+
content_found = 0
40+
links_section = 0
41+
first_version_link = ""
42+
}
43+
44+
# Track if we are in the links section at the bottom
45+
/^\[/ {
46+
links_section = 1
47+
}
48+
49+
# Replace [Unreleased] with the version and date
50+
/^## \[Unreleased\]/ {
51+
if (!unreleased_found) {
52+
print "## [Unreleased]"
53+
print ""
54+
print "## [" version "] - " date
55+
unreleased_found = 1
56+
next
57+
}
58+
}
59+
60+
# Capture the first version link to get the previous version
61+
links_section && first_version_link == "" && /^\[[0-9]+\.[0-9]+\.[0-9]+\]:/ {
62+
match($0, /\[([0-9]+\.[0-9]+\.[0-9]+)\]:/, arr)
63+
if (arr[1] != "") {
64+
first_version_link = arr[1]
65+
# Insert Unreleased and new version links before first version link
66+
print "[Unreleased]: https://github.com/copilot-community-sdk/copilot-sdk-java/compare/v" version "...HEAD"
67+
print "[" version "]: https://github.com/copilot-community-sdk/copilot-sdk-java/compare/v" arr[1] "...v" version
68+
}
69+
}
70+
71+
# Update existing [Unreleased] link if present
72+
links_section && /^\[Unreleased\]:/ {
73+
# Get the previous version from the existing link
74+
match($0, /v([0-9]+\.[0-9]+\.[0-9]+)\.\.\.HEAD/, arr)
75+
if (arr[1] != "") {
76+
print "[Unreleased]: https://github.com/copilot-community-sdk/copilot-sdk-java/compare/v" version "...HEAD"
77+
print "[" version "]: https://github.com/copilot-community-sdk/copilot-sdk-java/compare/v" arr[1] "...v" version
78+
next
79+
}
80+
}
81+
82+
# Print all other lines unchanged
83+
{ print }
84+
' "$CHANGELOG_FILE" > "$TEMP_FILE"
85+
86+
# Replace the original file
87+
mv "$TEMP_FILE" "$CHANGELOG_FILE"
88+
89+
echo "✓ CHANGELOG.md updated successfully"
90+
echo " - Added version ${VERSION} with date ${RELEASE_DATE}"
91+
echo " - Created new [Unreleased] section"
92+
echo " - Updated version comparison links"

.github/workflows/publish-maven.yml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,9 @@ jobs:
9797
run: |
9898
VERSION="${{ steps.versions.outputs.release_version }}"
9999
100+
# Update CHANGELOG.md with release version
101+
./.github/scripts/update-changelog.sh "${VERSION}"
102+
100103
# Update version in README.md
101104
sed -i "s|<version>[0-9]*\.[0-9]*\.[0-9]*</version>|<version>${VERSION}</version>|g" README.md
102105
sed -i "s|copilot-sdk:[0-9]*\.[0-9]*\.[0-9]*|copilot-sdk:${VERSION}|g" README.md
@@ -105,7 +108,7 @@ jobs:
105108
sed -i "s|copilot-sdk:[0-9]*\.[0-9]*\.[0-9]*|copilot-sdk:${VERSION}|g" jbang-example.java
106109
107110
# Commit the documentation changes before release:prepare (requires clean working directory)
108-
git add README.md jbang-example.java
111+
git add CHANGELOG.md README.md jbang-example.java
109112
git commit -m "docs: update version references to ${VERSION}"
110113
111114
# Save the commit SHA for potential rollback

0 commit comments

Comments
 (0)