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 | |
| 11 | USAGE="Usage: ${0##*/} [-y] [-b branch] [-n newver] DIR" |
| 12 | TARGET_DIR= |
| 13 | OUTPUT= |
| 14 | SAYYES= |
| 15 | BRANCH= |
| 16 | DEVEL= |
| 17 | NEW= |
| 18 | DIR= |
| 19 | DOC=( ) |
| 20 | |
| 21 | die() { |
| 22 | [ "$#" -eq 0 ] || echo "$*" >&2 |
| 23 | exit 1 |
| 24 | } |
| 25 | |
| 26 | err() { |
| 27 | echo "$*" >&2 |
| 28 | } |
| 29 | |
| 30 | quit() { |
| 31 | [ "$#" -eq 0 ] || echo "$*" |
| 32 | exit 0 |
| 33 | } |
| 34 | |
| 35 | while [ -n "$1" -a -z "${1##-*}" ]; do |
| 36 | case "$1" in |
| 37 | -y) SAYYES=1 ; shift ;; |
| 38 | -b) BRANCH="$2" ; shift 2 ;; |
| 39 | -n) NEW="$2" ; shift 2 ;; |
| 40 | -h|--help) quit "$USAGE" ;; |
| 41 | *) die "$USAGE" ;; |
| 42 | esac |
| 43 | done |
| 44 | |
| 45 | if [ $# -ne 1 ]; then |
| 46 | die "$USAGE" |
| 47 | fi |
| 48 | |
| 49 | DIR="$1" ; shift |
| 50 | if [ -z "$DIR" ]; then |
| 51 | die "Missing target directory name." |
| 52 | fi |
| 53 | |
| 54 | if [ -n "${DIR##/*}" ]; then |
| 55 | DIR="$PWD/$DIR" |
| 56 | fi |
| 57 | |
| 58 | if [ ! -d "$DIR/." ]; then |
| 59 | die "Target directory doesn't exist : $DIR" |
| 60 | fi |
| 61 | |
| 62 | if ! git rev-parse --verify -q HEAD >/dev/null; then |
| 63 | die "Failed to check git HEAD." |
| 64 | fi |
| 65 | |
| 66 | # we want to go to the git top dir |
| 67 | cd $(git rev-parse --show-toplevel) |
| 68 | |
| 69 | if [ "$(git rev-parse --verify -q HEAD)" != "$(git rev-parse --verify -q master)" ]; then |
| 70 | die "git HEAD doesn't match master branch." |
| 71 | fi |
| 72 | |
| 73 | if [ "$(git diff HEAD|wc -c)" != 0 ]; then |
| 74 | err "You appear to have uncommitted local changes, please commit them first :" |
| 75 | git status -s -uno >&2 |
| 76 | die |
| 77 | fi |
| 78 | |
| 79 | if [ -z "$NEW" ]; then |
| 80 | NEW="$(git describe --tags HEAD --abbrev=0)" |
| 81 | NEW="${NEW#v}" |
| 82 | if [ -z "$NEW" ]; then |
| 83 | die "Fatal: cannot determine new version, please specify it." |
| 84 | fi |
| 85 | if [ "$(git describe --tags HEAD)" != "v$NEW" ]; then |
| 86 | die "Current version doesn't seem tagged, it reports $(git describe --tags "v$NEW"). Did you release it ?" |
| 87 | fi |
| 88 | fi |
| 89 | |
| 90 | if ! git show-ref --tags "v$NEW" >/dev/null; then |
| 91 | die "git tag v$NEW doesn't exist, did you create the release ?" |
| 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 | TARGET_DIR="$DIR/$BRANCH" |
| 104 | if [ ! -d "$TARGET_DIR/." ]; then |
| 105 | die "Target directory doesn't contain branch $BRANCH. You may have to create it in $DIR." |
| 106 | fi |
| 107 | |
| 108 | if [ -z "${NEW##*-dev*}" ]; then |
| 109 | DEVEL="/devel" |
| 110 | fi |
| 111 | |
| 112 | if ! mkdir -p "$TARGET_DIR/src$DEVEL" "$TARGET_DIR/doc"; then |
| 113 | die "failed to create target directories." |
| 114 | fi |
| 115 | |
| 116 | case "$BRANCH" in |
| 117 | 1.3) DOC=( doc/{haproxy-en,haproxy-fr,configuration,architecture}.txt ) ;; |
| 118 | 1.4) DOC=( doc/{haproxy-en,haproxy-fr,configuration}.txt ) ;; |
| 119 | 1.5) DOC=( doc/{coding-style,configuration,proxy-protocol}.txt ) ;; |
| 120 | 1.6) DOC=( doc/{coding-style,intro,management,configuration,proxy-protocol,lua}.txt ) ;; |
| 121 | *) DOC=( doc/{coding-style,intro,management,configuration,proxy-protocol,lua}.txt ) ;; |
| 122 | esac |
| 123 | |
| 124 | echo "Ready to produce the following files in $TARGET_DIR/ :" |
| 125 | echo " haproxy-$NEW.tar.gz -> src${DEVEL}/" |
| 126 | echo " CHANGELOG -> src/CHANGELOG" |
| 127 | echo " ${DOC[@]} -> doc/*{,.gz}" |
| 128 | echo |
| 129 | |
| 130 | git ls-tree -l --abbrev=12 "v$NEW" -- CHANGELOG "${DOC[@]}" |
| 131 | |
| 132 | if [ -z "$SAYYES" ]; then |
| 133 | echo "Press ENTER to continue or Ctrl-C to abort now!" |
| 134 | read |
| 135 | fi |
| 136 | |
| 137 | echo "Archiving sources for version $NEW ..." |
| 138 | rm -f "${TARGET_DIR}/src${DEVEL}/haproxy-${NEW}.tar.gz"{,.md5} |
| 139 | if ! git archive --format=tar --prefix="haproxy-${NEW}/" "v$NEW" | \ |
| 140 | gzip -9 > "${TARGET_DIR}/src${DEVEL}/haproxy-${NEW}.tar.gz"; then |
| 141 | die "Failed to produce the tar.gz archive" |
| 142 | fi |
| 143 | |
| 144 | ( cd "$TARGET_DIR/src${DEVEL}" ; \ |
| 145 | md5sum haproxy-$NEW.tar.gz > haproxy-$NEW.tar.gz.md5 ) |
| 146 | |
| 147 | echo "Extracting doc ..." |
| 148 | git show "v$NEW:CHANGELOG" > "$TARGET_DIR/src/CHANGELOG" |
| 149 | |
| 150 | for i in "${DOC[@]}"; do |
| 151 | git show "v$NEW:$i" > "$TARGET_DIR/doc/${i#doc/}" |
| 152 | gzip -c9 < "$TARGET_DIR/doc/${i#doc/}" > "$TARGET_DIR/doc/${i#doc/}.gz" |
| 153 | done |
| 154 | |
| 155 | echo "Done : ls -l ${TARGET_DIR}" |
| 156 | ( cd "$TARGET_DIR" ; |
| 157 | ls -l src/CHANGELOG "src${DEVEL}/haproxy-${NEW}".tar.gz{,.md5} $(for i in "${DOC[@]}"; do echo "doc/${i#doc/}"{,.gz}; done) |
| 158 | ) |
| 159 | echo |