-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathextract-release-notes.sh
More file actions
executable file
·44 lines (39 loc) · 1.12 KB
/
Copy pathextract-release-notes.sh
File metadata and controls
executable file
·44 lines (39 loc) · 1.12 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
set -euo pipefail
# Print exactly one curated CHANGELOG.md release section. The build workflow
# uses this instead of regenerating notes from commits, so the reviewed
# changelog is the public GitHub Release body.
if [[ $# -lt 1 || $# -gt 2 ]]; then
echo "usage: $0 vX.Y.Z [CHANGELOG.md]" >&2
exit 2
fi
TAG="$1"
VERSION="${TAG#v}"
CHANGELOG="${2:-CHANGELOG.md}"
if [[ ! "$TAG" =~ ^v[0-9]+\.[0-9]+\.[0-9]+([-.][0-9A-Za-z.-]+)?$ ]]; then
echo "invalid release tag: $TAG" >&2
exit 2
fi
awk -v heading="## [$VERSION]" '
/^## \[/ {
suffix = substr($0, length(heading) + 1)
is_target = index($0, heading) == 1 && (suffix == "" || index(suffix, " - ") == 1)
if (is_target) {
matches += 1
capture = 1
} else {
capture = 0
}
}
capture {
lines[++line_count] = $0
if ($0 !~ /^## \[/ && $0 !~ /^[[:space:]]*$/) content_lines += 1
}
END {
if (matches != 1 || content_lines == 0) exit 1
for (i = 1; i <= line_count; i += 1) print lines[i]
}
' "$CHANGELOG" || {
echo "expected exactly one non-empty changelog section for $TAG in $CHANGELOG" >&2
exit 1
}