-
Notifications
You must be signed in to change notification settings - Fork 192
Expand file tree
/
Copy pathextract-release-notes.sh
More file actions
executable file
·44 lines (38 loc) · 1.23 KB
/
extract-release-notes.sh
File metadata and controls
executable file
·44 lines (38 loc) · 1.23 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
#!/usr/bin/env bash
# Extract release notes for a given version from the ChangeLog.
# Usage: extract-release-notes.sh [VERSION]
# If VERSION is omitted, extracts the first (most recent) section.
set -euo pipefail
VERSION="${1:-}"
# Strip leading 'v' if present
VERSION="${VERSION#v}"
CHANGELOG="${CHANGELOG:-ChangeLog}"
if [ ! -f "$CHANGELOG" ]; then
echo "Error: $CHANGELOG not found" >&2
exit 1
fi
if [ -z "$VERSION" ]; then
# Extract the first version section (everything between the first and second headers)
awk '
/^Version [0-9]+\.[0-9]+\.[0-9]+/ {
if (found) exit
found = 1
next
}
found && /^$/ && !started { next }
found { started = 1; print }
' "$CHANGELOG" | sed -e :a -e '/^[[:space:]]*$/{ $d; N; ba; }'
else
# Extract notes for the specific version
awk -v ver="$VERSION" '
/^Version [0-9]+\.[0-9]+\.[0-9]+/ {
if (found) exit
if (index($0, "Version " ver " ") == 1 || $0 == "Version " ver) {
found = 1
next
}
}
found && /^$/ && !started { next }
found { started = 1; print }
' "$CHANGELOG" | sed -e :a -e '/^[[:space:]]*$/{ $d; N; ba; }'
fi