forked from cloudendpoints/esp
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathrelease-changelog
executable file
·149 lines (121 loc) · 4.9 KB
/
release-changelog
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
#!/bin/bash
#
# Copyright (C) Extensible Service Proxy Authors
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
# are met:
# 1. Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
# 2. Redistributions in binary form must reproduce the above copyright
# notice, this list of conditions and the following disclaimer in the
# documentation and/or other materials provided with the distribution.
#
# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
# SUCH DAMAGE.
#
################################################################################
#
ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
. ${ROOT}/script/all-utilities || { echo "Cannot load Bash utilities"; exit 1; }
# This script will generate changelog from last commit to {SHA}
# You can use either tag or SHA to specify last commmit.
function usage() {
[[ -n "${1}" ]] && echo "${1}"
cat <<EOF
usage: ${BASH_SOURCE[0]} -s <commit sha> -l <last release sha or tag> -d <directory>
Generates changelog for changes between last release and current release.
EOF
exit 1
}
function push_tool() {
echo "Push directory "
pushd ${1}
}
function pop_tool() {
popd
}
SHA=""
LAST_COMMIT=""
DIRECTORY="."
while getopts :s:l:d: arg; do
case ${arg} in
s) SHA="${OPTARG}";;
l) LAST_COMMIT="${OPTARG}";;
d) DIRECTORY="${OPTARG}";;
*) usage "Invalid option: -${OPTARG}";;
esac
done
[[ -n "${SHA}" ]] || usage "Must provide commit sha via '-s' parameter."
[[ "${SHA}" =~ ^[0-9a-f]{40}$ ]] || usage "Invalid SHA: ${SHA}."
[[ -n "${LAST_COMMIT}" ]] || usage "Must provide last commit sha or tag via '-l' parameter."
if [ "${DIRECTORY}" != "." ]; then
push_tool ${DIRECTORY}
fi
VERSION=$(command cat ${ROOT}/src/nginx/version)
echo $(pwd)
echo "The change logs from last commit: ${LAST_COMMIT}"
echo "To SHA: ${SHA}"
echo "In directory: ${DIRECTORY}"
echo "Please copy this result to the release bug."
CHANGELOG="$(mktemp)"
trap "rm '${CHANGELOG}'" EXIT
cat <<EOF > "${CHANGELOG}"
# Release ${VERSION} $(date +%d-%m-%Y)
TODO: Edit the section below before submitting! DIRECTORY ${PWD}
===============================================
EOF
# List all commits since the last release and perform basic processing
# for release notes.
#
# git log --pretty format outputs an asterisk, commit subject (%s),
# newline (%n) and body (%b) indented by 2 spaces and re-wrapped to 76
# columns which is a git log default (%w(76,2)).
#
# The perl command strips the Change-Id line and surrounding whitespace.
# -p: assumes "while (<>) { ... }" loop around program and prints
# the line also, like sed.
# -e: takes a single line of Perl program
#
# BEGIN {undef $/;} enables 'slurp' mode on input. Perl special variable
# $/ means input record separator (newline by default) so we reset it
# to undef so Perl reads all input in order to process multi-line regex
# matching (http://perldoc.perl.org/perlvar.html).
#
# `s/\s+Change-Id:[^\n]*\s+/\n/gs` replaces Change-Id lines surrounded by
# whitespace with a single line so they don't need to be manually removed
# from the generated changelog.
echo $(pwd)
git log ${LAST_COMMIT}..${SHA} --pretty="- %s%n%w(76,2)" \
| perl -pe'BEGIN {undef $/;} s/\s+Change-Id:[^\n]*\s+/\n/gs;' \
>> "${CHANGELOG}"
cat <<EOF >> "${CHANGELOG}"
TODO: Edit the section above before submitting! DIRECTORY ${PWD}
===============================================
EOF
if [[ -f "${ROOT}/CHANGELOG.md" ]]; then
cat "${ROOT}/CHANGELOG.md" >> "${CHANGELOG}"
fi
cp "${CHANGELOG}" "${ROOT}/CHANGELOG.md"
git log ${LAST_COMMIT}..${SHA} --pretty=oneline
printf '\e[31m
***************************************************************************
* Please paste the script output verbatim into the release bug. *
* *
* Edit /CHANGELOG.md to summarize the changes in the release, *
* send for review and submit to the release branch. *
***************************************************************************
\e[0m'
if [ "${DIRECTORY}" != "." ]; then
pop_tool
fi