blob: 848d8d08f1e8a89273b3e632213828a22a63f800 [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 Tarreau96d53682021-01-06 15:46:33 +010013USAGE="Usage: ${0##*/} [-f] [-p] [-b branch] [-d date] [-o oldver] [-n newver]
Willy Tarreau0c612932021-01-06 15:16:46 +010014 -f: force to overwrite existing files and ignore local changes
Thayne McCombs478e5dd2021-01-07 21:36:27 -070015 -p: prepare future release (skip branch and tags existence checks)
Willy Tarreau0c612932021-01-06 15:16:46 +010016 -b: force the project branch name to this (def: inherited from the version)
17 -d: force the release date (e.g. to rework a failed announce)
18 -o: previous version (def: newver-1)
19 -n: new version (if not last tag)
20"
21PREPARE=
Willy Tarreau38234082020-02-07 08:11:45 +010022FORCE=
Willy Tarreau62b71ee2016-05-10 12:04:13 +020023OUTPUT=
24BRANCH=
25HTML=
26DATE=
27YEAR=
28OLD=
Willy Tarreau0c612932021-01-06 15:16:46 +010029LASTCOM=
30NEWVER=
31NEWTAG=
Willy Tarreau62b71ee2016-05-10 12:04:13 +020032DIR=
33
34die() {
35 [ "$#" -eq 0 ] || echo "$*" >&2
36 exit 1
37}
38
39err() {
40 echo "$*" >&2
41}
42
43quit() {
44 [ "$#" -eq 0 ] || echo "$*"
45 exit 0
46}
47
48while [ -n "$1" -a -z "${1##-*}" ]; do
49 case "$1" in
50 -d) DATE="$2" ; shift 2 ;;
51 -b) BRANCH="$2" ; shift 2 ;;
Willy Tarreau38234082020-02-07 08:11:45 +010052 -f) FORCE=1 ; shift ;;
Willy Tarreau96d53682021-01-06 15:46:33 +010053 -p) PREPARE=1 ; shift ;;
Willy Tarreau62b71ee2016-05-10 12:04:13 +020054 -o) OLD="$2" ; shift 2 ;;
Willy Tarreau0c612932021-01-06 15:16:46 +010055 -n) NEWVER="$2" ; shift 2 ;;
Willy Tarreau62b71ee2016-05-10 12:04:13 +020056 -h|--help) quit "$USAGE" ;;
57 *) die "$USAGE" ;;
58 esac
59done
60
61if [ $# -gt 0 ]; then
62 die "$USAGE"
63fi
64
65if ! git rev-parse --verify -q HEAD >/dev/null; then
66 die "Failed to check git HEAD."
67fi
68
69# we want to go to the git root dir
70DIR="$PWD"
71cd $(git rev-parse --show-toplevel)
72
Willy Tarreau0c612932021-01-06 15:16:46 +010073if [ -z "$FORCE" -a "$(git diff HEAD|wc -c)" != 0 ]; then
74 err "You appear to have uncommitted local changes, please commit them first :"
75 git status -s -uno >&2
76 die
77fi
78
Willy Tarreau96d53682021-01-06 15:46:33 +010079if [ -z "$PREPARE" -a "$(git rev-parse --verify -q HEAD)" != "$(git rev-parse --verify -q master)" ]; then
Willy Tarreau62b71ee2016-05-10 12:04:13 +020080 die "git HEAD doesn't match master branch."
81fi
82
Willy Tarreau0c612932021-01-06 15:16:46 +010083if [ -n "$NEWVER" ]; then
84 if git show-ref --tags "v$NEWVER" >/dev/null; then
85 NEWTAG="v$NEWVER"
86 else
87 echo "Note: no matching tag v$NEWVER, using HEAD".
88 fi
Willy Tarreau62b71ee2016-05-10 12:04:13 +020089fi
90
Willy Tarreau0c612932021-01-06 15:16:46 +010091# version unspecified or no existing tag for it
92if [ -z "$NEWTAG" ]; then
93 NEWTAG="$(git describe --tags HEAD --abbrev=0)"
94
95 if [ -z "$NEWTAG" ]; then
Willy Tarreau62b71ee2016-05-10 12:04:13 +020096 die "Fatal: cannot determine new version, please specify it."
Willy Tarreau96d53682021-01-06 15:46:33 +010097 elif [ -n "$PREPARE" ] && ! git show-ref --tags HEAD >/dev/null; then
98 # HEAD not tagged, hence we have to pretend we're on one version
99 # after the current tag
100 echo "Current version not tagged, trying to determine next one."
101 NEWTAG="${NEWTAG#v}"
102 if [ -z "$OLD" ]; then
103 OLD="$NEWTAG"
104 fi
105 radix="$NEWTAG"
106 while [ -n "$radix" -a -z "${radix%%*[0-9]}" ]; do
107 radix="${radix%[0-9]}"
108 done
Willy Tarreau0c612932021-01-06 15:16:46 +0100109
Willy Tarreau96d53682021-01-06 15:46:33 +0100110 number=${NEWTAG#$radix}
111 if [ -z "$number" -o "$radix" = "$NEWTAG" ]; then
112 die "Fatal: cannot determine new version, please specify it."
113 fi
114 NEWTAG="${radix}$((number+1))"
115 if [ -z "$NEWVER" ]; then
116 NEWVER="${NEWTAG}"
117 fi
118 NEWTAG="v$NEWTAG"
119 LASTCOM="$(git rev-parse --short HEAD)"
120 echo "Next version expected to be $NEWVER and next tag $NEWTAG based on commit $LASTCOM"
Willy Tarreau0c612932021-01-06 15:16:46 +0100121 elif [ "$(git describe --tags HEAD)" != "$NEWTAG" ]; then
122 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 +0200123 fi
Willy Tarreau0c612932021-01-06 15:16:46 +0100124elif ! git show-ref --tags "$NEWTAG" >/dev/null 2>&1; then
125 die "git tag $NEWTAG doesn't exist, did you create the release ?"
126fi
127
128if [ -z "$NEWVER" ]; then
129 NEWVER="${NEWTAG#v}"
Willy Tarreau62b71ee2016-05-10 12:04:13 +0200130fi
131
Willy Tarreau0c612932021-01-06 15:16:46 +0100132if [ -z "$LASTCOM" ]; then
133 LASTCOM="$(git rev-parse --short ${NEWTAG}^)"
Willy Tarreau62b71ee2016-05-10 12:04:13 +0200134fi
135
136if [ -z "$OLD" ]; then
Willy Tarreau0c612932021-01-06 15:16:46 +0100137 OLD="$(git describe --tags ${LASTCOM} --abbrev=0)"
Willy Tarreau62b71ee2016-05-10 12:04:13 +0200138 OLD="${OLD#v}"
139fi
140
141if ! git rev-parse --verify -q "v$OLD" >/dev/null; then
142 die "git tag v$OLD doesn't exist."
143fi
144
145# determine the product branch from the new release
146if [ -z "$BRANCH" ]; then
Willy Tarreau0c612932021-01-06 15:16:46 +0100147 subvers=${NEWVER#[0-9]*.[0-9]*[-.]*[0-9].}
148 [ "${subvers}" = "${NEWVER}" ] && subvers=""
149 major=${NEWVER%.$subvers}
Willy Tarreau62b71ee2016-05-10 12:04:13 +0200150 branch_ext=${major#*[0-9].*[0-9]}
151 BRANCH=${major%${branch_ext}}
152fi
153
154# determine the release date
155if [ -z "$DATE" ]; then
Willy Tarreau0c612932021-01-06 15:16:46 +0100156 DATE="$(git log -1 --pretty=fuller ${NEWTAG} 2>/dev/null | sed -ne '/^CommitDate:/{s/\(^[^ ]*:\)\|\( [-+].*\)//gp;q}')"
Willy Tarreau62b71ee2016-05-10 12:04:13 +0200157 DATE="$(date +%Y/%m/%d -d "$DATE")"
158fi
159YEAR="${DATE%%/*}"
160
Willy Tarreau0c612932021-01-06 15:16:46 +0100161OUTPUT="$DIR/mail-haproxy-$NEWVER.txt"
162HTML="$DIR/web-haproxy-$NEWVER.html"
Willy Tarreau38234082020-02-07 08:11:45 +0100163
164[ -z "$FORCE" ] || rm -f "${OUTPUT}" "${HTML}"
165
Willy Tarreau62b71ee2016-05-10 12:04:13 +0200166if [ -e "$OUTPUT" ]; then
Willy Tarreau38234082020-02-07 08:11:45 +0100167 die "${OUTPUT##*/} already exists, please remove it or retry with -f."
Willy Tarreau62b71ee2016-05-10 12:04:13 +0200168fi
169
Willy Tarreau62b71ee2016-05-10 12:04:13 +0200170if [ -e "$HTML" ]; then
Willy Tarreau38234082020-02-07 08:11:45 +0100171 die "$HTML already exists, please remove it or retry with -f."
Willy Tarreau62b71ee2016-05-10 12:04:13 +0200172fi
173
Willy Tarreau0f5ce602020-02-07 08:10:06 +0100174(
175 echo "# Send this using:"
Willy Tarreau0c612932021-01-06 15:16:46 +0100176 echo "# mutt -H <(tail -n +4 ${OUTPUT##*/}) -s \"[ANNOUNCE] haproxy-$NEWVER\" haproxy@formilux.org"
Willy Tarreau0f5ce602020-02-07 08:10:06 +0100177) >> "$OUTPUT"
178
179(echo
Willy Tarreau62b71ee2016-05-10 12:04:13 +0200180 echo "Hi,"
181 echo
Willy Tarreau0c612932021-01-06 15:16:46 +0100182 echo -n "HAProxy $NEWVER was released on $DATE. It added "
183 echo -n $(git log --oneline --reverse --format="%s" "v$OLD".."$LASTCOM" | wc -l)
Willy Tarreau62b71ee2016-05-10 12:04:13 +0200184 echo " new commits"
185 echo "after version $OLD."
186 echo
187 echo "- per tag :"
Willy Tarreau0c612932021-01-06 15:16:46 +0100188 git log --oneline --reverse --format="%s" "v$OLD".."$LASTCOM" | cut -f1 -d':' | sort | uniq -c
Willy Tarreau62b71ee2016-05-10 12:04:13 +0200189 echo
190 echo "major commits :"
Willy Tarreau0c612932021-01-06 15:16:46 +0100191 git log --oneline --reverse --format=" - %s" "v$OLD".."$LASTCOM" | grep MAJOR
Willy Tarreau62b71ee2016-05-10 12:04:13 +0200192 echo
193 echo "- per file :"
Willy Tarreau0c612932021-01-06 15:16:46 +0100194 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 +0200195 echo
196 echo "- per topic :"
Willy Tarreau0c612932021-01-06 15:16:46 +0100197 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 +0200198 echo
199 echo "- sorted changelog :"
Willy Tarreau0c612932021-01-06 15:16:46 +0100200 git log --oneline --reverse --format="%s" "v$OLD".."$LASTCOM" | sort
Willy Tarreau62b71ee2016-05-10 12:04:13 +0200201 echo
202 echo "#############################################################################################"
203) >> "$OUTPUT"
204
205# report the download paths
Willy Tarreau0c612932021-01-06 15:16:46 +0100206if [ -z "${NEWVER##*-dev*}" ]; then
Willy Tarreau62b71ee2016-05-10 12:04:13 +0200207 gitdir="haproxy.git"
208else
209 gitdir="haproxy-$BRANCH.git"
210fi
211
212(echo "Please find the usual URLs below :"
Willy Tarreau68b3e132022-09-17 12:17:07 +0200213 echo " Site index : https://www.haproxy.org/"
214 echo " Documentation : https://docs.haproxy.org/"
Willy Tarreauf0089d82022-04-16 07:57:15 +0200215 echo " Wiki : https://github.com/haproxy/wiki/wiki"
Willy Tarreau68b3e132022-09-17 12:17:07 +0200216 echo " Discourse : https://discourse.haproxy.org/"
Willy Tarreaud6cad122018-12-19 18:59:51 +0100217 echo " Slack channel : https://slack.haproxy.org/"
Willy Tarreau9589c3b2019-01-29 06:51:16 +0100218 echo " Issue tracker : https://github.com/haproxy/haproxy/issues"
Willy Tarreau68b3e132022-09-17 12:17:07 +0200219 echo " Sources : https://www.haproxy.org/download/${BRANCH}/src/"
220 echo " Git repository : https://git.haproxy.org/git/${gitdir}/"
221 echo " Git Web browsing : https://git.haproxy.org/?p=${gitdir}"
222 echo " Changelog : https://www.haproxy.org/download/${BRANCH}/src/CHANGELOG"
223 echo " Pending bugs : https://www.haproxy.org/l/pending-bugs"
224 echo " Reviewed bugs : https://www.haproxy.org/l/reviewed-bugs"
225 echo " Code reports : https://www.haproxy.org/l/code-reports"
226 echo " Latest builds : https://www.haproxy.org/l/dev-packages"
Willy Tarreau62b71ee2016-05-10 12:04:13 +0200227) >> "$OUTPUT"
228
229# sign
230(echo
231 echo "${GIT_COMMITTER_NAME% *}"
232) >> "$OUTPUT"
233
234(echo "---"
235 echo "Complete changelog :"
Willy Tarreau0c612932021-01-06 15:16:46 +0100236 git shortlog "v$OLD".."$LASTCOM"
Willy Tarreau62b71ee2016-05-10 12:04:13 +0200237 echo "---"
238) >> "$OUTPUT"
239
240
241# prepare the HTML update
242set -- $(date +%e -d "$DATE")
243case "$1" in
244 11|12|13) day="${1}th" ;;
245 *1) day="${1}st" ;;
246 *2) day="${2}nd" ;;
247 *3) day="${1}rd" ;;
248 *) day="${1}th" ;;
249esac
250
251humandate=$(date "+%B, $day, %Y" -d "$DATE")
Willy Tarreau0c612932021-01-06 15:16:46 +0100252(echo "$humandate</b> : <i>$NEWVER</i>"
Willy Tarreau62b71ee2016-05-10 12:04:13 +0200253 echo " <p>"
254 echo " <ul>"
255 echo "<--------------------------- edit contents below --------------------------->"
256 echo "- per tag :"
Willy Tarreau0c612932021-01-06 15:16:46 +0100257 git log --oneline --reverse --format="%s" "v$OLD".."$LASTCOM" | cut -f1 -d':' | sort | uniq -c
Willy Tarreau62b71ee2016-05-10 12:04:13 +0200258 echo
259 echo "- per topic :"
Willy Tarreau0c612932021-01-06 15:16:46 +0100260 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 +0200261 echo
262 echo "major commits :"
Willy Tarreau0c612932021-01-06 15:16:46 +0100263 git log --oneline --reverse --format=" - %s" "v$OLD".."$LASTCOM" | grep MAJOR
Willy Tarreau62b71ee2016-05-10 12:04:13 +0200264 echo
265 echo "<--------------------------------------------------------------------------->"
266 echo " Code and changelog are available <a href=\"/download/${BRANCH}/src/\">here</a> as usual."
267 echo " </ul>"
268 echo " <p>"
269 echo " <b>"
270) >> "$HTML"
271
272echo "The announce was emitted into file $OUTPUT."
273echo "You can edit it and send it this way :"
274echo
Willy Tarreau0c612932021-01-06 15:16:46 +0100275echo " mutt -H <(tail -n +4 ${OUTPUT##*/}) -s \"[ANNOUNCE] haproxy-$NEWVER\" haproxy@formilux.org"
Willy Tarreau62b71ee2016-05-10 12:04:13 +0200276echo
277echo "The HTML block was emitted into $HTML and needs to be finished by hand."
278echo