blob: 8d99ace69510d83e9133ee41a34570aeae1efbaa [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
11USAGE="Usage: ${0##*/} [-y] [-b branch] [-n newver] DIR"
12TARGET_DIR=
13OUTPUT=
14SAYYES=
15BRANCH=
16DEVEL=
17NEW=
18DIR=
19DOC=( )
20
21die() {
22 [ "$#" -eq 0 ] || echo "$*" >&2
23 exit 1
24}
25
26err() {
27 echo "$*" >&2
28}
29
30quit() {
31 [ "$#" -eq 0 ] || echo "$*"
32 exit 0
33}
34
35while [ -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
43done
44
45if [ $# -ne 1 ]; then
46 die "$USAGE"
47fi
48
49DIR="$1" ; shift
50if [ -z "$DIR" ]; then
51 die "Missing target directory name."
52fi
53
54if [ -n "${DIR##/*}" ]; then
55 DIR="$PWD/$DIR"
56fi
57
58if [ ! -d "$DIR/." ]; then
59 die "Target directory doesn't exist : $DIR"
60fi
61
62if ! git rev-parse --verify -q HEAD >/dev/null; then
63 die "Failed to check git HEAD."
64fi
65
66# we want to go to the git top dir
67cd $(git rev-parse --show-toplevel)
68
69if [ "$(git rev-parse --verify -q HEAD)" != "$(git rev-parse --verify -q master)" ]; then
70 die "git HEAD doesn't match master branch."
71fi
72
73if [ "$(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
77fi
78
79if [ -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
88fi
89
90if ! git show-ref --tags "v$NEW" >/dev/null; then
91 die "git tag v$NEW doesn't exist, did you create the release ?"
92fi
93
94# determine the product branch from the new release
95if [ -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}}
101fi
102
103TARGET_DIR="$DIR/$BRANCH"
104if [ ! -d "$TARGET_DIR/." ]; then
105 die "Target directory doesn't contain branch $BRANCH. You may have to create it in $DIR."
106fi
107
108if [ -z "${NEW##*-dev*}" ]; then
109 DEVEL="/devel"
110fi
111
112if ! mkdir -p "$TARGET_DIR/src$DEVEL" "$TARGET_DIR/doc"; then
113 die "failed to create target directories."
114fi
115
116case "$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 ) ;;
122esac
123
124echo "Ready to produce the following files in $TARGET_DIR/ :"
125echo " haproxy-$NEW.tar.gz -> src${DEVEL}/"
126echo " CHANGELOG -> src/CHANGELOG"
127echo " ${DOC[@]} -> doc/*{,.gz}"
128echo
129
130git ls-tree -l --abbrev=12 "v$NEW" -- CHANGELOG "${DOC[@]}"
131
132if [ -z "$SAYYES" ]; then
133 echo "Press ENTER to continue or Ctrl-C to abort now!"
134 read
135fi
136
137echo "Archiving sources for version $NEW ..."
138rm -f "${TARGET_DIR}/src${DEVEL}/haproxy-${NEW}.tar.gz"{,.md5}
139if ! 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"
142fi
143
144( cd "$TARGET_DIR/src${DEVEL}" ; \
145 md5sum haproxy-$NEW.tar.gz > haproxy-$NEW.tar.gz.md5 )
146
147echo "Extracting doc ..."
148git show "v$NEW:CHANGELOG" > "$TARGET_DIR/src/CHANGELOG"
149
150for 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"
153done
154
155echo "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)
159echo