root / devtools / autopkg.sh @ c9b113ac
History | View | Annotate | Download (6.3 kB)
1 |
#!/bin/bash |
---|---|
2 |
|
3 |
# Copyright 2012 GRNET S.A. All rights reserved. |
4 |
# |
5 |
# Redistribution and use in source and binary forms, with or |
6 |
# without modification, are permitted provided that the following |
7 |
# conditions are met: |
8 |
# |
9 |
# 1. Redistributions of source code must retain the above |
10 |
# copyright notice, this list of conditions and the following |
11 |
# disclaimer. |
12 |
# |
13 |
# 2. Redistributions in binary form must reproduce the above |
14 |
# copyright notice, this list of conditions and the following |
15 |
# disclaimer in the documentation and/or other materials |
16 |
# provided with the distribution. |
17 |
# |
18 |
# THIS SOFTWARE IS PROVIDED BY GRNET S.A. ``AS IS'' AND ANY EXPRESS |
19 |
# OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED |
20 |
# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR |
21 |
# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL GRNET S.A OR |
22 |
# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
23 |
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
24 |
# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF |
25 |
# USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED |
26 |
# AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT |
27 |
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN |
28 |
# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
29 |
# POSSIBILITY OF SUCH DAMAGE. |
30 |
# |
31 |
# The views and conclusions contained in the software and |
32 |
# documentation are those of the authors and should not be |
33 |
# interpreted as representing official policies, either expressed |
34 |
# or implied, of GRNET S.A. |
35 |
|
36 |
parse_git_branch() |
37 |
{ |
38 |
git branch 2> /dev/null | grep '^*' | sed 's/^*\ //g' |
39 |
} |
40 |
|
41 |
die() |
42 |
{ |
43 |
echo $* 1>&2 |
44 |
exit 1 |
45 |
} |
46 |
|
47 |
cleanup() |
48 |
{ |
49 |
trap - EXIT |
50 |
|
51 |
if [ ${#CLEANUP[*]} -gt 0 ]; then |
52 |
LAST_ELEMENT=$((${#CLEANUP[*]}-1)) |
53 |
REVERSE_INDEXES=$(seq ${LAST_ELEMENT} -1 0) |
54 |
for i in $REVERSE_INDEXES; do |
55 |
local cmd=${CLEANUP[$i]} |
56 |
$cmd |
57 |
done |
58 |
fi |
59 |
} |
60 |
|
61 |
add_cleanup() { |
62 |
local cmd="" |
63 |
for arg; do cmd+=$(printf "%q " "$arg"); done |
64 |
CLEANUP+=("$cmd") |
65 |
} |
66 |
|
67 |
|
68 |
add_checkpoint() |
69 |
{ |
70 |
commit=$(git reflog | head -n1 | cut -f 1 -d " ") |
71 |
add_cleanup git reset --hard $commit |
72 |
LASTCHECKPOINT=$commit |
73 |
} |
74 |
|
75 |
CLEANUP=( ) |
76 |
|
77 |
source devtools/autopkg.conf |
78 |
|
79 |
# The root of the git repository, no matter where we're called from |
80 |
TOPLEVEL="$(git rev-parse --show-toplevel)" |
81 |
CURRENT_BRANCH=$(parse_git_branch) |
82 |
|
83 |
LOCALBRANCH="$CURRENT_BRANCH" |
84 |
LOCALDEBIAN=$1 |
85 |
DEBIANBRANCH=${LOCALDEBIAN:- origin/$REMOTEDEBIAN} |
86 |
|
87 |
MODIFIED=$(git status --short | grep -v "??") |
88 |
if [[ -n $MODIFIED ]]; then |
89 |
echo "error: Repository is dirty. Commit your local changes." |
90 |
exit 1 |
91 |
fi |
92 |
|
93 |
|
94 |
set -e |
95 |
trap cleanup EXIT |
96 |
|
97 |
cd "$TOPLEVEL" |
98 |
|
99 |
# Prerequisites: Test all important directories exist |
100 |
test -d "$PKGAREA" || die "Package area directory $PKGAREA missing" |
101 |
test -d "$BACKUPAREA" || die "Backup area directory $BACKUPAREA missing" |
102 |
|
103 |
# Prerequisite: Test the dialog utility is available |
104 |
dialog --help &>/dev/null || die "Could not run the 'dialog' utility" |
105 |
|
106 |
|
107 |
echo "##########################################################" |
108 |
echo "Will build packages" |
109 |
echo "under '$BUILDAREA'," |
110 |
echo "from local branch '$LOCALBRANCH'" |
111 |
echo "and debian branch '$DEBIANBRANCH'" |
112 |
echo "##########################################################" |
113 |
echo "Press Enter to continue..." |
114 |
read |
115 |
|
116 |
add_checkpoint |
117 |
|
118 |
# Create a temporary debian branch to do everything |
119 |
TMPDEBIAN=$(mktemp -u debian.XXX) |
120 |
|
121 |
git branch --track $TMPDEBIAN $DEBIANBRANCH |
122 |
#add_cleanup git branch -D $TMPDEBIAN |
123 |
|
124 |
git checkout $TMPDEBIAN |
125 |
add_cleanup git checkout $LOCALBRANCH |
126 |
|
127 |
add_checkpoint |
128 |
|
129 |
# Whether we are in snapshot or release mode |
130 |
snap=false |
131 |
mrgextra=-m |
132 |
dchextra=-R |
133 |
mrgmsg="Merge branch '$REMOTEUPSTREAM' into $REMOTEDEBIAN" |
134 |
dialog --yesno "Create Snapshot?" 5 20 && snap=true && GITFLOW_BUILD_MODE=snapshot && dchextra=-S && mrgextra= && mrgmsg= |
135 |
|
136 |
# merge local branch into tmp branch with a nice commit message, |
137 |
# so it can be pushed as is to upstream debian |
138 |
GIT_MERGE_AUTOEDIT=no |
139 |
git merge $mrgextra ${mrgextra:+"$mrgmsg"} $LOCALBRANCH |
140 |
|
141 |
# auto edit Debian changelog depending on Snapshot or Release mode |
142 |
export EDITOR=/usr/bin/vim |
143 |
|
144 |
# use the devtools to determine Debian version |
145 |
export GITFLOW_BUILD_MODE |
146 |
version=$(devtools/version.py debian) |
147 |
git-dch --debian-branch=$TMPDEBIAN --git-author --ignore-regex=".*" --multimaint-merge --since=HEAD -N $version |
148 |
git add debian/changelog |
149 |
|
150 |
# get version from the changelog |
151 |
# we add a git tag here, so setup.py sdist works as expected |
152 |
# FIXME: This is a workaround for the way Synnefo packages determine |
153 |
# the versions for their Python packages |
154 |
version=$(IFS="()" ; read x v x < debian/changelog ; echo $v) |
155 |
if ! $snap; then |
156 |
git commit -s -a -m "Bump new upstream version" |
157 |
TAGFILE=$(mktemp -t tag.XXX) |
158 |
add_cleanup rm $TAGFILE |
159 |
dialog --inputbox "New Debian Tag: " 5 30 "debian/$version" 2>$TAGFILE |
160 |
git tag $(<$TAGFILE) |
161 |
add_cleanup git tag -d $(<$TAGFILE) |
162 |
fi |
163 |
|
164 |
|
165 |
for p in $PACKAGES; do |
166 |
|
167 |
cd $p |
168 |
python setup.py sdist |
169 |
grep "__version_vcs" -r . -l -I | xargs git add -f |
170 |
cd - |
171 |
|
172 |
done |
173 |
|
174 |
# Build all packages |
175 |
git-buildpackage --git-export-dir="$BUILDAREA" \ |
176 |
--git-upstream-branch=$LOCALBRANCH \ |
177 |
--git-debian-branch=$TMPDEBIAN \ |
178 |
--git-export=INDEX \ |
179 |
--git-ignore-new -sa |
180 |
|
181 |
# do some dirty backup |
182 |
# pkgarea might be needed by auto-deploy tool |
183 |
rm -f "$PKGAREA"/* || true |
184 |
cp -v "$BUILDAREA"/* "$PKGAREA"/ || true |
185 |
cp -v "$BUILDAREA"/* "$BACKUPAREA"/ || true |
186 |
|
187 |
echo "###############################################" |
188 |
echo "#### SUCCESS ####" |
189 |
echo "###############################################" |
190 |
|
191 |
git fetch origin |
192 |
#check if your local branch is up-to-date |
193 |
commits_behind=$(git rev-list $LOCALBRANCH..origin/$REMOTEUPSTREAM | wc -l) |
194 |
if [ $commits_behind -ne 0 ]; then |
195 |
die "Your local branch is outdated!! Please run: git pull --rebase origin/$REMOTEUPSTREAM" |
196 |
fi |
197 |
commits_behind=$(git rev-list $DEBIANBRANCH..origin/$REMOTEDEBIAN | wc -l) |
198 |
if [ $commits_behind -ne 0 ]; then |
199 |
die "Your debian branch is outdated!! Please run: git pull --rebase origin/$REMOTEDEBIAN" |
200 |
fi |
201 |
|
202 |
trap - EXIT |
203 |
|
204 |
# Remove the added versions.py files |
205 |
git reset --hard HEAD |
206 |
# here we can push the commits to the remote debian branch as they are |
207 |
|
208 |
if ! $snap; then |
209 |
TAGS="--tags" |
210 |
fi |
211 |
echo "git push $TAGS origin $TMPDEBIAN:$REMOTEDEBIAN" |
212 |
echo "git checkout $LOCALBRANCH" |
213 |
echo "git push $TAGS origin $LOCALBRANCH:$REMOTEUPSTREAM" |
214 |
echo |
215 |
|
216 |
exit 0 |