-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathupdate-changelog.sh
More file actions
executable file
·121 lines (104 loc) · 3.9 KB
/
update-changelog.sh
File metadata and controls
executable file
·121 lines (104 loc) · 3.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
#!/bin/bash
set -e
# Script to update CHANGELOG.md during release process
# Usage: ./update-changelog.sh <version> [upstream-hash]
# Example: ./update-changelog.sh 1.0.8
# Example: ./update-changelog.sh 1.0.8 05e3c46c8c23130c9c064dc43d00ec78f7a75eab
if [ -z "$1" ]; then
echo "Error: Version argument required"
echo "Usage: $0 <version> [upstream-hash]"
exit 1
fi
VERSION="$1"
UPSTREAM_HASH="${2:-}"
CHANGELOG_FILE="${CHANGELOG_FILE:-CHANGELOG.md}"
RELEASE_DATE=$(date +%Y-%m-%d)
echo "Updating CHANGELOG.md for version ${VERSION} (${RELEASE_DATE})"
if [ -n "$UPSTREAM_HASH" ]; then
echo " Upstream SDK sync: ${UPSTREAM_HASH:0:7}"
fi
# Check if CHANGELOG.md exists
if [ ! -f "$CHANGELOG_FILE" ]; then
echo "Error: CHANGELOG.md not found"
exit 1
fi
# Check if there's an [Unreleased] section
if ! grep -q "## \[Unreleased\]" "$CHANGELOG_FILE"; then
echo "Error: No [Unreleased] section found in CHANGELOG.md"
exit 1
fi
# Create a temporary file
TEMP_FILE=$(mktemp)
# Process the CHANGELOG
awk -v version="$VERSION" -v date="$RELEASE_DATE" -v upstream_hash="$UPSTREAM_HASH" '
BEGIN {
unreleased_found = 0
content_found = 0
links_section = 0
first_version_link = ""
repo_url = ""
}
# Track if we are in the links section at the bottom
/^\[/ {
links_section = 1
}
# Capture the repository URL from the first version link
links_section && repo_url == "" && /^\[[0-9]+\.[0-9]+\.[0-9]+(-java\.[0-9]+)?\]:/ {
match($0, /(https:\/\/github\.com\/[^\/]+\/[^\/]+)\//, arr)
if (arr[1] != "") {
repo_url = arr[1]
}
}
# Replace [Unreleased] with the version and date
/^## \[Unreleased\]/ {
if (!unreleased_found) {
print "## [Unreleased]"
print ""
if (upstream_hash != "") {
short_hash = substr(upstream_hash, 1, 7)
print "> **Upstream sync:** [`github/copilot-sdk@" short_hash "`](https://github.com/github/copilot-sdk/commit/" upstream_hash ")"
print ""
}
print "## [" version "] - " date
if (upstream_hash != "") {
print ""
print "> **Upstream sync:** [`github/copilot-sdk@" short_hash "`](https://github.com/github/copilot-sdk/commit/" upstream_hash ")"
}
unreleased_found = 1
skip_old_upstream = 1
next
}
}
# Skip the old upstream sync line and surrounding blank lines from the previous [Unreleased] section
skip_old_upstream && /^[[:space:]]*$/ { next }
skip_old_upstream && /^> \*\*Upstream sync:\*\*/ { next }
skip_old_upstream && !/^[[:space:]]*$/ && !/^> \*\*Upstream sync:\*\*/ { skip_old_upstream = 0 }
# Capture the first version link to get the previous version
links_section && first_version_link == "" && /^\[[0-9]+\.[0-9]+\.[0-9]+(-java\.[0-9]+)?\]:/ {
match($0, /\[([0-9]+\.[0-9]+\.[0-9]+(-java\.[0-9]+)?)\]:/, arr)
if (arr[1] != "" && repo_url != "") {
first_version_link = arr[1]
# Insert Unreleased and new version links before first version link
print "[Unreleased]: " repo_url "/compare/v" version "...HEAD"
print "[" version "]: " repo_url "/compare/v" arr[1] "...v" version
}
}
# Update existing [Unreleased] link if present
links_section && /^\[Unreleased\]:/ {
# Get the previous version and repo URL from the existing link
match($0, /(https:\/\/github\.com\/[^\/]+\/[^\/]+)\/compare\/v([0-9]+\.[0-9]+\.[0-9]+(-java\.[0-9]+)?)\.\.\.HEAD/, arr)
if (arr[1] != "" && arr[2] != "") {
print "[Unreleased]: " arr[1] "/compare/v" version "...HEAD"
print "[" version "]: " arr[1] "/compare/v" arr[2] "...v" version
next
}
}
# Print all other lines unchanged
{ print }
' "$CHANGELOG_FILE" > "$TEMP_FILE"
# Replace the original file
mv "$TEMP_FILE" "$CHANGELOG_FILE"
echo "✓ CHANGELOG.md updated successfully"
echo " - Added version ${VERSION} with date ${RELEASE_DATE}"
echo " - Created new [Unreleased] section"
echo " - Updated version comparison links"