blob: 9066d4add79d7cc309ae64cbdfaff48a18de36d5 [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
Willy Tarreau267970e2023-05-24 22:48:14 +020025# need to have group write on emitted files for others to update
26umask 002
27
Willy Tarreau62b71ee2016-05-10 12:04:13 +020028die() {
29 [ "$#" -eq 0 ] || echo "$*" >&2
30 exit 1
31}
32
33err() {
34 echo "$*" >&2
35}
36
37quit() {
Willy Tarreaubd698912017-06-09 15:57:31 +020038 [ "$#" -eq 0 -o -n "$QUIET" ] || echo "$*"
Willy Tarreau62b71ee2016-05-10 12:04:13 +020039 exit 0
40}
41
42while [ -n "$1" -a -z "${1##-*}" ]; do
43 case "$1" in
Willy Tarreau7ca88152017-06-09 15:54:39 +020044 -a) AUTO=1 ; shift ;;
Willy Tarreaubd698912017-06-09 15:57:31 +020045 -q) QUIET=1 ; shift ;;
Willy Tarreau62b71ee2016-05-10 12:04:13 +020046 -y) SAYYES=1 ; shift ;;
47 -b) BRANCH="$2" ; shift 2 ;;
48 -n) NEW="$2" ; shift 2 ;;
49 -h|--help) quit "$USAGE" ;;
50 *) die "$USAGE" ;;
51 esac
52done
53
54if [ $# -ne 1 ]; then
55 die "$USAGE"
56fi
57
58DIR="$1" ; shift
59if [ -z "$DIR" ]; then
60 die "Missing target directory name."
61fi
62
63if [ -n "${DIR##/*}" ]; then
64 DIR="$PWD/$DIR"
65fi
66
67if [ ! -d "$DIR/." ]; then
68 die "Target directory doesn't exist : $DIR"
69fi
70
71if ! git rev-parse --verify -q HEAD >/dev/null; then
72 die "Failed to check git HEAD."
73fi
74
75# we want to go to the git top dir
Willy Tarreau600cb572017-06-09 15:36:02 +020076toplvl=$(git rev-parse --show-toplevel)
77if [ -n "$toplvl" ]; then
78 cd "$toplvl"
79fi
80
81# ensure that a master branch exists here
82if [ -z "$(git rev-parse --verify -q master 2>/dev/null)" ]; then
83 die "Current directory doesn't seem to be a valid git directory (no master branch)."
84fi
Willy Tarreau62b71ee2016-05-10 12:04:13 +020085
86if [ "$(git rev-parse --verify -q HEAD)" != "$(git rev-parse --verify -q master)" ]; then
87 die "git HEAD doesn't match master branch."
88fi
89
Willy Tarreau600cb572017-06-09 15:36:02 +020090if [ "$(git diff HEAD 2>/dev/null |wc -c)" != 0 ]; then
Willy Tarreau62b71ee2016-05-10 12:04:13 +020091 err "You appear to have uncommitted local changes, please commit them first :"
92 git status -s -uno >&2
93 die
94fi
95
Willy Tarreau7ca88152017-06-09 15:54:39 +020096if [ -z "$NEW" -o -n "$AUTO" ]; then
Willy Tarreau62b71ee2016-05-10 12:04:13 +020097 if [ -z "$NEW" ]; then
Willy Tarreau7ca88152017-06-09 15:54:39 +020098 NEW="$(git describe --tags HEAD --abbrev=0)"
99 NEW="${NEW#v}"
100 if [ -z "$NEW" ]; then
101 die "Fatal: cannot determine new version, please specify it."
102 fi
Willy Tarreau62b71ee2016-05-10 12:04:13 +0200103 fi
Willy Tarreau7ca88152017-06-09 15:54:39 +0200104
Willy Tarreau62b71ee2016-05-10 12:04:13 +0200105 if [ "$(git describe --tags HEAD)" != "v$NEW" ]; then
Willy Tarreau7ca88152017-06-09 15:54:39 +0200106 if [ -n "$AUTO" ]; then
107 quit "Not tagged, nothing to do."
108 fi
Willy Tarreau62b71ee2016-05-10 12:04:13 +0200109 die "Current version doesn't seem tagged, it reports $(git describe --tags "v$NEW"). Did you release it ?"
110 fi
111fi
112
113if ! git show-ref --tags "v$NEW" >/dev/null; then
114 die "git tag v$NEW doesn't exist, did you create the release ?"
115fi
116
117# determine the product branch from the new release
118if [ -z "$BRANCH" ]; then
119 subvers=${NEW#[0-9]*.[0-9]*[-.]*[0-9].}
120 [ "${subvers}" = "${NEW}" ] && subvers=""
121 major=${NEW%.$subvers}
122 branch_ext=${major#*[0-9].*[0-9]}
123 BRANCH=${major%${branch_ext}}
124fi
125
126TARGET_DIR="$DIR/$BRANCH"
127if [ ! -d "$TARGET_DIR/." ]; then
128 die "Target directory doesn't contain branch $BRANCH. You may have to create it in $DIR."
129fi
130
131if [ -z "${NEW##*-dev*}" ]; then
132 DEVEL="/devel"
133fi
134
Willy Tarreau7ca88152017-06-09 15:54:39 +0200135if [ -n "$AUTO" -a -e "$TARGET_DIR/src${DEVEL}/haproxy-$NEW.tar.gz.md5" ]; then
136 quit "Version $NEW Already released."
137fi
138
Willy Tarreau62b71ee2016-05-10 12:04:13 +0200139if ! mkdir -p "$TARGET_DIR/src$DEVEL" "$TARGET_DIR/doc"; then
140 die "failed to create target directories."
141fi
142
143case "$BRANCH" in
144 1.3) DOC=( doc/{haproxy-en,haproxy-fr,configuration,architecture}.txt ) ;;
145 1.4) DOC=( doc/{haproxy-en,haproxy-fr,configuration}.txt ) ;;
146 1.5) DOC=( doc/{coding-style,configuration,proxy-protocol}.txt ) ;;
147 1.6) DOC=( doc/{coding-style,intro,management,configuration,proxy-protocol,lua}.txt ) ;;
Willy Tarreau6cc21182016-11-09 23:21:47 +0100148 *) DOC=( doc/{coding-style,intro,management,configuration,proxy-protocol,lua,SPOE}.txt ) ;;
Willy Tarreau62b71ee2016-05-10 12:04:13 +0200149esac
150
Willy Tarreau7ca88152017-06-09 15:54:39 +0200151if [ -z "$AUTO" ]; then
152 echo "Ready to produce the following files in $TARGET_DIR/ :"
153 echo " haproxy-$NEW.tar.gz -> src${DEVEL}/"
154 echo " CHANGELOG -> src/CHANGELOG"
155 echo " ${DOC[@]} -> doc/*{,.gz}"
156 echo
Willy Tarreau62b71ee2016-05-10 12:04:13 +0200157
Willy Tarreau7ca88152017-06-09 15:54:39 +0200158 git ls-tree -l --abbrev=12 "v$NEW" -- CHANGELOG "${DOC[@]}"
Willy Tarreau62b71ee2016-05-10 12:04:13 +0200159
Willy Tarreau7ca88152017-06-09 15:54:39 +0200160 if [ -z "$SAYYES" ]; then
161 echo "Press ENTER to continue or Ctrl-C to abort now!"
162 read
163 fi
Willy Tarreau62b71ee2016-05-10 12:04:13 +0200164fi
165
166echo "Archiving sources for version $NEW ..."
Tim Duesterhus3ce38112018-07-19 23:57:56 +0200167rm -f "${TARGET_DIR}/src${DEVEL}/haproxy-${NEW}.tar.gz"{,.md5,.sha256}
Willy Tarreau62b71ee2016-05-10 12:04:13 +0200168if ! git archive --format=tar --prefix="haproxy-${NEW}/" "v$NEW" | \
Willy Tarreau6fab3e62020-05-30 06:59:07 +0200169 $CMD_GZIP > "${TARGET_DIR}/src${DEVEL}/haproxy-${NEW}.tar.gz"; then
Willy Tarreau62b71ee2016-05-10 12:04:13 +0200170 die "Failed to produce the tar.gz archive"
171fi
172
173( cd "$TARGET_DIR/src${DEVEL}" ; \
Tim Duesterhus3ce38112018-07-19 23:57:56 +0200174 md5sum haproxy-$NEW.tar.gz > haproxy-$NEW.tar.gz.md5 ; \
175 sha256sum haproxy-$NEW.tar.gz > haproxy-$NEW.tar.gz.sha256 )
Willy Tarreau62b71ee2016-05-10 12:04:13 +0200176
177echo "Extracting doc ..."
178git show "v$NEW:CHANGELOG" > "$TARGET_DIR/src/CHANGELOG"
179
180for i in "${DOC[@]}"; do
181 git show "v$NEW:$i" > "$TARGET_DIR/doc/${i#doc/}"
Willy Tarreau6fab3e62020-05-30 06:59:07 +0200182 $CMD_GZIP < "$TARGET_DIR/doc/${i#doc/}" > "$TARGET_DIR/doc/${i#doc/}.gz"
Willy Tarreau62b71ee2016-05-10 12:04:13 +0200183done
184
Willy Tarreauc9641a22022-05-30 15:34:51 +0200185if [ -x "${ARG0%/*}/make-releases-json" ]; then
186 # regenerate versions
187 "${ARG0%/*}/make-releases-json" -o "$TARGET_DIR/src/releases.json" "$TARGET_DIR"
188fi
189
Willy Tarreau62b71ee2016-05-10 12:04:13 +0200190echo "Done : ls -l ${TARGET_DIR}"
191( cd "$TARGET_DIR" ;
Tim Duesterhus3ce38112018-07-19 23:57:56 +0200192 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 +0200193)
194echo