blob: 5faab5342f7165cd3095984d6d053f74a98bbe4d [file] [log] [blame]
Willy Tarreau62b71ee2016-05-10 12:04:13 +02001#!/bin/bash
2# 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 Tarreau6848d942021-01-06 15:46:33 +010013USAGE="Usage: ${0##*/} [-f] [-p] [-b branch] [-d date] [-o oldver] [-n newver]
Willy Tarreaudc37f882021-01-06 15:16:46 +010014 -f: force to overwrite existing files and ignore local changes
Willy Tarreau6848d942021-01-06 15:46:33 +010015 -p: prepare future relase (skip branch and tags existence checks)
Willy Tarreaudc37f882021-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 Tarreau7dc322d2020-02-07 08:11:45 +010022FORCE=
Willy Tarreau62b71ee2016-05-10 12:04:13 +020023OUTPUT=
24BRANCH=
25HTML=
26DATE=
27YEAR=
28OLD=
Willy Tarreaudc37f882021-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 Tarreau7dc322d2020-02-07 08:11:45 +010052 -f) FORCE=1 ; shift ;;
Willy Tarreau6848d942021-01-06 15:46:33 +010053 -p) PREPARE=1 ; shift ;;
Willy Tarreau62b71ee2016-05-10 12:04:13 +020054 -o) OLD="$2" ; shift 2 ;;
Willy Tarreaudc37f882021-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 Tarreaudc37f882021-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 Tarreau6848d942021-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 Tarreaudc37f882021-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 Tarreaudc37f882021-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 Tarreau6848d942021-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 Tarreaudc37f882021-01-06 15:16:46 +0100109
Willy Tarreau6848d942021-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 Tarreaudc37f882021-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 Tarreaudc37f882021-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 Tarreaudc37f882021-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 Tarreaudc37f882021-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 Tarreaudc37f882021-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 Tarreaudc37f882021-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 Tarreaudc37f882021-01-06 15:16:46 +0100161OUTPUT="$DIR/mail-haproxy-$NEWVER.txt"
162HTML="$DIR/web-haproxy-$NEWVER.html"
Willy Tarreau7dc322d2020-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 Tarreau7dc322d2020-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 Tarreau7dc322d2020-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 Tarreau84f6dca2020-02-07 08:10:06 +0100174(
175 echo "# Send this using:"
Willy Tarreaudc37f882021-01-06 15:16:46 +0100176 echo "# mutt -H <(tail -n +4 ${OUTPUT##*/}) -s \"[ANNOUNCE] haproxy-$NEWVER\" haproxy@formilux.org"
Willy Tarreau84f6dca2020-02-07 08:10:06 +0100177) >> "$OUTPUT"
178
179(echo
Willy Tarreau62b71ee2016-05-10 12:04:13 +0200180 echo "Hi,"
181 echo
Willy Tarreaudc37f882021-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 Tarreaudc37f882021-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 Tarreaudc37f882021-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 Tarreaudc37f882021-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 Tarreaudc37f882021-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 Tarreaudc37f882021-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 Tarreaudc37f882021-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 :"
213 echo " Site index : http://www.haproxy.org/"
214 echo " Discourse : http://discourse.haproxy.org/"
Willy Tarreaud6cad122018-12-19 18:59:51 +0100215 echo " Slack channel : https://slack.haproxy.org/"
Willy Tarreau9589c3b2019-01-29 06:51:16 +0100216 echo " Issue tracker : https://github.com/haproxy/haproxy/issues"
Willy Tarreau36787f52020-07-30 17:41:42 +0200217 echo " Wiki : https://github.com/haproxy/wiki/wiki"
Willy Tarreau62b71ee2016-05-10 12:04:13 +0200218 echo " Sources : http://www.haproxy.org/download/${BRANCH}/src/"
219 echo " Git repository : http://git.haproxy.org/git/${gitdir}/"
220 echo " Git Web browsing : http://git.haproxy.org/?p=${gitdir}"
221 echo " Changelog : http://www.haproxy.org/download/${BRANCH}/src/CHANGELOG"
222 echo " Cyril's HTML doc : http://cbonte.github.io/haproxy-dconv/"
223) >> "$OUTPUT"
224
225# sign
226(echo
227 echo "${GIT_COMMITTER_NAME% *}"
228) >> "$OUTPUT"
229
230(echo "---"
231 echo "Complete changelog :"
Willy Tarreaudc37f882021-01-06 15:16:46 +0100232 git shortlog "v$OLD".."$LASTCOM"
Willy Tarreau62b71ee2016-05-10 12:04:13 +0200233 echo "---"
234) >> "$OUTPUT"
235
236
237# prepare the HTML update
238set -- $(date +%e -d "$DATE")
239case "$1" in
240 11|12|13) day="${1}th" ;;
241 *1) day="${1}st" ;;
242 *2) day="${2}nd" ;;
243 *3) day="${1}rd" ;;
244 *) day="${1}th" ;;
245esac
246
247humandate=$(date "+%B, $day, %Y" -d "$DATE")
Willy Tarreaudc37f882021-01-06 15:16:46 +0100248(echo "$humandate</b> : <i>$NEWVER</i>"
Willy Tarreau62b71ee2016-05-10 12:04:13 +0200249 echo " <p>"
250 echo " <ul>"
251 echo "<--------------------------- edit contents below --------------------------->"
252 echo "- per tag :"
Willy Tarreaudc37f882021-01-06 15:16:46 +0100253 git log --oneline --reverse --format="%s" "v$OLD".."$LASTCOM" | cut -f1 -d':' | sort | uniq -c
Willy Tarreau62b71ee2016-05-10 12:04:13 +0200254 echo
255 echo "- per topic :"
Willy Tarreaudc37f882021-01-06 15:16:46 +0100256 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 +0200257 echo
258 echo "major commits :"
Willy Tarreaudc37f882021-01-06 15:16:46 +0100259 git log --oneline --reverse --format=" - %s" "v$OLD".."$LASTCOM" | grep MAJOR
Willy Tarreau62b71ee2016-05-10 12:04:13 +0200260 echo
261 echo "<--------------------------------------------------------------------------->"
262 echo " Code and changelog are available <a href=\"/download/${BRANCH}/src/\">here</a> as usual."
263 echo " </ul>"
264 echo " <p>"
265 echo " <b>"
266) >> "$HTML"
267
268echo "The announce was emitted into file $OUTPUT."
269echo "You can edit it and send it this way :"
270echo
Willy Tarreaudc37f882021-01-06 15:16:46 +0100271echo " mutt -H <(tail -n +4 ${OUTPUT##*/}) -s \"[ANNOUNCE] haproxy-$NEWVER\" haproxy@formilux.org"
Willy Tarreau62b71ee2016-05-10 12:04:13 +0200272echo
273echo "The HTML block was emitted into $HTML and needs to be finished by hand."
274echo