blob: 6a615a6f1adf4b19ec6046c5419ea46a128c6bf3 [file] [log] [blame]
Willy Tarreau62b71ee2016-05-10 12:04:13 +02001#!/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 Tarreaubd698912017-06-09 15:57:31 +020011USAGE="Usage: ${0##*/} [-a] [-q] [-y] [-b branch] [-n newver] DIR"
Willy Tarreau62b71ee2016-05-10 12:04:13 +020012TARGET_DIR=
13OUTPUT=
14SAYYES=
15BRANCH=
16DEVEL=
Willy Tarreaubd698912017-06-09 15:57:31 +020017QUIET=
Willy Tarreau7ca88152017-06-09 15:54:39 +020018AUTO=
Willy Tarreau62b71ee2016-05-10 12:04:13 +020019NEW=
20DIR=
21DOC=( )
22
23die() {
24 [ "$#" -eq 0 ] || echo "$*" >&2
25 exit 1
26}
27
28err() {
29 echo "$*" >&2
30}
31
32quit() {
Willy Tarreaubd698912017-06-09 15:57:31 +020033 [ "$#" -eq 0 -o -n "$QUIET" ] || echo "$*"
Willy Tarreau62b71ee2016-05-10 12:04:13 +020034 exit 0
35}
36
37while [ -n "$1" -a -z "${1##-*}" ]; do
38 case "$1" in
Willy Tarreau7ca88152017-06-09 15:54:39 +020039 -a) AUTO=1 ; shift ;;
Willy Tarreaubd698912017-06-09 15:57:31 +020040 -q) QUIET=1 ; shift ;;
Willy Tarreau62b71ee2016-05-10 12:04:13 +020041 -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
47done
48
49if [ $# -ne 1 ]; then
50 die "$USAGE"
51fi
52
53DIR="$1" ; shift
54if [ -z "$DIR" ]; then
55 die "Missing target directory name."
56fi
57
58if [ -n "${DIR##/*}" ]; then
59 DIR="$PWD/$DIR"
60fi
61
62if [ ! -d "$DIR/." ]; then
63 die "Target directory doesn't exist : $DIR"
64fi
65
66if ! git rev-parse --verify -q HEAD >/dev/null; then
67 die "Failed to check git HEAD."
68fi
69
70# we want to go to the git top dir
Willy Tarreau600cb572017-06-09 15:36:02 +020071toplvl=$(git rev-parse --show-toplevel)
72if [ -n "$toplvl" ]; then
73 cd "$toplvl"
74fi
75
76# ensure that a master branch exists here
77if [ -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)."
79fi
Willy Tarreau62b71ee2016-05-10 12:04:13 +020080
81if [ "$(git rev-parse --verify -q HEAD)" != "$(git rev-parse --verify -q master)" ]; then
82 die "git HEAD doesn't match master branch."
83fi
84
Willy Tarreau600cb572017-06-09 15:36:02 +020085if [ "$(git diff HEAD 2>/dev/null |wc -c)" != 0 ]; then
Willy Tarreau62b71ee2016-05-10 12:04:13 +020086 err "You appear to have uncommitted local changes, please commit them first :"
87 git status -s -uno >&2
88 die
89fi
90
Willy Tarreau7ca88152017-06-09 15:54:39 +020091if [ -z "$NEW" -o -n "$AUTO" ]; then
Willy Tarreau62b71ee2016-05-10 12:04:13 +020092 if [ -z "$NEW" ]; then
Willy Tarreau7ca88152017-06-09 15:54:39 +020093 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 Tarreau62b71ee2016-05-10 12:04:13 +020098 fi
Willy Tarreau7ca88152017-06-09 15:54:39 +020099
Willy Tarreau62b71ee2016-05-10 12:04:13 +0200100 if [ "$(git describe --tags HEAD)" != "v$NEW" ]; then
Willy Tarreau7ca88152017-06-09 15:54:39 +0200101 if [ -n "$AUTO" ]; then
102 quit "Not tagged, nothing to do."
103 fi
Willy Tarreau62b71ee2016-05-10 12:04:13 +0200104 die "Current version doesn't seem tagged, it reports $(git describe --tags "v$NEW"). Did you release it ?"
105 fi
106fi
107
108if ! git show-ref --tags "v$NEW" >/dev/null; then
109 die "git tag v$NEW doesn't exist, did you create the release ?"
110fi
111
112# determine the product branch from the new release
113if [ -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}}
119fi
120
121TARGET_DIR="$DIR/$BRANCH"
122if [ ! -d "$TARGET_DIR/." ]; then
123 die "Target directory doesn't contain branch $BRANCH. You may have to create it in $DIR."
124fi
125
126if [ -z "${NEW##*-dev*}" ]; then
127 DEVEL="/devel"
128fi
129
Willy Tarreau7ca88152017-06-09 15:54:39 +0200130if [ -n "$AUTO" -a -e "$TARGET_DIR/src${DEVEL}/haproxy-$NEW.tar.gz.md5" ]; then
131 quit "Version $NEW Already released."
132fi
133
Willy Tarreau62b71ee2016-05-10 12:04:13 +0200134if ! mkdir -p "$TARGET_DIR/src$DEVEL" "$TARGET_DIR/doc"; then
135 die "failed to create target directories."
136fi
137
138case "$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 Tarreau6cc21182016-11-09 23:21:47 +0100143 *) DOC=( doc/{coding-style,intro,management,configuration,proxy-protocol,lua,SPOE}.txt ) ;;
Willy Tarreau62b71ee2016-05-10 12:04:13 +0200144esac
145
Willy Tarreau7ca88152017-06-09 15:54:39 +0200146if [ -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 Tarreau62b71ee2016-05-10 12:04:13 +0200152
Willy Tarreau7ca88152017-06-09 15:54:39 +0200153 git ls-tree -l --abbrev=12 "v$NEW" -- CHANGELOG "${DOC[@]}"
Willy Tarreau62b71ee2016-05-10 12:04:13 +0200154
Willy Tarreau7ca88152017-06-09 15:54:39 +0200155 if [ -z "$SAYYES" ]; then
156 echo "Press ENTER to continue or Ctrl-C to abort now!"
157 read
158 fi
Willy Tarreau62b71ee2016-05-10 12:04:13 +0200159fi
160
161echo "Archiving sources for version $NEW ..."
Tim Duesterhus3ce38112018-07-19 23:57:56 +0200162rm -f "${TARGET_DIR}/src${DEVEL}/haproxy-${NEW}.tar.gz"{,.md5,.sha256}
Willy Tarreau62b71ee2016-05-10 12:04:13 +0200163if ! 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"
166fi
167
168( cd "$TARGET_DIR/src${DEVEL}" ; \
Tim Duesterhus3ce38112018-07-19 23:57:56 +0200169 md5sum haproxy-$NEW.tar.gz > haproxy-$NEW.tar.gz.md5 ; \
170 sha256sum haproxy-$NEW.tar.gz > haproxy-$NEW.tar.gz.sha256 )
Willy Tarreau62b71ee2016-05-10 12:04:13 +0200171
172echo "Extracting doc ..."
173git show "v$NEW:CHANGELOG" > "$TARGET_DIR/src/CHANGELOG"
174
175for 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"
178done
179
180echo "Done : ls -l ${TARGET_DIR}"
181( cd "$TARGET_DIR" ;
Tim Duesterhus3ce38112018-07-19 23:57:56 +0200182 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 +0200183)
184echo