blob: 385b18f88e23362c3223a5cd08e2900c900316ca [file] [log] [blame]
Willy Tarreaube9b00f2020-02-05 04:45:18 +01001#!/usr/bin/env bash
Willy Tarreau62b71ee2016-05-10 12:04:13 +02002# prepares a template e-mail and HTML file to announce a new release
3# Copyright (c) 2006-2016 Willy Tarreau <w@1wt.eu>
4#
5# In short :
6# - requires git
7# - wants that last commit is a release/tag
8# - no restriction to master, uses last tag
9# - creates mail-$version.txt
10# - creates web-$version.html
11# - indicates how to edit the mail and how to send it
12
Willy Tarreaud1754b62021-01-06 15:16:46 +010013USAGE="Usage: ${0##*/} [-f] [-b branch] [-d date] [-o oldver] [-n newver]
14 -f: force to overwrite existing files and ignore local changes
15 -b: force the project branch name to this (def: inherited from the version)
16 -d: force the release date (e.g. to rework a failed announce)
17 -o: previous version (def: newver-1)
18 -n: new version (if not last tag)
19"
20PREPARE=
Willy Tarreau38234082020-02-07 08:11:45 +010021FORCE=
Willy Tarreau62b71ee2016-05-10 12:04:13 +020022OUTPUT=
23BRANCH=
24HTML=
25DATE=
26YEAR=
27OLD=
Willy Tarreaud1754b62021-01-06 15:16:46 +010028LASTCOM=
29NEWVER=
30NEWTAG=
Willy Tarreau62b71ee2016-05-10 12:04:13 +020031DIR=
32
33die() {
34 [ "$#" -eq 0 ] || echo "$*" >&2
35 exit 1
36}
37
38err() {
39 echo "$*" >&2
40}
41
42quit() {
43 [ "$#" -eq 0 ] || echo "$*"
44 exit 0
45}
46
47while [ -n "$1" -a -z "${1##-*}" ]; do
48 case "$1" in
49 -d) DATE="$2" ; shift 2 ;;
50 -b) BRANCH="$2" ; shift 2 ;;
Willy Tarreau38234082020-02-07 08:11:45 +010051 -f) FORCE=1 ; shift ;;
Willy Tarreau62b71ee2016-05-10 12:04:13 +020052 -o) OLD="$2" ; shift 2 ;;
Willy Tarreaud1754b62021-01-06 15:16:46 +010053 -n) NEWVER="$2" ; shift 2 ;;
Willy Tarreau62b71ee2016-05-10 12:04:13 +020054 -h|--help) quit "$USAGE" ;;
55 *) die "$USAGE" ;;
56 esac
57done
58
59if [ $# -gt 0 ]; then
60 die "$USAGE"
61fi
62
63if ! git rev-parse --verify -q HEAD >/dev/null; then
64 die "Failed to check git HEAD."
65fi
66
67# we want to go to the git root dir
68DIR="$PWD"
69cd $(git rev-parse --show-toplevel)
70
Willy Tarreaud1754b62021-01-06 15:16:46 +010071if [ -z "$FORCE" -a "$(git diff HEAD|wc -c)" != 0 ]; then
72 err "You appear to have uncommitted local changes, please commit them first :"
73 git status -s -uno >&2
74 die
75fi
76
Willy Tarreau62b71ee2016-05-10 12:04:13 +020077if [ "$(git rev-parse --verify -q HEAD)" != "$(git rev-parse --verify -q master)" ]; then
78 die "git HEAD doesn't match master branch."
79fi
80
Willy Tarreaud1754b62021-01-06 15:16:46 +010081if [ -n "$NEWVER" ]; then
82 if git show-ref --tags "v$NEWVER" >/dev/null; then
83 NEWTAG="v$NEWVER"
84 else
85 echo "Note: no matching tag v$NEWVER, using HEAD".
86 fi
Willy Tarreau62b71ee2016-05-10 12:04:13 +020087fi
88
Willy Tarreaud1754b62021-01-06 15:16:46 +010089# version unspecified or no existing tag for it
90if [ -z "$NEWTAG" ]; then
91 NEWTAG="$(git describe --tags HEAD --abbrev=0)"
92
93 if [ -z "$NEWTAG" ]; then
Willy Tarreau62b71ee2016-05-10 12:04:13 +020094 die "Fatal: cannot determine new version, please specify it."
Willy Tarreaud1754b62021-01-06 15:16:46 +010095
96 elif [ "$(git describe --tags HEAD)" != "$NEWTAG" ]; then
97 die "About to use current HEAD which doesn't seem tagged, it reports '$(git describe --tags HEAD 2>/dev/null)'. Did you release it ?"
Willy Tarreau62b71ee2016-05-10 12:04:13 +020098 fi
Willy Tarreaud1754b62021-01-06 15:16:46 +010099elif ! git show-ref --tags "$NEWTAG" >/dev/null 2>&1; then
100 die "git tag $NEWTAG doesn't exist, did you create the release ?"
101fi
102
103if [ -z "$NEWVER" ]; then
104 NEWVER="${NEWTAG#v}"
Willy Tarreau62b71ee2016-05-10 12:04:13 +0200105fi
106
Willy Tarreaud1754b62021-01-06 15:16:46 +0100107if [ -z "$LASTCOM" ]; then
108 LASTCOM="$(git rev-parse --short ${NEWTAG}^)"
Willy Tarreau62b71ee2016-05-10 12:04:13 +0200109fi
110
111if [ -z "$OLD" ]; then
Willy Tarreaud1754b62021-01-06 15:16:46 +0100112 OLD="$(git describe --tags ${LASTCOM} --abbrev=0)"
Willy Tarreau62b71ee2016-05-10 12:04:13 +0200113 OLD="${OLD#v}"
114fi
115
116if ! git rev-parse --verify -q "v$OLD" >/dev/null; then
117 die "git tag v$OLD doesn't exist."
118fi
119
120# determine the product branch from the new release
121if [ -z "$BRANCH" ]; then
Willy Tarreaud1754b62021-01-06 15:16:46 +0100122 subvers=${NEWVER#[0-9]*.[0-9]*[-.]*[0-9].}
123 [ "${subvers}" = "${NEWVER}" ] && subvers=""
124 major=${NEWVER%.$subvers}
Willy Tarreau62b71ee2016-05-10 12:04:13 +0200125 branch_ext=${major#*[0-9].*[0-9]}
126 BRANCH=${major%${branch_ext}}
127fi
128
129# determine the release date
130if [ -z "$DATE" ]; then
Willy Tarreaud1754b62021-01-06 15:16:46 +0100131 DATE="$(git log -1 --pretty=fuller ${NEWTAG} 2>/dev/null | sed -ne '/^CommitDate:/{s/\(^[^ ]*:\)\|\( [-+].*\)//gp;q}')"
Willy Tarreau62b71ee2016-05-10 12:04:13 +0200132 DATE="$(date +%Y/%m/%d -d "$DATE")"
133fi
134YEAR="${DATE%%/*}"
135
Willy Tarreaud1754b62021-01-06 15:16:46 +0100136OUTPUT="$DIR/mail-haproxy-$NEWVER.txt"
137HTML="$DIR/web-haproxy-$NEWVER.html"
Willy Tarreau38234082020-02-07 08:11:45 +0100138
139[ -z "$FORCE" ] || rm -f "${OUTPUT}" "${HTML}"
140
Willy Tarreau62b71ee2016-05-10 12:04:13 +0200141if [ -e "$OUTPUT" ]; then
Willy Tarreau38234082020-02-07 08:11:45 +0100142 die "${OUTPUT##*/} already exists, please remove it or retry with -f."
Willy Tarreau62b71ee2016-05-10 12:04:13 +0200143fi
144
Willy Tarreau62b71ee2016-05-10 12:04:13 +0200145if [ -e "$HTML" ]; then
Willy Tarreau38234082020-02-07 08:11:45 +0100146 die "$HTML already exists, please remove it or retry with -f."
Willy Tarreau62b71ee2016-05-10 12:04:13 +0200147fi
148
Willy Tarreau0f5ce602020-02-07 08:10:06 +0100149(
150 echo "# Send this using:"
Willy Tarreaud1754b62021-01-06 15:16:46 +0100151 echo "# mutt -H <(tail -n +4 ${OUTPUT##*/}) -s \"[ANNOUNCE] haproxy-$NEWVER\" haproxy@formilux.org"
Willy Tarreau0f5ce602020-02-07 08:10:06 +0100152) >> "$OUTPUT"
153
154(echo
Willy Tarreau62b71ee2016-05-10 12:04:13 +0200155 echo "Hi,"
156 echo
Willy Tarreaud1754b62021-01-06 15:16:46 +0100157 echo -n "HAProxy $NEWVER was released on $DATE. It added "
158 echo -n $(git log --oneline --reverse --format="%s" "v$OLD".."$LASTCOM" | wc -l)
Willy Tarreau62b71ee2016-05-10 12:04:13 +0200159 echo " new commits"
160 echo "after version $OLD."
161 echo
162 echo "- per tag :"
Willy Tarreaud1754b62021-01-06 15:16:46 +0100163 git log --oneline --reverse --format="%s" "v$OLD".."$LASTCOM" | cut -f1 -d':' | sort | uniq -c
Willy Tarreau62b71ee2016-05-10 12:04:13 +0200164 echo
165 echo "major commits :"
Willy Tarreaud1754b62021-01-06 15:16:46 +0100166 git log --oneline --reverse --format=" - %s" "v$OLD".."$LASTCOM" | grep MAJOR
Willy Tarreau62b71ee2016-05-10 12:04:13 +0200167 echo
168 echo "- per file :"
Willy Tarreaud1754b62021-01-06 15:16:46 +0100169 git show "v$OLD".."$LASTCOM" -- src/ | grep ^diff | awk '{ print substr($3,7)}' | sort | uniq -c | sort -nr | head -15
Willy Tarreau62b71ee2016-05-10 12:04:13 +0200170 echo
171 echo "- per topic :"
Willy Tarreaud1754b62021-01-06 15:16:46 +0100172 git log --oneline --reverse --format="%s" "v$OLD".."$LASTCOM" | cut -f2 -d':' | awk '{sub("s$","",$1); print $1}' | sort | uniq -c
Willy Tarreau62b71ee2016-05-10 12:04:13 +0200173 echo
174 echo "- sorted changelog :"
Willy Tarreaud1754b62021-01-06 15:16:46 +0100175 git log --oneline --reverse --format="%s" "v$OLD".."$LASTCOM" | sort
Willy Tarreau62b71ee2016-05-10 12:04:13 +0200176 echo
177 echo "#############################################################################################"
178) >> "$OUTPUT"
179
180# report the download paths
Willy Tarreaud1754b62021-01-06 15:16:46 +0100181if [ -z "${NEWVER##*-dev*}" ]; then
Willy Tarreau62b71ee2016-05-10 12:04:13 +0200182 gitdir="haproxy.git"
183else
184 gitdir="haproxy-$BRANCH.git"
185fi
186
187(echo "Please find the usual URLs below :"
188 echo " Site index : http://www.haproxy.org/"
189 echo " Discourse : http://discourse.haproxy.org/"
Willy Tarreaud6cad122018-12-19 18:59:51 +0100190 echo " Slack channel : https://slack.haproxy.org/"
Willy Tarreau9589c3b2019-01-29 06:51:16 +0100191 echo " Issue tracker : https://github.com/haproxy/haproxy/issues"
Willy Tarreaube789df2020-07-30 17:41:42 +0200192 echo " Wiki : https://github.com/haproxy/wiki/wiki"
Willy Tarreau62b71ee2016-05-10 12:04:13 +0200193 echo " Sources : http://www.haproxy.org/download/${BRANCH}/src/"
194 echo " Git repository : http://git.haproxy.org/git/${gitdir}/"
195 echo " Git Web browsing : http://git.haproxy.org/?p=${gitdir}"
196 echo " Changelog : http://www.haproxy.org/download/${BRANCH}/src/CHANGELOG"
197 echo " Cyril's HTML doc : http://cbonte.github.io/haproxy-dconv/"
198) >> "$OUTPUT"
199
200# sign
201(echo
202 echo "${GIT_COMMITTER_NAME% *}"
203) >> "$OUTPUT"
204
205(echo "---"
206 echo "Complete changelog :"
Willy Tarreaud1754b62021-01-06 15:16:46 +0100207 git shortlog "v$OLD".."$LASTCOM"
Willy Tarreau62b71ee2016-05-10 12:04:13 +0200208 echo "---"
209) >> "$OUTPUT"
210
211
212# prepare the HTML update
213set -- $(date +%e -d "$DATE")
214case "$1" in
215 11|12|13) day="${1}th" ;;
216 *1) day="${1}st" ;;
217 *2) day="${2}nd" ;;
218 *3) day="${1}rd" ;;
219 *) day="${1}th" ;;
220esac
221
222humandate=$(date "+%B, $day, %Y" -d "$DATE")
Willy Tarreaud1754b62021-01-06 15:16:46 +0100223(echo "$humandate</b> : <i>$NEWVER</i>"
Willy Tarreau62b71ee2016-05-10 12:04:13 +0200224 echo " <p>"
225 echo " <ul>"
226 echo "<--------------------------- edit contents below --------------------------->"
227 echo "- per tag :"
Willy Tarreaud1754b62021-01-06 15:16:46 +0100228 git log --oneline --reverse --format="%s" "v$OLD".."$LASTCOM" | cut -f1 -d':' | sort | uniq -c
Willy Tarreau62b71ee2016-05-10 12:04:13 +0200229 echo
230 echo "- per topic :"
Willy Tarreaud1754b62021-01-06 15:16:46 +0100231 git log --oneline --reverse --format="%s" "v$OLD".."$LASTCOM" | cut -f2 -d':' | awk '{sub("s$","",$1); print $1}' | sort | uniq -c
Willy Tarreau62b71ee2016-05-10 12:04:13 +0200232 echo
233 echo "major commits :"
Willy Tarreaud1754b62021-01-06 15:16:46 +0100234 git log --oneline --reverse --format=" - %s" "v$OLD".."$LASTCOM" | grep MAJOR
Willy Tarreau62b71ee2016-05-10 12:04:13 +0200235 echo
236 echo "<--------------------------------------------------------------------------->"
237 echo " Code and changelog are available <a href=\"/download/${BRANCH}/src/\">here</a> as usual."
238 echo " </ul>"
239 echo " <p>"
240 echo " <b>"
241) >> "$HTML"
242
243echo "The announce was emitted into file $OUTPUT."
244echo "You can edit it and send it this way :"
245echo
Willy Tarreaud1754b62021-01-06 15:16:46 +0100246echo " mutt -H <(tail -n +4 ${OUTPUT##*/}) -s \"[ANNOUNCE] haproxy-$NEWVER\" haproxy@formilux.org"
Willy Tarreau62b71ee2016-05-10 12:04:13 +0200247echo
248echo "The HTML block was emitted into $HTML and needs to be finished by hand."
249echo