-
-
Notifications
You must be signed in to change notification settings - Fork 115
Expand file tree
/
Copy pathconvert-release-notes.sh
More file actions
executable file
·218 lines (184 loc) · 5.42 KB
/
convert-release-notes.sh
File metadata and controls
executable file
·218 lines (184 loc) · 5.42 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
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
#!/usr/bin/env bash
set -e
SCRIPTNAME=$0
# SCRIPTPATH=$(dirname "$0")
VERSION=""
RELNOTES_FILE=doc/RELNOTES
PRINT_EMAIL=false
PRINT_YAML=false
RC=""
usage() {
cat >&2 <<EOF
Usage: $SCRIPTNAME [options] [<version>]
Convert the RELNOTES file format to the different text formats used in
e-mail/GitHub/git-tags/website.
<version> Specify the version to extract from RELNOTES. Defaults to
the top-most version in the file.
-e, --email Generate an email header before the release notes.
-r <num>, --rc <num> Use this release candidate in generated text.
-y, --yaml Convert to yaml output for website nsd_releases.yml file.
-f, --file Specify the file to read. Defaults to "$RELNOTES_FILE".
Examples:
Latest release: $SCRIPTNAME
Specific release: $SCRIPTNAME 4.12.0
Release candidate: $SCRIPTNAME -r 1 4.12.0
EOF
}
error_unknown_option() {
echo "Unknown option: $1" >&2
usage && exit 1
}
error_too_many_args() {
echo "Too many arguments found: $1" >&2
usage && exit 1
}
extract_release_notes() {
# Find latest version if VERSION was not specified
if [[ -z "$VERSION" ]]; then
VERSION=$(grep -E -m1 -B1 "^=====+$" <"$RELNOTES_FILE" | head -n1)
fi
sed -E -e "/^$VERSION/{ n; n; bfound }; d; bend" \
-e ':found; /\n=====+$/bstrip_trailer; N; bfound' \
-e ':strip_trailer; s/\n+([0-9]+\.[0-9]+\.[0-9]+)\n=====+$//' \
-e ':delete_tabs; s/\t+//g' \
-e ':end' "$RELNOTES_FILE"
# grep -En -B1 '^=====+$' "$RELNOTES_FILE" | grep -A3 "$VERSION" | \
# grep -E "^[0-9]+-" | cut -d- -f1 | {
# read -r start
# read -r end
# head -n"$((end-1))" <"$RELNOTES_FILE" | tail -n+"$start" | tr -d "\t"
# }
}
convert_rel_notes_to_yaml() {
local features=()
local bugs=()
local state=none
local -n array_to_add # nameref ("pointer") to features or bugs array
local tmp_item
while read -r; do
local line=$REPLY
# echo ">>> $line"
if grep -qE "^FEATURES:" <<<"$line"; then
state=features
elif grep -qE "^BUG FIXES:" <<<"$line"; then
state=bugs
elif grep -qE "^- " <<<"$line"; then
state=item_start
elif grep -qE "^ " <<<"$line"; then
state=item_continue
else
# skip empty/unknown lines
continue
fi
case "$state" in
features)
# Starting a new section, add last item to previous section
if [[ -R array_to_add && -n "$tmp_item" ]]; then
array_to_add+=("$tmp_item")
tmp_item=""
fi
# shellcheck disable=2178
declare -n array_to_add=features
;;
bugs)
# Starting a new section, add last item to previous section
if [[ -R array_to_add && -n "$tmp_item" ]]; then
array_to_add+=("$tmp_item")
tmp_item=""
fi
# shellcheck disable=2178
declare -n array_to_add=bugs
;;
item_start)
[[ -n "$tmp_item" ]] && array_to_add+=("$tmp_item")
tmp_item=${line#- }
;;
item_continue)
tmp_item+=$'\n'"${line}"
;;
esac
done < <(tail -n+2 <<<"$(extract_release_notes)")
# Finished reading, add completed item to active section
[[ -n "$tmp_item" ]] && array_to_add+=("$tmp_item")
cat <<EOF
---
version: $VERSION
date: $(date "+%d %B, %Y")
EOF
if [[ "${#features[@]}" == 0 ]]; then
echo "features: []"
else
echo "features:"
for f in "${features[@]}"; do
echo "- >-"
echo " $f"
done
fi
if [[ "${#bugs[@]}" == 0 ]]; then
echo "bugs: []"
else
echo "bugs:"
for f in "${bugs[@]}"; do
echo "- >-"
echo " $f"
done
fi
}
#### PARSE ARGUMENTS ####
if [[ "$1" =~ ^-h|--help$ ]]; then
usage && exit
else
until [[ -z "$1" ]]; do
case "$1" in
-e|--email)
PRINT_EMAIL=true
;;
-r|--rc)
RC=rc$2
shift
;;
-y|--yaml)
PRINT_YAML=true
;;
-f|--file)
RELNOTES_FILE=$2
shift
;;
-*)
error_unknown_option "$1"
;;
*)
if [[ -z "$VERSION" ]]; then
VERSION=$1
else
error_too_many_args "$1"
fi
;;
esac
shift
done
fi
if ! [[ -f "$RELNOTES_FILE" ]]; then
echo "$0: $RELNOTES_FILE: No such file or directory" >&2
exit 3
fi
#### Generate text ####
if [[ "$PRINT_EMAIL" == true ]]; then
SHA256=""
if [[ -f "nsd-$VERSION$RC.tar.gz.sha256" ]]; then
SHA256=$(cat "nsd-$VERSION$RC.tar.gz.sha256")
fi
cat <<EOF
Dear all,
NSD $VERSION ${RC:+pre-}release is available:
https://nlnetlabs.nl/downloads/nsd/nsd-$VERSION$RC.tar.gz
sha256 $SHA256
pgp https://nlnetlabs.nl/downloads/nsd/nsd-$VERSION$RC.tar.gz.asc
EOF
fi # END PRINT_EMAIL
if [[ "$PRINT_YAML" == true ]]; then
convert_rel_notes_to_yaml
else
extract_release_notes
fi
# vim: set ts=4 et sw=4: