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 | # creates a new haproxy release at the current commit |
| 3 | # Copyright (c) 2006-2016 Willy Tarreau <w@1wt.eu> |
| 4 | # |
| 5 | # In short : |
| 6 | # - requires git |
| 7 | # - works only from master branch |
| 8 | # - finds old and new version by itself |
| 9 | # - builds changelog |
| 10 | # - updates dates and versions in files |
| 11 | # - commits + tags + signs |
| 12 | # - no upload! |
| 13 | |
| 14 | USAGE="Usage: ${0##*/} [-i] [-y] [-t] [-b branch] [-d date] [-o oldver] [-n newver]" |
| 15 | INTERACTIVE= |
| 16 | TAGONLY= |
| 17 | SAYYES= |
| 18 | BRANCH= |
| 19 | DATE= |
| 20 | YEAR= |
| 21 | OLD= |
| 22 | NEW= |
| 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 | do_commit() { |
| 39 | ( |
| 40 | echo "[RELEASE] Released version $NEW" |
| 41 | echo |
| 42 | echo "Released version $NEW with the following main changes :" |
| 43 | sed -ne '/^[ ]*-/,/^$/{p;b a};d;:a;/^$/q' CHANGELOG |
| 44 | ) | git commit -a -F - |
| 45 | } |
| 46 | |
| 47 | do_tag() { |
| 48 | git tag -u "$GIT_GPG_KEY" -s -m "HAProxy $NEW" v$NEW && echo "Tagged as v$NEW" |
| 49 | } |
| 50 | |
Willy Tarreau | 4a5be93 | 2017-06-16 12:43:53 +0200 | [diff] [blame] | 51 | if [ -z "$GIT_COMMITTER_NAME" ]; then |
| 52 | GIT_COMMITTER_NAME=$(git config --get user.name) |
| 53 | [ -n "$GIT_COMMITTER_NAME" ] || die "GIT_COMMITTER_NAME not set" |
| 54 | fi |
| 55 | |
| 56 | if [ -z "$GIT_COMMITTER_EMAIL" ]; then |
| 57 | GIT_COMMITTER_EMAIL=$(git config --get user.email) |
| 58 | [ -n "$GIT_COMMITTER_EMAIL" ] || die "GIT_COMMITTER_EMAIL not set" |
| 59 | fi |
| 60 | |
Willy Tarreau | 62b71ee | 2016-05-10 12:04:13 +0200 | [diff] [blame] | 61 | while [ -n "$1" -a -z "${1##-*}" ]; do |
| 62 | case "$1" in |
| 63 | -y) SAYYES=1 ; shift ;; |
| 64 | -i) INTERACTIVE=1 ; shift ;; |
| 65 | -t) TAGONLY=1 ; shift ;; |
| 66 | -d) DATE="$2" ; shift 2 ;; |
| 67 | -b) BRANCH="$2" ; shift 2 ;; |
| 68 | -o) OLD="$2" ; shift 2 ;; |
| 69 | -n) NEW="$2" ; shift 2 ;; |
| 70 | -h|--help) quit "$USAGE" ;; |
| 71 | *) die "$USAGE" ;; |
| 72 | esac |
| 73 | done |
| 74 | |
| 75 | if [ $# -gt 0 ]; then |
| 76 | die "$USAGE" |
| 77 | fi |
| 78 | |
| 79 | if [ -z "$GIT_GPG_KEY" ]; then |
| 80 | die "GIT_GPG_KEY is not set, it must contain your GPG key ID." |
| 81 | fi |
| 82 | |
| 83 | if ! git rev-parse --verify -q HEAD >/dev/null; then |
| 84 | die "Failed to check git HEAD." |
| 85 | fi |
| 86 | |
| 87 | # we want to go to the git top dir |
| 88 | cd $(git rev-parse --show-toplevel) |
| 89 | |
| 90 | if [ "$(git rev-parse --verify -q HEAD)" != "$(git rev-parse --verify -q master)" ]; then |
| 91 | die "git HEAD doesn't match master branch." |
| 92 | fi |
| 93 | |
| 94 | if [ "$(git diff HEAD|wc -c)" != 0 ]; then |
| 95 | err "You appear to have uncommitted local changes, please commit them first :" |
| 96 | git status -s -uno >&2 |
| 97 | die |
| 98 | fi |
| 99 | |
| 100 | if [ -z "$OLD" ]; then |
| 101 | OLD="$(git describe --tags HEAD --abbrev=0)" |
| 102 | OLD="${OLD#v}" |
| 103 | fi |
| 104 | |
| 105 | if ! git rev-parse --verify -q "v$OLD" >/dev/null; then |
| 106 | die "git tag v$OLD doesn't exist." |
| 107 | fi |
| 108 | |
| 109 | if [ -z "$NEW" ]; then |
| 110 | radix="$OLD" |
| 111 | while [ -n "$radix" -a -z "${radix%%*[0-9]}" ]; do |
| 112 | radix="${radix%[0-9]}" |
| 113 | done |
| 114 | |
| 115 | number=${OLD#$radix} |
| 116 | if [ -z "$number" -o "$radix" = "$OLD" ]; then |
| 117 | die "Fatal: cannot determine new version, please specify it." |
| 118 | fi |
| 119 | NEW=${radix}$((number+1)) |
| 120 | fi |
| 121 | |
| 122 | if git show-ref --tags "v$NEW" >/dev/null; then |
| 123 | die "git tag v$NEW already exists, please remove it first." |
| 124 | fi |
| 125 | |
| 126 | # determine the product branch from the new release |
| 127 | if [ -z "$BRANCH" ]; then |
| 128 | subvers=${NEW#[0-9]*.[0-9]*[-.]*[0-9].} |
| 129 | [ "${subvers}" = "${NEW}" ] && subvers="" |
| 130 | major=${NEW%.$subvers} |
| 131 | branch_ext=${major#*[0-9].*[0-9]} |
| 132 | BRANCH=${major%${branch_ext}} |
| 133 | fi |
| 134 | |
| 135 | |
| 136 | # determine the release date |
| 137 | if [ -z "$DATE" ]; then |
| 138 | # Uncomment the line below to use the date of the last commit, |
| 139 | # otherwise fall back to current date |
| 140 | DATE="$(git log --pretty=fuller -1 v$NEW 2>/dev/null | sed -ne '/^CommitDate:/{s/\(^[^ ]*:\)\|\( [-+].*\)//gp;q}')" |
| 141 | DATE="$(date +%Y/%m/%d -d "$DATE")" |
| 142 | else |
| 143 | if [ "$DATE" != "$(date +%Y/%m/%d -d "$DATE")" ]; then |
| 144 | die "Date format must exclusively be YYYY/MM/DD ; date was '$DATE'." |
| 145 | fi |
| 146 | fi |
| 147 | YEAR="${DATE%%/*}" |
| 148 | |
| 149 | if [ -n "$TAGONLY" ]; then |
| 150 | do_tag || die "Failed to tag changes" |
| 151 | echo "Done. You may have to push changes." |
| 152 | exit 0 |
| 153 | fi |
| 154 | |
| 155 | echo "About to release version $NEW from $OLD at $DATE (branch $BRANCH)." |
| 156 | if [ -z "$SAYYES" ]; then |
| 157 | echo "Press ENTER to continue or Ctrl-C to abort now!" |
| 158 | read |
| 159 | fi |
| 160 | |
| 161 | echo "Updating CHANGELOG ..." |
| 162 | ( echo "ChangeLog :" |
| 163 | echo "===========" |
| 164 | echo |
| 165 | echo "$DATE : $NEW" |
| 166 | #git shortlog v$OLD.. | sed -ne 's/^ / - /p' |
Willy Tarreau | 7e8c016 | 2019-11-25 20:40:52 +0100 | [diff] [blame] | 167 | if [ $(git log --oneline v$OLD.. | wc -l) = 0 ]; then |
| 168 | echo " - exact copy of $OLD" |
| 169 | else |
| 170 | git log --oneline --reverse --format=" - %s" v$OLD.. |
| 171 | fi |
Willy Tarreau | 62b71ee | 2016-05-10 12:04:13 +0200 | [diff] [blame] | 172 | echo |
Willy Tarreau | 2c44cd8 | 2017-06-16 12:35:54 +0200 | [diff] [blame] | 173 | tail -n +4 CHANGELOG |
Willy Tarreau | 62b71ee | 2016-05-10 12:04:13 +0200 | [diff] [blame] | 174 | ) >.chglog.tmp && mv .chglog.tmp CHANGELOG |
| 175 | |
| 176 | echo "Updating VERSION ..." |
| 177 | rm -f VERSION VERDATE |
| 178 | echo "$NEW" > VERSION |
| 179 | |
| 180 | echo "Updating VERDATE ..." |
| 181 | echo '$Format:%ci$' > VERDATE |
| 182 | echo "$DATE" >> VERDATE |
| 183 | |
Willy Tarreau | 7f33273 | 2018-12-16 22:27:15 +0100 | [diff] [blame] | 184 | # updating branch and date in all modified doc files except the outdated architecture.txt |
| 185 | for file in doc/intro.txt doc/configuration.txt doc/management.txt $(git diff --name-only v${OLD}.. -- doc); do |
Willy Tarreau | 62b71ee | 2016-05-10 12:04:13 +0200 | [diff] [blame] | 186 | if [ ! -e "$file" ]; then continue; fi |
| 187 | if [ "$file" = doc/architecture.txt ]; then continue; fi |
| 188 | echo "Updating $file ..." |
| 189 | sed -e "1,10s:\(\sversion\s\).*:\1$BRANCH:" \ |
| 190 | -e "1,10s:\(\s\)\(20[0-9]\{2\}/[0-9]\{1,2\}/[0-9]\{1,2\}\):\1$DATE:" \ |
| 191 | -i "$file" |
| 192 | done |
| 193 | |
| 194 | echo "Updating haproxy.c ..." |
| 195 | sed -e "s:Copyright 2000-[0-9]*\s*Willy Tarreau.*>:Copyright 2000-$YEAR Willy Tarreau <willy@haproxy.org>:" \ |
| 196 | -i src/haproxy.c |
| 197 | |
Willy Tarreau | 990397e | 2017-01-05 19:58:24 +0100 | [diff] [blame] | 198 | echo "Updating version.h ..." |
| 199 | sed -e "s:^\(#define\s*PRODUCT_BRANCH\s*\)\"[^\"]*\":\1\"$BRANCH\":" \ |
| 200 | -i include/common/version.h |
| 201 | |
Willy Tarreau | 62b71ee | 2016-05-10 12:04:13 +0200 | [diff] [blame] | 202 | if [ -n "$INTERACTIVE" ]; then |
Willy Tarreau | a8ee4b1 | 2019-06-15 18:56:48 +0200 | [diff] [blame] | 203 | vi CHANGELOG VERSION VERDATE \ |
Willy Tarreau | 7f33273 | 2018-12-16 22:27:15 +0100 | [diff] [blame] | 204 | src/haproxy.c doc/configuration.txt \ |
Willy Tarreau | 62b71ee | 2016-05-10 12:04:13 +0200 | [diff] [blame] | 205 | $(git diff --name-only v${OLD}.. -- doc) |
| 206 | fi |
| 207 | |
| 208 | if [ "$(git diff -- CHANGELOG | wc -c)" = 0 ]; then |
| 209 | die "CHANGELOG must be updated." |
| 210 | fi |
| 211 | |
| 212 | if [ -z "$SAYYES" ]; then |
| 213 | echo "Press ENTER to review the changes..." |
| 214 | read |
| 215 | fi |
| 216 | |
| 217 | git diff |
| 218 | |
| 219 | echo |
| 220 | echo "About to commit and tag version $NEW with the following message:" |
| 221 | echo |
| 222 | echo "[RELEASE] Released version $NEW with the following main changes :" |
| 223 | sed -ne '/^[ ]*-/,/^$/{p;b a};d;:a;/^$/q' CHANGELOG |
| 224 | |
| 225 | echo |
| 226 | echo "LAST chance to cancel! Press ENTER to proceed now or Ctrl-C to abort." |
| 227 | read |
| 228 | |
| 229 | do_commit || die "Failed to commit changes" |
| 230 | do_tag || die "Failed to tag changes" |
| 231 | |
Willy Tarreau | ff0c842 | 2019-11-25 15:49:31 +0100 | [diff] [blame] | 232 | remote=$(git config --get branch.master.remote) |
Willy Tarreau | 62b71ee | 2016-05-10 12:04:13 +0200 | [diff] [blame] | 233 | echo "Do not forget to push updates, publish and announce this version :" |
| 234 | echo |
Willy Tarreau | ff0c842 | 2019-11-25 15:49:31 +0100 | [diff] [blame] | 235 | echo "git push ${remote:-origin} master v$NEW" |
Willy Tarreau | 62b71ee | 2016-05-10 12:04:13 +0200 | [diff] [blame] | 236 | echo "${0%/*}/publish-release" |
| 237 | echo "${0%/*}/announce-release" |