Willy Tarreau | 62b71ee | 2016-05-10 12:04:13 +0200 | [diff] [blame] | 1 | #!/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 Tarreau | 7dc322d | 2020-02-07 08:11:45 +0100 | [diff] [blame] | 13 | USAGE="Usage: ${0##*/} [-f] [-b branch] [-d date] [-o oldver] [-n newver]" |
| 14 | FORCE= |
Willy Tarreau | 62b71ee | 2016-05-10 12:04:13 +0200 | [diff] [blame] | 15 | OUTPUT= |
| 16 | BRANCH= |
| 17 | HTML= |
| 18 | DATE= |
| 19 | YEAR= |
| 20 | OLD= |
| 21 | NEW= |
| 22 | DIR= |
| 23 | |
| 24 | die() { |
| 25 | [ "$#" -eq 0 ] || echo "$*" >&2 |
| 26 | exit 1 |
| 27 | } |
| 28 | |
| 29 | err() { |
| 30 | echo "$*" >&2 |
| 31 | } |
| 32 | |
| 33 | quit() { |
| 34 | [ "$#" -eq 0 ] || echo "$*" |
| 35 | exit 0 |
| 36 | } |
| 37 | |
| 38 | while [ -n "$1" -a -z "${1##-*}" ]; do |
| 39 | case "$1" in |
| 40 | -d) DATE="$2" ; shift 2 ;; |
| 41 | -b) BRANCH="$2" ; shift 2 ;; |
Willy Tarreau | 7dc322d | 2020-02-07 08:11:45 +0100 | [diff] [blame] | 42 | -f) FORCE=1 ; shift ;; |
Willy Tarreau | 62b71ee | 2016-05-10 12:04:13 +0200 | [diff] [blame] | 43 | -o) OLD="$2" ; shift 2 ;; |
| 44 | -n) NEW="$2" ; shift 2 ;; |
| 45 | -h|--help) quit "$USAGE" ;; |
| 46 | *) die "$USAGE" ;; |
| 47 | esac |
| 48 | done |
| 49 | |
| 50 | if [ $# -gt 0 ]; then |
| 51 | die "$USAGE" |
| 52 | fi |
| 53 | |
| 54 | if ! git rev-parse --verify -q HEAD >/dev/null; then |
| 55 | die "Failed to check git HEAD." |
| 56 | fi |
| 57 | |
| 58 | # we want to go to the git root dir |
| 59 | DIR="$PWD" |
| 60 | cd $(git rev-parse --show-toplevel) |
| 61 | |
| 62 | if [ "$(git rev-parse --verify -q HEAD)" != "$(git rev-parse --verify -q master)" ]; then |
| 63 | die "git HEAD doesn't match master branch." |
| 64 | fi |
| 65 | |
| 66 | if [ "$(git diff HEAD|wc -c)" != 0 ]; then |
| 67 | err "You appear to have uncommitted local changes, please commit them first :" |
| 68 | git status -s -uno >&2 |
| 69 | die |
| 70 | fi |
| 71 | |
| 72 | if [ -z "$NEW" ]; then |
| 73 | NEW="$(git describe --tags HEAD --abbrev=0)" |
| 74 | NEW="${NEW#v}" |
| 75 | if [ -z "$NEW" ]; then |
| 76 | die "Fatal: cannot determine new version, please specify it." |
| 77 | fi |
| 78 | if [ "$(git describe --tags HEAD)" != "v$NEW" ]; then |
| 79 | die "Current version doesn't seem tagged, it reports $(git describe --tags "v$NEW"). Did you release it ?" |
| 80 | fi |
| 81 | fi |
| 82 | |
| 83 | if ! git show-ref --tags "v$NEW" >/dev/null; then |
Willy Tarreau | 827385f | 2017-03-27 19:36:45 +0200 | [diff] [blame] | 84 | die "git tag v$NEW doesn't exist, did you create the release ?" |
Willy Tarreau | 62b71ee | 2016-05-10 12:04:13 +0200 | [diff] [blame] | 85 | fi |
| 86 | |
| 87 | if [ -z "$OLD" ]; then |
| 88 | OLD="$(git describe --tags v${NEW}^ --abbrev=0)" |
| 89 | OLD="${OLD#v}" |
| 90 | fi |
| 91 | |
| 92 | if ! git rev-parse --verify -q "v$OLD" >/dev/null; then |
| 93 | die "git tag v$OLD doesn't exist." |
| 94 | fi |
| 95 | |
| 96 | # determine the product branch from the new release |
| 97 | if [ -z "$BRANCH" ]; then |
| 98 | subvers=${NEW#[0-9]*.[0-9]*[-.]*[0-9].} |
| 99 | [ "${subvers}" = "${NEW}" ] && subvers="" |
| 100 | major=${NEW%.$subvers} |
| 101 | branch_ext=${major#*[0-9].*[0-9]} |
| 102 | BRANCH=${major%${branch_ext}} |
| 103 | fi |
| 104 | |
| 105 | # determine the release date |
| 106 | if [ -z "$DATE" ]; then |
| 107 | DATE="$(git log -1 --pretty=fuller v${NEW} 2>/dev/null | sed -ne '/^CommitDate:/{s/\(^[^ ]*:\)\|\( [-+].*\)//gp;q}')" |
| 108 | DATE="$(date +%Y/%m/%d -d "$DATE")" |
| 109 | fi |
| 110 | YEAR="${DATE%%/*}" |
| 111 | |
| 112 | OUTPUT="$DIR/mail-haproxy-$NEW.txt" |
Willy Tarreau | 7dc322d | 2020-02-07 08:11:45 +0100 | [diff] [blame] | 113 | HTML="$DIR/web-haproxy-$NEW.html" |
| 114 | |
| 115 | [ -z "$FORCE" ] || rm -f "${OUTPUT}" "${HTML}" |
| 116 | |
Willy Tarreau | 62b71ee | 2016-05-10 12:04:13 +0200 | [diff] [blame] | 117 | if [ -e "$OUTPUT" ]; then |
Willy Tarreau | 7dc322d | 2020-02-07 08:11:45 +0100 | [diff] [blame] | 118 | die "${OUTPUT##*/} already exists, please remove it or retry with -f." |
Willy Tarreau | 62b71ee | 2016-05-10 12:04:13 +0200 | [diff] [blame] | 119 | fi |
| 120 | |
Willy Tarreau | 62b71ee | 2016-05-10 12:04:13 +0200 | [diff] [blame] | 121 | if [ -e "$HTML" ]; then |
Willy Tarreau | 7dc322d | 2020-02-07 08:11:45 +0100 | [diff] [blame] | 122 | die "$HTML already exists, please remove it or retry with -f." |
Willy Tarreau | 62b71ee | 2016-05-10 12:04:13 +0200 | [diff] [blame] | 123 | fi |
| 124 | |
Willy Tarreau | 84f6dca | 2020-02-07 08:10:06 +0100 | [diff] [blame] | 125 | ( |
| 126 | echo "# Send this using:" |
Willy Tarreau | 164d009 | 2020-02-15 15:24:28 +0100 | [diff] [blame] | 127 | echo "# mutt -H <(tail -n +4 ${OUTPUT##*/}) -s \"[ANNOUNCE] haproxy-$NEW\" haproxy@formilux.org" |
Willy Tarreau | 84f6dca | 2020-02-07 08:10:06 +0100 | [diff] [blame] | 128 | ) >> "$OUTPUT" |
| 129 | |
| 130 | (echo |
Willy Tarreau | 62b71ee | 2016-05-10 12:04:13 +0200 | [diff] [blame] | 131 | echo "Hi," |
| 132 | echo |
| 133 | echo -n "HAProxy $NEW was released on $DATE. It added " |
| 134 | echo -n $(git log --oneline --reverse --format="%s" "v$OLD".."v$NEW^" | wc -l) |
| 135 | echo " new commits" |
| 136 | echo "after version $OLD." |
| 137 | echo |
| 138 | echo "- per tag :" |
| 139 | git log --oneline --reverse --format="%s" "v$OLD".."v$NEW^" | cut -f1 -d':' | sort | uniq -c |
| 140 | echo |
| 141 | echo "major commits :" |
| 142 | git log --oneline --reverse --format=" - %s" "v$OLD".."v$NEW^" | grep MAJOR |
| 143 | echo |
| 144 | echo "- per file :" |
| 145 | git show "v$OLD".."v$NEW^" -- src/ | grep ^diff | awk '{ print substr($3,7)}' | sort | uniq -c | sort -nr | head -15 |
| 146 | echo |
| 147 | echo "- per topic :" |
| 148 | git log --oneline --reverse --format="%s" "v$OLD".."v$NEW^" | cut -f2 -d':' | awk '{sub("s$","",$1); print $1}' | sort | uniq -c |
| 149 | echo |
| 150 | echo "- sorted changelog :" |
| 151 | git log --oneline --reverse --format="%s" "v$OLD".."v$NEW^" | sort |
| 152 | echo |
| 153 | echo "#############################################################################################" |
| 154 | ) >> "$OUTPUT" |
| 155 | |
| 156 | # report the download paths |
| 157 | if [ -z "${NEW##*-dev*}" ]; then |
| 158 | gitdir="haproxy.git" |
| 159 | else |
| 160 | gitdir="haproxy-$BRANCH.git" |
| 161 | fi |
| 162 | |
| 163 | (echo "Please find the usual URLs below :" |
| 164 | echo " Site index : http://www.haproxy.org/" |
| 165 | echo " Discourse : http://discourse.haproxy.org/" |
Willy Tarreau | d6cad12 | 2018-12-19 18:59:51 +0100 | [diff] [blame] | 166 | echo " Slack channel : https://slack.haproxy.org/" |
Willy Tarreau | 9589c3b | 2019-01-29 06:51:16 +0100 | [diff] [blame] | 167 | echo " Issue tracker : https://github.com/haproxy/haproxy/issues" |
Willy Tarreau | 36787f5 | 2020-07-30 17:41:42 +0200 | [diff] [blame] | 168 | echo " Wiki : https://github.com/haproxy/wiki/wiki" |
Willy Tarreau | 62b71ee | 2016-05-10 12:04:13 +0200 | [diff] [blame] | 169 | echo " Sources : http://www.haproxy.org/download/${BRANCH}/src/" |
| 170 | echo " Git repository : http://git.haproxy.org/git/${gitdir}/" |
| 171 | echo " Git Web browsing : http://git.haproxy.org/?p=${gitdir}" |
| 172 | echo " Changelog : http://www.haproxy.org/download/${BRANCH}/src/CHANGELOG" |
| 173 | echo " Cyril's HTML doc : http://cbonte.github.io/haproxy-dconv/" |
| 174 | ) >> "$OUTPUT" |
| 175 | |
| 176 | # sign |
| 177 | (echo |
| 178 | echo "${GIT_COMMITTER_NAME% *}" |
| 179 | ) >> "$OUTPUT" |
| 180 | |
| 181 | (echo "---" |
| 182 | echo "Complete changelog :" |
Willy Tarreau | 6a375ef | 2017-03-27 19:32:24 +0200 | [diff] [blame] | 183 | git shortlog "v$OLD".."v$NEW^" |
Willy Tarreau | 62b71ee | 2016-05-10 12:04:13 +0200 | [diff] [blame] | 184 | echo "---" |
| 185 | ) >> "$OUTPUT" |
| 186 | |
| 187 | |
| 188 | # prepare the HTML update |
| 189 | set -- $(date +%e -d "$DATE") |
| 190 | case "$1" in |
| 191 | 11|12|13) day="${1}th" ;; |
| 192 | *1) day="${1}st" ;; |
| 193 | *2) day="${2}nd" ;; |
| 194 | *3) day="${1}rd" ;; |
| 195 | *) day="${1}th" ;; |
| 196 | esac |
| 197 | |
| 198 | humandate=$(date "+%B, $day, %Y" -d "$DATE") |
| 199 | (echo "$humandate</b> : <i>$NEW</i>" |
| 200 | echo " <p>" |
| 201 | echo " <ul>" |
| 202 | echo "<--------------------------- edit contents below --------------------------->" |
| 203 | echo "- per tag :" |
| 204 | git log --oneline --reverse --format="%s" "v$OLD".."v$NEW^" | cut -f1 -d':' | sort | uniq -c |
| 205 | echo |
| 206 | echo "- per topic :" |
| 207 | git log --oneline --reverse --format="%s" "v$OLD".."v$NEW^" | cut -f2 -d':' | awk '{sub("s$","",$1); print $1}' | sort | uniq -c |
| 208 | echo |
| 209 | echo "major commits :" |
| 210 | git log --oneline --reverse --format=" - %s" "v$OLD".."v$NEW^" | grep MAJOR |
| 211 | echo |
| 212 | echo "<--------------------------------------------------------------------------->" |
| 213 | echo " Code and changelog are available <a href=\"/download/${BRANCH}/src/\">here</a> as usual." |
| 214 | echo " </ul>" |
| 215 | echo " <p>" |
| 216 | echo " <b>" |
| 217 | ) >> "$HTML" |
| 218 | |
| 219 | echo "The announce was emitted into file $OUTPUT." |
| 220 | echo "You can edit it and send it this way :" |
| 221 | echo |
Willy Tarreau | 164d009 | 2020-02-15 15:24:28 +0100 | [diff] [blame] | 222 | echo " mutt -H <(tail -n +4 ${OUTPUT##*/}) -s \"[ANNOUNCE] haproxy-$NEW\" haproxy@formilux.org" |
Willy Tarreau | 62b71ee | 2016-05-10 12:04:13 +0200 | [diff] [blame] | 223 | echo |
| 224 | echo "The HTML block was emitted into $HTML and needs to be finished by hand." |
| 225 | echo |