Willy Tarreau | 62b71ee | 2016-05-10 12:04:13 +0200 | [diff] [blame] | 1 | #!/bin/bash |
| 2 | # puts the public files online after a release |
| 3 | # Copyright (c) 2006-2016 Willy Tarreau <w@1wt.eu> |
| 4 | # |
| 5 | # In short : |
| 6 | # - requires git |
| 7 | # - no restriction to master, uses last tag |
| 8 | # - copies & compresses files, changelog & docs to the final destination |
| 9 | # - shows a listing of the final file |
| 10 | |
Willy Tarreau | bd69891 | 2017-06-09 15:57:31 +0200 | [diff] [blame] | 11 | USAGE="Usage: ${0##*/} [-a] [-q] [-y] [-b branch] [-n newver] DIR" |
Willy Tarreau | 62b71ee | 2016-05-10 12:04:13 +0200 | [diff] [blame] | 12 | TARGET_DIR= |
| 13 | OUTPUT= |
| 14 | SAYYES= |
| 15 | BRANCH= |
| 16 | DEVEL= |
Willy Tarreau | bd69891 | 2017-06-09 15:57:31 +0200 | [diff] [blame] | 17 | QUIET= |
Willy Tarreau | 7ca8815 | 2017-06-09 15:54:39 +0200 | [diff] [blame] | 18 | AUTO= |
Willy Tarreau | 62b71ee | 2016-05-10 12:04:13 +0200 | [diff] [blame] | 19 | NEW= |
| 20 | DIR= |
| 21 | DOC=( ) |
| 22 | |
| 23 | die() { |
| 24 | [ "$#" -eq 0 ] || echo "$*" >&2 |
| 25 | exit 1 |
| 26 | } |
| 27 | |
| 28 | err() { |
| 29 | echo "$*" >&2 |
| 30 | } |
| 31 | |
| 32 | quit() { |
Willy Tarreau | bd69891 | 2017-06-09 15:57:31 +0200 | [diff] [blame] | 33 | [ "$#" -eq 0 -o -n "$QUIET" ] || echo "$*" |
Willy Tarreau | 62b71ee | 2016-05-10 12:04:13 +0200 | [diff] [blame] | 34 | exit 0 |
| 35 | } |
| 36 | |
| 37 | while [ -n "$1" -a -z "${1##-*}" ]; do |
| 38 | case "$1" in |
Willy Tarreau | 7ca8815 | 2017-06-09 15:54:39 +0200 | [diff] [blame] | 39 | -a) AUTO=1 ; shift ;; |
Willy Tarreau | bd69891 | 2017-06-09 15:57:31 +0200 | [diff] [blame] | 40 | -q) QUIET=1 ; shift ;; |
Willy Tarreau | 62b71ee | 2016-05-10 12:04:13 +0200 | [diff] [blame] | 41 | -y) SAYYES=1 ; shift ;; |
| 42 | -b) BRANCH="$2" ; shift 2 ;; |
| 43 | -n) NEW="$2" ; shift 2 ;; |
| 44 | -h|--help) quit "$USAGE" ;; |
| 45 | *) die "$USAGE" ;; |
| 46 | esac |
| 47 | done |
| 48 | |
| 49 | if [ $# -ne 1 ]; then |
| 50 | die "$USAGE" |
| 51 | fi |
| 52 | |
| 53 | DIR="$1" ; shift |
| 54 | if [ -z "$DIR" ]; then |
| 55 | die "Missing target directory name." |
| 56 | fi |
| 57 | |
| 58 | if [ -n "${DIR##/*}" ]; then |
| 59 | DIR="$PWD/$DIR" |
| 60 | fi |
| 61 | |
| 62 | if [ ! -d "$DIR/." ]; then |
| 63 | die "Target directory doesn't exist : $DIR" |
| 64 | fi |
| 65 | |
| 66 | if ! git rev-parse --verify -q HEAD >/dev/null; then |
| 67 | die "Failed to check git HEAD." |
| 68 | fi |
| 69 | |
| 70 | # we want to go to the git top dir |
Willy Tarreau | 600cb57 | 2017-06-09 15:36:02 +0200 | [diff] [blame] | 71 | toplvl=$(git rev-parse --show-toplevel) |
| 72 | if [ -n "$toplvl" ]; then |
| 73 | cd "$toplvl" |
| 74 | fi |
| 75 | |
| 76 | # ensure that a master branch exists here |
| 77 | if [ -z "$(git rev-parse --verify -q master 2>/dev/null)" ]; then |
| 78 | die "Current directory doesn't seem to be a valid git directory (no master branch)." |
| 79 | fi |
Willy Tarreau | 62b71ee | 2016-05-10 12:04:13 +0200 | [diff] [blame] | 80 | |
| 81 | if [ "$(git rev-parse --verify -q HEAD)" != "$(git rev-parse --verify -q master)" ]; then |
| 82 | die "git HEAD doesn't match master branch." |
| 83 | fi |
| 84 | |
Willy Tarreau | 600cb57 | 2017-06-09 15:36:02 +0200 | [diff] [blame] | 85 | if [ "$(git diff HEAD 2>/dev/null |wc -c)" != 0 ]; then |
Willy Tarreau | 62b71ee | 2016-05-10 12:04:13 +0200 | [diff] [blame] | 86 | err "You appear to have uncommitted local changes, please commit them first :" |
| 87 | git status -s -uno >&2 |
| 88 | die |
| 89 | fi |
| 90 | |
Willy Tarreau | 7ca8815 | 2017-06-09 15:54:39 +0200 | [diff] [blame] | 91 | if [ -z "$NEW" -o -n "$AUTO" ]; then |
Willy Tarreau | 62b71ee | 2016-05-10 12:04:13 +0200 | [diff] [blame] | 92 | if [ -z "$NEW" ]; then |
Willy Tarreau | 7ca8815 | 2017-06-09 15:54:39 +0200 | [diff] [blame] | 93 | NEW="$(git describe --tags HEAD --abbrev=0)" |
| 94 | NEW="${NEW#v}" |
| 95 | if [ -z "$NEW" ]; then |
| 96 | die "Fatal: cannot determine new version, please specify it." |
| 97 | fi |
Willy Tarreau | 62b71ee | 2016-05-10 12:04:13 +0200 | [diff] [blame] | 98 | fi |
Willy Tarreau | 7ca8815 | 2017-06-09 15:54:39 +0200 | [diff] [blame] | 99 | |
Willy Tarreau | 62b71ee | 2016-05-10 12:04:13 +0200 | [diff] [blame] | 100 | if [ "$(git describe --tags HEAD)" != "v$NEW" ]; then |
Willy Tarreau | 7ca8815 | 2017-06-09 15:54:39 +0200 | [diff] [blame] | 101 | if [ -n "$AUTO" ]; then |
| 102 | quit "Not tagged, nothing to do." |
| 103 | fi |
Willy Tarreau | 62b71ee | 2016-05-10 12:04:13 +0200 | [diff] [blame] | 104 | die "Current version doesn't seem tagged, it reports $(git describe --tags "v$NEW"). Did you release it ?" |
| 105 | fi |
| 106 | fi |
| 107 | |
| 108 | if ! git show-ref --tags "v$NEW" >/dev/null; then |
| 109 | die "git tag v$NEW doesn't exist, did you create the release ?" |
| 110 | fi |
| 111 | |
| 112 | # determine the product branch from the new release |
| 113 | if [ -z "$BRANCH" ]; then |
| 114 | subvers=${NEW#[0-9]*.[0-9]*[-.]*[0-9].} |
| 115 | [ "${subvers}" = "${NEW}" ] && subvers="" |
| 116 | major=${NEW%.$subvers} |
| 117 | branch_ext=${major#*[0-9].*[0-9]} |
| 118 | BRANCH=${major%${branch_ext}} |
| 119 | fi |
| 120 | |
| 121 | TARGET_DIR="$DIR/$BRANCH" |
| 122 | if [ ! -d "$TARGET_DIR/." ]; then |
| 123 | die "Target directory doesn't contain branch $BRANCH. You may have to create it in $DIR." |
| 124 | fi |
| 125 | |
| 126 | if [ -z "${NEW##*-dev*}" ]; then |
| 127 | DEVEL="/devel" |
| 128 | fi |
| 129 | |
Willy Tarreau | 7ca8815 | 2017-06-09 15:54:39 +0200 | [diff] [blame] | 130 | if [ -n "$AUTO" -a -e "$TARGET_DIR/src${DEVEL}/haproxy-$NEW.tar.gz.md5" ]; then |
| 131 | quit "Version $NEW Already released." |
| 132 | fi |
| 133 | |
Willy Tarreau | 62b71ee | 2016-05-10 12:04:13 +0200 | [diff] [blame] | 134 | if ! mkdir -p "$TARGET_DIR/src$DEVEL" "$TARGET_DIR/doc"; then |
| 135 | die "failed to create target directories." |
| 136 | fi |
| 137 | |
| 138 | case "$BRANCH" in |
| 139 | 1.3) DOC=( doc/{haproxy-en,haproxy-fr,configuration,architecture}.txt ) ;; |
| 140 | 1.4) DOC=( doc/{haproxy-en,haproxy-fr,configuration}.txt ) ;; |
| 141 | 1.5) DOC=( doc/{coding-style,configuration,proxy-protocol}.txt ) ;; |
| 142 | 1.6) DOC=( doc/{coding-style,intro,management,configuration,proxy-protocol,lua}.txt ) ;; |
Willy Tarreau | 6cc2118 | 2016-11-09 23:21:47 +0100 | [diff] [blame] | 143 | *) DOC=( doc/{coding-style,intro,management,configuration,proxy-protocol,lua,SPOE}.txt ) ;; |
Willy Tarreau | 62b71ee | 2016-05-10 12:04:13 +0200 | [diff] [blame] | 144 | esac |
| 145 | |
Willy Tarreau | 7ca8815 | 2017-06-09 15:54:39 +0200 | [diff] [blame] | 146 | if [ -z "$AUTO" ]; then |
| 147 | echo "Ready to produce the following files in $TARGET_DIR/ :" |
| 148 | echo " haproxy-$NEW.tar.gz -> src${DEVEL}/" |
| 149 | echo " CHANGELOG -> src/CHANGELOG" |
| 150 | echo " ${DOC[@]} -> doc/*{,.gz}" |
| 151 | echo |
Willy Tarreau | 62b71ee | 2016-05-10 12:04:13 +0200 | [diff] [blame] | 152 | |
Willy Tarreau | 7ca8815 | 2017-06-09 15:54:39 +0200 | [diff] [blame] | 153 | git ls-tree -l --abbrev=12 "v$NEW" -- CHANGELOG "${DOC[@]}" |
Willy Tarreau | 62b71ee | 2016-05-10 12:04:13 +0200 | [diff] [blame] | 154 | |
Willy Tarreau | 7ca8815 | 2017-06-09 15:54:39 +0200 | [diff] [blame] | 155 | if [ -z "$SAYYES" ]; then |
| 156 | echo "Press ENTER to continue or Ctrl-C to abort now!" |
| 157 | read |
| 158 | fi |
Willy Tarreau | 62b71ee | 2016-05-10 12:04:13 +0200 | [diff] [blame] | 159 | fi |
| 160 | |
| 161 | echo "Archiving sources for version $NEW ..." |
Tim Duesterhus | 3ce3811 | 2018-07-19 23:57:56 +0200 | [diff] [blame] | 162 | rm -f "${TARGET_DIR}/src${DEVEL}/haproxy-${NEW}.tar.gz"{,.md5,.sha256} |
Willy Tarreau | 62b71ee | 2016-05-10 12:04:13 +0200 | [diff] [blame] | 163 | if ! git archive --format=tar --prefix="haproxy-${NEW}/" "v$NEW" | \ |
| 164 | gzip -9 > "${TARGET_DIR}/src${DEVEL}/haproxy-${NEW}.tar.gz"; then |
| 165 | die "Failed to produce the tar.gz archive" |
| 166 | fi |
| 167 | |
| 168 | ( cd "$TARGET_DIR/src${DEVEL}" ; \ |
Tim Duesterhus | 3ce3811 | 2018-07-19 23:57:56 +0200 | [diff] [blame] | 169 | md5sum haproxy-$NEW.tar.gz > haproxy-$NEW.tar.gz.md5 ; \ |
| 170 | sha256sum haproxy-$NEW.tar.gz > haproxy-$NEW.tar.gz.sha256 ) |
Willy Tarreau | 62b71ee | 2016-05-10 12:04:13 +0200 | [diff] [blame] | 171 | |
| 172 | echo "Extracting doc ..." |
| 173 | git show "v$NEW:CHANGELOG" > "$TARGET_DIR/src/CHANGELOG" |
| 174 | |
| 175 | for i in "${DOC[@]}"; do |
| 176 | git show "v$NEW:$i" > "$TARGET_DIR/doc/${i#doc/}" |
| 177 | gzip -c9 < "$TARGET_DIR/doc/${i#doc/}" > "$TARGET_DIR/doc/${i#doc/}.gz" |
| 178 | done |
| 179 | |
| 180 | echo "Done : ls -l ${TARGET_DIR}" |
| 181 | ( cd "$TARGET_DIR" ; |
Tim Duesterhus | 3ce3811 | 2018-07-19 23:57:56 +0200 | [diff] [blame] | 182 | ls -l src/CHANGELOG "src${DEVEL}/haproxy-${NEW}".tar.gz{,.md5,.sha256} $(for i in "${DOC[@]}"; do echo "doc/${i#doc/}"{,.gz}; done) |
Willy Tarreau | 62b71ee | 2016-05-10 12:04:13 +0200 | [diff] [blame] | 183 | ) |
| 184 | echo |