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