blob: 4938049a3ed3641c1751038b46bbd05deb71490c [file] [log] [blame]
Willy Tarreaube9b00f2020-02-05 04:45:18 +01001#!/usr/bin/env bash
Willy Tarreau62b71ee2016-05-10 12:04:13 +02002# 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 Tarreaubd698912017-06-09 15:57:31 +020011USAGE="Usage: ${0##*/} [-a] [-q] [-y] [-b branch] [-n newver] DIR"
Willy Tarreau6fab3e62020-05-30 06:59:07 +020012CMD_GZIP="${CMD_GZIP:-gzip -nc9}"
Willy Tarreau62b71ee2016-05-10 12:04:13 +020013TARGET_DIR=
14OUTPUT=
15SAYYES=
16BRANCH=
17DEVEL=
Willy Tarreaubd698912017-06-09 15:57:31 +020018QUIET=
Willy Tarreau7ca88152017-06-09 15:54:39 +020019AUTO=
Willy Tarreau62b71ee2016-05-10 12:04:13 +020020NEW=
21DIR=
22DOC=( )
23
24die() {
25 [ "$#" -eq 0 ] || echo "$*" >&2
26 exit 1
27}
28
29err() {
30 echo "$*" >&2
31}
32
33quit() {
Willy Tarreaubd698912017-06-09 15:57:31 +020034 [ "$#" -eq 0 -o -n "$QUIET" ] || echo "$*"
Willy Tarreau62b71ee2016-05-10 12:04:13 +020035 exit 0
36}
37
38while [ -n "$1" -a -z "${1##-*}" ]; do
39 case "$1" in
Willy Tarreau7ca88152017-06-09 15:54:39 +020040 -a) AUTO=1 ; shift ;;
Willy Tarreaubd698912017-06-09 15:57:31 +020041 -q) QUIET=1 ; shift ;;
Willy Tarreau62b71ee2016-05-10 12:04:13 +020042 -y) SAYYES=1 ; shift ;;
43 -b) BRANCH="$2" ; shift 2 ;;
44 -n) NEW="$2" ; shift 2 ;;
45 -h|--help) quit "$USAGE" ;;
46 *) die "$USAGE" ;;
47 esac
48done
49
50if [ $# -ne 1 ]; then
51 die "$USAGE"
52fi
53
54DIR="$1" ; shift
55if [ -z "$DIR" ]; then
56 die "Missing target directory name."
57fi
58
59if [ -n "${DIR##/*}" ]; then
60 DIR="$PWD/$DIR"
61fi
62
63if [ ! -d "$DIR/." ]; then
64 die "Target directory doesn't exist : $DIR"
65fi
66
67if ! git rev-parse --verify -q HEAD >/dev/null; then
68 die "Failed to check git HEAD."
69fi
70
71# we want to go to the git top dir
Willy Tarreau600cb572017-06-09 15:36:02 +020072toplvl=$(git rev-parse --show-toplevel)
73if [ -n "$toplvl" ]; then
74 cd "$toplvl"
75fi
76
77# ensure that a master branch exists here
78if [ -z "$(git rev-parse --verify -q master 2>/dev/null)" ]; then
79 die "Current directory doesn't seem to be a valid git directory (no master branch)."
80fi
Willy Tarreau62b71ee2016-05-10 12:04:13 +020081
82if [ "$(git rev-parse --verify -q HEAD)" != "$(git rev-parse --verify -q master)" ]; then
83 die "git HEAD doesn't match master branch."
84fi
85
Willy Tarreau600cb572017-06-09 15:36:02 +020086if [ "$(git diff HEAD 2>/dev/null |wc -c)" != 0 ]; then
Willy Tarreau62b71ee2016-05-10 12:04:13 +020087 err "You appear to have uncommitted local changes, please commit them first :"
88 git status -s -uno >&2
89 die
90fi
91
Willy Tarreau7ca88152017-06-09 15:54:39 +020092if [ -z "$NEW" -o -n "$AUTO" ]; then
Willy Tarreau62b71ee2016-05-10 12:04:13 +020093 if [ -z "$NEW" ]; then
Willy Tarreau7ca88152017-06-09 15:54:39 +020094 NEW="$(git describe --tags HEAD --abbrev=0)"
95 NEW="${NEW#v}"
96 if [ -z "$NEW" ]; then
97 die "Fatal: cannot determine new version, please specify it."
98 fi
Willy Tarreau62b71ee2016-05-10 12:04:13 +020099 fi
Willy Tarreau7ca88152017-06-09 15:54:39 +0200100
Willy Tarreau62b71ee2016-05-10 12:04:13 +0200101 if [ "$(git describe --tags HEAD)" != "v$NEW" ]; then
Willy Tarreau7ca88152017-06-09 15:54:39 +0200102 if [ -n "$AUTO" ]; then
103 quit "Not tagged, nothing to do."
104 fi
Willy Tarreau62b71ee2016-05-10 12:04:13 +0200105 die "Current version doesn't seem tagged, it reports $(git describe --tags "v$NEW"). Did you release it ?"
106 fi
107fi
108
109if ! git show-ref --tags "v$NEW" >/dev/null; then
110 die "git tag v$NEW doesn't exist, did you create the release ?"
111fi
112
113# determine the product branch from the new release
114if [ -z "$BRANCH" ]; then
115 subvers=${NEW#[0-9]*.[0-9]*[-.]*[0-9].}
116 [ "${subvers}" = "${NEW}" ] && subvers=""
117 major=${NEW%.$subvers}
118 branch_ext=${major#*[0-9].*[0-9]}
119 BRANCH=${major%${branch_ext}}
120fi
121
122TARGET_DIR="$DIR/$BRANCH"
123if [ ! -d "$TARGET_DIR/." ]; then
124 die "Target directory doesn't contain branch $BRANCH. You may have to create it in $DIR."
125fi
126
127if [ -z "${NEW##*-dev*}" ]; then
128 DEVEL="/devel"
129fi
130
Willy Tarreau7ca88152017-06-09 15:54:39 +0200131if [ -n "$AUTO" -a -e "$TARGET_DIR/src${DEVEL}/haproxy-$NEW.tar.gz.md5" ]; then
132 quit "Version $NEW Already released."
133fi
134
Willy Tarreau62b71ee2016-05-10 12:04:13 +0200135if ! mkdir -p "$TARGET_DIR/src$DEVEL" "$TARGET_DIR/doc"; then
136 die "failed to create target directories."
137fi
138
139case "$BRANCH" in
140 1.3) DOC=( doc/{haproxy-en,haproxy-fr,configuration,architecture}.txt ) ;;
141 1.4) DOC=( doc/{haproxy-en,haproxy-fr,configuration}.txt ) ;;
142 1.5) DOC=( doc/{coding-style,configuration,proxy-protocol}.txt ) ;;
143 1.6) DOC=( doc/{coding-style,intro,management,configuration,proxy-protocol,lua}.txt ) ;;
Willy Tarreau6cc21182016-11-09 23:21:47 +0100144 *) DOC=( doc/{coding-style,intro,management,configuration,proxy-protocol,lua,SPOE}.txt ) ;;
Willy Tarreau62b71ee2016-05-10 12:04:13 +0200145esac
146
Willy Tarreau7ca88152017-06-09 15:54:39 +0200147if [ -z "$AUTO" ]; then
148 echo "Ready to produce the following files in $TARGET_DIR/ :"
149 echo " haproxy-$NEW.tar.gz -> src${DEVEL}/"
150 echo " CHANGELOG -> src/CHANGELOG"
151 echo " ${DOC[@]} -> doc/*{,.gz}"
152 echo
Willy Tarreau62b71ee2016-05-10 12:04:13 +0200153
Willy Tarreau7ca88152017-06-09 15:54:39 +0200154 git ls-tree -l --abbrev=12 "v$NEW" -- CHANGELOG "${DOC[@]}"
Willy Tarreau62b71ee2016-05-10 12:04:13 +0200155
Willy Tarreau7ca88152017-06-09 15:54:39 +0200156 if [ -z "$SAYYES" ]; then
157 echo "Press ENTER to continue or Ctrl-C to abort now!"
158 read
159 fi
Willy Tarreau62b71ee2016-05-10 12:04:13 +0200160fi
161
162echo "Archiving sources for version $NEW ..."
Tim Duesterhus3ce38112018-07-19 23:57:56 +0200163rm -f "${TARGET_DIR}/src${DEVEL}/haproxy-${NEW}.tar.gz"{,.md5,.sha256}
Willy Tarreau62b71ee2016-05-10 12:04:13 +0200164if ! git archive --format=tar --prefix="haproxy-${NEW}/" "v$NEW" | \
Willy Tarreau6fab3e62020-05-30 06:59:07 +0200165 $CMD_GZIP > "${TARGET_DIR}/src${DEVEL}/haproxy-${NEW}.tar.gz"; then
Willy Tarreau62b71ee2016-05-10 12:04:13 +0200166 die "Failed to produce the tar.gz archive"
167fi
168
169( cd "$TARGET_DIR/src${DEVEL}" ; \
Tim Duesterhus3ce38112018-07-19 23:57:56 +0200170 md5sum haproxy-$NEW.tar.gz > haproxy-$NEW.tar.gz.md5 ; \
171 sha256sum haproxy-$NEW.tar.gz > haproxy-$NEW.tar.gz.sha256 )
Willy Tarreau62b71ee2016-05-10 12:04:13 +0200172
173echo "Extracting doc ..."
174git show "v$NEW:CHANGELOG" > "$TARGET_DIR/src/CHANGELOG"
175
176for i in "${DOC[@]}"; do
177 git show "v$NEW:$i" > "$TARGET_DIR/doc/${i#doc/}"
Willy Tarreau6fab3e62020-05-30 06:59:07 +0200178 $CMD_GZIP < "$TARGET_DIR/doc/${i#doc/}" > "$TARGET_DIR/doc/${i#doc/}.gz"
Willy Tarreau62b71ee2016-05-10 12:04:13 +0200179done
180
181echo "Done : ls -l ${TARGET_DIR}"
182( cd "$TARGET_DIR" ;
Tim Duesterhus3ce38112018-07-19 23:57:56 +0200183 ls -l src/CHANGELOG "src${DEVEL}/haproxy-${NEW}".tar.gz{,.md5,.sha256} $(for i in "${DOC[@]}"; do echo "doc/${i#doc/}"{,.gz}; done)
Willy Tarreau62b71ee2016-05-10 12:04:13 +0200184)
185echo