forked from open-policy-agent/opa
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlatest-release-notes.sh
executable file
·61 lines (48 loc) · 1.21 KB
/
latest-release-notes.sh
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
#!/usr/bin/env bash
set -e
OPA_DIR=$(dirname "${BASH_SOURCE}")/..
CHANGELOG="${OPA_DIR}/CHANGELOG.md"
usage() {
echo "latest-release-notes.sh --output=<path>"
}
OUTPUT=""
for i in "$@"; do
case $i in
--output=*)
OUTPUT="${i#*=}"
shift
;;
*)
usage
exit 1
;;
esac
done
if [ -z "${OUTPUT}" ]; then
usage
exit 1
fi
# Versions start with a h2 (## <semver>), find the latest two for start and stop
# positions in the CHANGELOG
LATEST_VERSION=$(grep '## [0-9]' "${CHANGELOG}" | head -n 1)
STOP_VERSION=$(grep '## [0-9]' "${CHANGELOG}" | head -n 2 | tail -n 1)
STARTED=false
while IFS= read -r line
do
# Skip lines until the first version header is found
if [[ "${STARTED}" == false ]]; then
if [[ "${line}" == "${LATEST_VERSION}" ]]; then
STARTED=true
fi
continue
fi
# Stop reading after we see the stopping point
if [[ "${line}" == "${STOP_VERSION}" ]]; then
break
fi
# Append each line between the two onto the release notes
echo -e "${line}" >> "${OUTPUT}"
done < "${CHANGELOG}"
# Delete all leading blank lines at top of file
sed -i.bak '/./,$!d' "${OUTPUT}"
rm "${OUTPUT}.bak"