-
Notifications
You must be signed in to change notification settings - Fork 257
/
Copy pathgenerate_changelog.sh
executable file
·79 lines (70 loc) · 2.23 KB
/
generate_changelog.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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
#!/bin/bash
# Copyright 2020 Google Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
set -e
set -u
function printChangelog() {
local TITLE=$1
shift
# Skip the sentinel value.
local ENTRIES=("${@:2}")
if [ ${#ENTRIES[@]} -ne 0 ]; then
echo "### ${TITLE}"
echo ""
for ((i = 0; i < ${#ENTRIES[@]}; i++))
do
echo "* ${ENTRIES[$i]}"
done
echo ""
fi
}
if [[ -z "${GITHUB_SHA}" ]]; then
GITHUB_SHA="HEAD"
fi
LAST_TAG=`git describe --tags $(git rev-list --tags --max-count=1) 2> /dev/null` || true
if [[ -z "${LAST_TAG}" ]]; then
echo "[INFO] No tags found. Including all commits up to ${GITHUB_SHA}."
VERSION_RANGE="${GITHUB_SHA}"
else
echo "[INFO] Last release tag: ${LAST_TAG}."
COMMIT_SHA=`git show-ref -s ${LAST_TAG}`
echo "[INFO] Last release commit: ${COMMIT_SHA}."
VERSION_RANGE="${COMMIT_SHA}..${GITHUB_SHA}"
echo "[INFO] Including all commits in the range ${VERSION_RANGE}."
fi
echo ""
# Older versions of Bash (< 4.4) treat empty arrays as unbound variables, which triggers
# errors when referencing them. Therefore we initialize each of these arrays with an empty
# sentinel value, and later skip them.
CHANGES=("")
FIXES=("")
FEATS=("")
MISC=("")
while read -r line
do
COMMIT_MSG=`echo ${line} | cut -d ' ' -f 2-`
if [[ $COMMIT_MSG =~ ^change(\(.*\))?: ]]; then
CHANGES+=("$COMMIT_MSG")
elif [[ $COMMIT_MSG =~ ^fix(\(.*\))?: ]]; then
FIXES+=("$COMMIT_MSG")
elif [[ $COMMIT_MSG =~ ^feat(\(.*\))?: ]]; then
FEATS+=("$COMMIT_MSG")
else
MISC+=("${COMMIT_MSG}")
fi
done < <(git log ${VERSION_RANGE} --oneline)
printChangelog "Breaking Changes" "${CHANGES[@]}"
printChangelog "New Features" "${FEATS[@]}"
printChangelog "Bug Fixes" "${FIXES[@]}"
printChangelog "Miscellaneous" "${MISC[@]}"