Willy Tarreau | be9b00f | 2020-02-05 04:45:18 +0100 | [diff] [blame] | 1 | #!/usr/bin/env bash |
Willy Tarreau | 62b71ee | 2016-05-10 12:04:13 +0200 | [diff] [blame] | 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 | 3823408 | 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 | 3823408 | 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 | 3823408 | 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 | 3823408 | 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 | 3823408 | 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 | 0f5ce60 | 2020-02-07 08:10:06 +0100 | [diff] [blame] | 125 | ( |
| 126 | echo "# Send this using:" |
| 127 | echo "# mutt -i <(tail -n +4 ${OUTPUT##*/}) -s \"[ANNOUNCE] haproxy-$NEW\" haproxy@formilux.org" |
| 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 | 62b71ee | 2016-05-10 12:04:13 +0200 | [diff] [blame] | 168 | echo " Sources : http://www.haproxy.org/download/${BRANCH}/src/" |
| 169 | echo " Git repository : http://git.haproxy.org/git/${gitdir}/" |
| 170 | echo " Git Web browsing : http://git.haproxy.org/?p=${gitdir}" |
| 171 | echo " Changelog : http://www.haproxy.org/download/${BRANCH}/src/CHANGELOG" |
| 172 | echo " Cyril's HTML doc : http://cbonte.github.io/haproxy-dconv/" |
| 173 | ) >> "$OUTPUT" |
| 174 | |
| 175 | # sign |
| 176 | (echo |
| 177 | echo "${GIT_COMMITTER_NAME% *}" |
| 178 | ) >> "$OUTPUT" |
| 179 | |
| 180 | (echo "---" |
| 181 | echo "Complete changelog :" |
Willy Tarreau | 6a375ef | 2017-03-27 19:32:24 +0200 | [diff] [blame] | 182 | git shortlog "v$OLD".."v$NEW^" |
Willy Tarreau | 62b71ee | 2016-05-10 12:04:13 +0200 | [diff] [blame] | 183 | echo "---" |
| 184 | ) >> "$OUTPUT" |
| 185 | |
| 186 | |
| 187 | # prepare the HTML update |
| 188 | set -- $(date +%e -d "$DATE") |
| 189 | case "$1" in |
| 190 | 11|12|13) day="${1}th" ;; |
| 191 | *1) day="${1}st" ;; |
| 192 | *2) day="${2}nd" ;; |
| 193 | *3) day="${1}rd" ;; |
| 194 | *) day="${1}th" ;; |
| 195 | esac |
| 196 | |
| 197 | humandate=$(date "+%B, $day, %Y" -d "$DATE") |
| 198 | (echo "$humandate</b> : <i>$NEW</i>" |
| 199 | echo " <p>" |
| 200 | echo " <ul>" |
| 201 | echo "<--------------------------- edit contents below --------------------------->" |
| 202 | echo "- per tag :" |
| 203 | git log --oneline --reverse --format="%s" "v$OLD".."v$NEW^" | cut -f1 -d':' | sort | uniq -c |
| 204 | echo |
| 205 | echo "- per topic :" |
| 206 | git log --oneline --reverse --format="%s" "v$OLD".."v$NEW^" | cut -f2 -d':' | awk '{sub("s$","",$1); print $1}' | sort | uniq -c |
| 207 | echo |
| 208 | echo "major commits :" |
| 209 | git log --oneline --reverse --format=" - %s" "v$OLD".."v$NEW^" | grep MAJOR |
| 210 | echo |
| 211 | echo "<--------------------------------------------------------------------------->" |
| 212 | echo " Code and changelog are available <a href=\"/download/${BRANCH}/src/\">here</a> as usual." |
| 213 | echo " </ul>" |
| 214 | echo " <p>" |
| 215 | echo " <b>" |
| 216 | ) >> "$HTML" |
| 217 | |
| 218 | echo "The announce was emitted into file $OUTPUT." |
| 219 | echo "You can edit it and send it this way :" |
| 220 | echo |
Willy Tarreau | 0f5ce60 | 2020-02-07 08:10:06 +0100 | [diff] [blame] | 221 | echo " mutt -i <(tail -n +4 ${OUTPUT##*/}) -s \"[ANNOUNCE] haproxy-$NEW\" haproxy@formilux.org" |
Willy Tarreau | 62b71ee | 2016-05-10 12:04:13 +0200 | [diff] [blame] | 222 | echo |
| 223 | echo "The HTML block was emitted into $HTML and needs to be finished by hand." |
| 224 | echo |