blob: 3cf32d80c5772eb36300e04aa6586904dde0edf7 [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 Tarreauc9641a22022-05-30 15:34:51 +020020ARG0="$0"
Willy Tarreau62b71ee2016-05-10 12:04:13 +020021NEW=
22DIR=
23DOC=( )
24
25die() {
26 [ "$#" -eq 0 ] || echo "$*" >&2
27 exit 1
28}
29
30err() {
31 echo "$*" >&2
32}
33
34quit() {
Willy Tarreaubd698912017-06-09 15:57:31 +020035 [ "$#" -eq 0 -o -n "$QUIET" ] || echo "$*"
Willy Tarreau62b71ee2016-05-10 12:04:13 +020036 exit 0
37}
38
39while [ -n "$1" -a -z "${1##-*}" ]; do
40 case "$1" in
Willy Tarreau7ca88152017-06-09 15:54:39 +020041 -a) AUTO=1 ; shift ;;
Willy Tarreaubd698912017-06-09 15:57:31 +020042 -q) QUIET=1 ; shift ;;
Willy Tarreau62b71ee2016-05-10 12:04:13 +020043 -y) SAYYES=1 ; shift ;;
44 -b) BRANCH="$2" ; shift 2 ;;
45 -n) NEW="$2" ; shift 2 ;;
46 -h|--help) quit "$USAGE" ;;
47 *) die "$USAGE" ;;
48 esac
49done
50
51if [ $# -ne 1 ]; then
52 die "$USAGE"
53fi
54
55DIR="$1" ; shift
56if [ -z "$DIR" ]; then
57 die "Missing target directory name."
58fi
59
60if [ -n "${DIR##/*}" ]; then
61 DIR="$PWD/$DIR"
62fi
63
64if [ ! -d "$DIR/." ]; then
65 die "Target directory doesn't exist : $DIR"
66fi
67
68if ! git rev-parse --verify -q HEAD >/dev/null; then
69 die "Failed to check git HEAD."
70fi
71
72# we want to go to the git top dir
Willy Tarreau600cb572017-06-09 15:36:02 +020073toplvl=$(git rev-parse --show-toplevel)
74if [ -n "$toplvl" ]; then
75 cd "$toplvl"
76fi
77
78# ensure that a master branch exists here
79if [ -z "$(git rev-parse --verify -q master 2>/dev/null)" ]; then
80 die "Current directory doesn't seem to be a valid git directory (no master branch)."
81fi
Willy Tarreau62b71ee2016-05-10 12:04:13 +020082
83if [ "$(git rev-parse --verify -q HEAD)" != "$(git rev-parse --verify -q master)" ]; then
84 die "git HEAD doesn't match master branch."
85fi
86
Willy Tarreau600cb572017-06-09 15:36:02 +020087if [ "$(git diff HEAD 2>/dev/null |wc -c)" != 0 ]; then
Willy Tarreau62b71ee2016-05-10 12:04:13 +020088 err "You appear to have uncommitted local changes, please commit them first :"
89 git status -s -uno >&2
90 die
91fi
92
Willy Tarreau7ca88152017-06-09 15:54:39 +020093if [ -z "$NEW" -o -n "$AUTO" ]; then
Willy Tarreau62b71ee2016-05-10 12:04:13 +020094 if [ -z "$NEW" ]; then
Willy Tarreau7ca88152017-06-09 15:54:39 +020095 NEW="$(git describe --tags HEAD --abbrev=0)"
96 NEW="${NEW#v}"
97 if [ -z "$NEW" ]; then
98 die "Fatal: cannot determine new version, please specify it."
99 fi
Willy Tarreau62b71ee2016-05-10 12:04:13 +0200100 fi
Willy Tarreau7ca88152017-06-09 15:54:39 +0200101
Willy Tarreau62b71ee2016-05-10 12:04:13 +0200102 if [ "$(git describe --tags HEAD)" != "v$NEW" ]; then
Willy Tarreau7ca88152017-06-09 15:54:39 +0200103 if [ -n "$AUTO" ]; then
104 quit "Not tagged, nothing to do."
105 fi
Willy Tarreau62b71ee2016-05-10 12:04:13 +0200106 die "Current version doesn't seem tagged, it reports $(git describe --tags "v$NEW"). Did you release it ?"
107 fi
108fi
109
110if ! git show-ref --tags "v$NEW" >/dev/null; then
111 die "git tag v$NEW doesn't exist, did you create the release ?"
112fi
113
114# determine the product branch from the new release
115if [ -z "$BRANCH" ]; then
116 subvers=${NEW#[0-9]*.[0-9]*[-.]*[0-9].}
117 [ "${subvers}" = "${NEW}" ] && subvers=""
118 major=${NEW%.$subvers}
119 branch_ext=${major#*[0-9].*[0-9]}
120 BRANCH=${major%${branch_ext}}
121fi
122
123TARGET_DIR="$DIR/$BRANCH"
124if [ ! -d "$TARGET_DIR/." ]; then
125 die "Target directory doesn't contain branch $BRANCH. You may have to create it in $DIR."
126fi
127
128if [ -z "${NEW##*-dev*}" ]; then
129 DEVEL="/devel"
130fi
131
Willy Tarreau7ca88152017-06-09 15:54:39 +0200132if [ -n "$AUTO" -a -e "$TARGET_DIR/src${DEVEL}/haproxy-$NEW.tar.gz.md5" ]; then
133 quit "Version $NEW Already released."
134fi
135
Willy Tarreau62b71ee2016-05-10 12:04:13 +0200136if ! mkdir -p "$TARGET_DIR/src$DEVEL" "$TARGET_DIR/doc"; then
137 die "failed to create target directories."
138fi
139
140case "$BRANCH" in
141 1.3) DOC=( doc/{haproxy-en,haproxy-fr,configuration,architecture}.txt ) ;;
142 1.4) DOC=( doc/{haproxy-en,haproxy-fr,configuration}.txt ) ;;
143 1.5) DOC=( doc/{coding-style,configuration,proxy-protocol}.txt ) ;;
144 1.6) DOC=( doc/{coding-style,intro,management,configuration,proxy-protocol,lua}.txt ) ;;
Willy Tarreau6cc21182016-11-09 23:21:47 +0100145 *) DOC=( doc/{coding-style,intro,management,configuration,proxy-protocol,lua,SPOE}.txt ) ;;
Willy Tarreau62b71ee2016-05-10 12:04:13 +0200146esac
147
Willy Tarreau7ca88152017-06-09 15:54:39 +0200148if [ -z "$AUTO" ]; then
149 echo "Ready to produce the following files in $TARGET_DIR/ :"
150 echo " haproxy-$NEW.tar.gz -> src${DEVEL}/"
151 echo " CHANGELOG -> src/CHANGELOG"
152 echo " ${DOC[@]} -> doc/*{,.gz}"
153 echo
Willy Tarreau62b71ee2016-05-10 12:04:13 +0200154
Willy Tarreau7ca88152017-06-09 15:54:39 +0200155 git ls-tree -l --abbrev=12 "v$NEW" -- CHANGELOG "${DOC[@]}"
Willy Tarreau62b71ee2016-05-10 12:04:13 +0200156
Willy Tarreau7ca88152017-06-09 15:54:39 +0200157 if [ -z "$SAYYES" ]; then
158 echo "Press ENTER to continue or Ctrl-C to abort now!"
159 read
160 fi
Willy Tarreau62b71ee2016-05-10 12:04:13 +0200161fi
162
163echo "Archiving sources for version $NEW ..."
Tim Duesterhus3ce38112018-07-19 23:57:56 +0200164rm -f "${TARGET_DIR}/src${DEVEL}/haproxy-${NEW}.tar.gz"{,.md5,.sha256}
Willy Tarreau62b71ee2016-05-10 12:04:13 +0200165if ! git archive --format=tar --prefix="haproxy-${NEW}/" "v$NEW" | \
Willy Tarreau6fab3e62020-05-30 06:59:07 +0200166 $CMD_GZIP > "${TARGET_DIR}/src${DEVEL}/haproxy-${NEW}.tar.gz"; then
Willy Tarreau62b71ee2016-05-10 12:04:13 +0200167 die "Failed to produce the tar.gz archive"
168fi
169
170( cd "$TARGET_DIR/src${DEVEL}" ; \
Tim Duesterhus3ce38112018-07-19 23:57:56 +0200171 md5sum haproxy-$NEW.tar.gz > haproxy-$NEW.tar.gz.md5 ; \
172 sha256sum haproxy-$NEW.tar.gz > haproxy-$NEW.tar.gz.sha256 )
Willy Tarreau62b71ee2016-05-10 12:04:13 +0200173
174echo "Extracting doc ..."
175git show "v$NEW:CHANGELOG" > "$TARGET_DIR/src/CHANGELOG"
176
177for i in "${DOC[@]}"; do
178 git show "v$NEW:$i" > "$TARGET_DIR/doc/${i#doc/}"
Willy Tarreau6fab3e62020-05-30 06:59:07 +0200179 $CMD_GZIP < "$TARGET_DIR/doc/${i#doc/}" > "$TARGET_DIR/doc/${i#doc/}.gz"
Willy Tarreau62b71ee2016-05-10 12:04:13 +0200180done
181
Willy Tarreauc9641a22022-05-30 15:34:51 +0200182if [ -x "${ARG0%/*}/make-releases-json" ]; then
183 # regenerate versions
184 "${ARG0%/*}/make-releases-json" -o "$TARGET_DIR/src/releases.json" "$TARGET_DIR"
185fi
186
Willy Tarreau62b71ee2016-05-10 12:04:13 +0200187echo "Done : ls -l ${TARGET_DIR}"
188( cd "$TARGET_DIR" ;
Tim Duesterhus3ce38112018-07-19 23:57:56 +0200189 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 +0200190)
191echo