root / devtools / autopkg.sh @ 17ad5d37
History | View | Annotate | Download (4.5 kB)
1 |
#!/bin/bash |
---|---|
2 |
|
3 |
parse_git_branch() |
4 |
{ |
5 |
git branch 2> /dev/null | grep '^*' | sed 's/^*\ //g' |
6 |
} |
7 |
|
8 |
die() |
9 |
{ |
10 |
echo $* 1>&2 |
11 |
exit 1 |
12 |
} |
13 |
|
14 |
cleanup() |
15 |
{ |
16 |
trap - EXIT |
17 |
|
18 |
if [ ${#CLEANUP[*]} -gt 0 ]; then |
19 |
LAST_ELEMENT=$((${#CLEANUP[*]}-1)) |
20 |
REVERSE_INDEXES=$(seq ${LAST_ELEMENT} -1 0) |
21 |
for i in $REVERSE_INDEXES; do |
22 |
local cmd=${CLEANUP[$i]} |
23 |
$cmd |
24 |
done |
25 |
fi |
26 |
} |
27 |
|
28 |
add_cleanup() { |
29 |
local cmd="" |
30 |
for arg; do cmd+=$(printf "%q " "$arg"); done |
31 |
CLEANUP+=("$cmd") |
32 |
} |
33 |
|
34 |
|
35 |
add_checkpoint() |
36 |
{ |
37 |
commit=$(git reflog | head -n1 | cut -f 1 -d " ") |
38 |
add_cleanup git reset --hard $commit |
39 |
LASTCHECKPOINT=$commit |
40 |
} |
41 |
|
42 |
CLEANUP=( ) |
43 |
|
44 |
source devtools/autopkg.conf |
45 |
|
46 |
# The root of the git repository, no matter where we're called from |
47 |
TOPLEVEL="$(git rev-parse --show-toplevel)" |
48 |
CURRENT_BRANCH=$(parse_git_branch) |
49 |
|
50 |
LOCALBRANCH="$CURRENT_BRANCH" |
51 |
LOCALDEBIAN=$1 |
52 |
DEBIANBRANCH=${LOCALDEBIAN:- origin/$REMOTEDEBIAN} |
53 |
|
54 |
|
55 |
|
56 |
set -e |
57 |
trap cleanup EXIT |
58 |
|
59 |
cd "$TOPLEVEL" |
60 |
|
61 |
# Prerequisites: Test all important directories exist |
62 |
test -d "$PKGAREA" || die "Package area directory $PKGAREA missing" |
63 |
test -d "$BACKUPAREA" || die "Backup area directory $BACKUPAREA missing" |
64 |
|
65 |
# Prerequisite: Test the dialog utility is available |
66 |
dialog --help &>/dev/null || die "Could not run the 'dialog' utility" |
67 |
|
68 |
|
69 |
echo "##########################################################" |
70 |
echo "Will build packages" |
71 |
echo "under '$BUILDAREA'," |
72 |
echo "from local branch '$LOCALBRANCH'" |
73 |
echo "and debian branch '$DEBIANBRANCH'" |
74 |
echo "##########################################################" |
75 |
echo "Press Enter to continue..." |
76 |
read |
77 |
|
78 |
add_checkpoint |
79 |
|
80 |
# Create a temporary debian branch to do everything |
81 |
TMPDEBIAN=$(mktemp -u debian.XXX) |
82 |
|
83 |
git branch --track $TMPDEBIAN $DEBIANBRANCH |
84 |
#add_cleanup git branch -D $TMPDEBIAN |
85 |
|
86 |
git checkout $TMPDEBIAN |
87 |
add_cleanup git checkout $LOCALBRANCH |
88 |
|
89 |
add_checkpoint |
90 |
|
91 |
# Whether we are in snapshot or release mode |
92 |
snap=false |
93 |
mrgextra=-m |
94 |
dchextra=-R |
95 |
mrgmsg="Merge branch '$REMOTEUPSTREAM' into $REMOTEDEBIAN" |
96 |
dialog --yesno "Create Snapshot?" 5 20 && snap=true && dchextra=-S && mrgextra= && mrgmsg= |
97 |
|
98 |
# merge local branch into tmp branch with a nice commit message, |
99 |
# so it can be pushed as is to upstream debian |
100 |
git merge --no-edit $mrgextra ${mrgextra:+"$mrgmsg"} $LOCALBRANCH |
101 |
|
102 |
# auto edit Debian changelog depending on Snapshot or Release mode |
103 |
export EDITOR=/usr/bin/vim |
104 |
git-dch --debian-branch=$TMPDEBIAN --git-author --ignore-regex=".*" --multimaint-merge --since=HEAD $dchextra |
105 |
git add debian/changelog |
106 |
|
107 |
# get version from the changelog |
108 |
# we add a git tag here, so setup.py sdist works as expected |
109 |
# FIXME: This is a workaround for the way Synnefo packages determine |
110 |
# the versions for their Python packages |
111 |
version=$(IFS="()" ; read x v x < debian/changelog ; echo $v) |
112 |
if ! $snap; then |
113 |
git commit -s -a -m "Bump new upstream version" |
114 |
TAGFILE=$(mktemp -t tag.XXX) |
115 |
add_cleanup rm $TAGFILE |
116 |
dialog --inputbox "New Debian Tag: " 5 30 "debian/$version" 2>$TAGFILE |
117 |
git tag $(<$TAGFILE) |
118 |
add_cleanup git tag -d $(<$TAGFILE) |
119 |
fi |
120 |
|
121 |
|
122 |
for p in $PACKAGES; do |
123 |
|
124 |
cd $p |
125 |
python setup.py sdist |
126 |
grep "__version_vcs" -r . -l -I | xargs git add -f |
127 |
cd - |
128 |
|
129 |
done |
130 |
|
131 |
# Build all packages |
132 |
git-buildpackage --git-export-dir="$BUILDAREA" \ |
133 |
--git-upstream-branch=$LOCALBRANCH \ |
134 |
--git-debian-branch=$TMPDEBIAN \ |
135 |
--git-export=INDEX \ |
136 |
--git-ignore-new -sa |
137 |
|
138 |
# do some dirty backup |
139 |
# pkgarea might be needed by auto-deploy tool |
140 |
rm -f "$PKGAREA"/* || true |
141 |
cp -v "$BUILDAREA"/* "$PKGAREA"/ || true |
142 |
cp -v "$BUILDAREA"/* "$BACKUPAREA"/ || true |
143 |
|
144 |
echo "###############################################" |
145 |
echo "#### SUCCESS ####" |
146 |
echo "###############################################" |
147 |
|
148 |
git fetch origin |
149 |
#check if your local branch is up-to-date |
150 |
commits_behind=$(git rev-list $LOCALBRANCH..origin/$REMOTEUPSTREAM | wc -l) |
151 |
if [ $commits_behind -ne 0 ]; then |
152 |
die "Your local branch is outdated!! Please run: git pull --rebase origin/$REMOTEUPSTREAM" |
153 |
fi |
154 |
commits_behind=$(git rev-list $DEBIANBRANCH..origin/$REMOTEDEBIAN | wc -l) |
155 |
if [ $commits_behind -ne 0 ]; then |
156 |
die "Your debian branch is outdated!! Please run: git pull --rebase origin/$REMOTEDEBIAN" |
157 |
fi |
158 |
|
159 |
trap - EXIT |
160 |
|
161 |
# Remove the added versions.py files |
162 |
git reset --hard HEAD |
163 |
# here we can push the commits to the remote debian branch as they are |
164 |
|
165 |
if ! $snap; then |
166 |
TAGS="--tags" |
167 |
fi |
168 |
echo "git push $TAGS origin $TMPDEBIAN:$REMOTEDEBIAN" |
169 |
echo "git checkout $LOCALBRANCH" |
170 |
echo "git push $TAGS origin $LOCALBRANCH:$REMOTEUPSTREAM" |
171 |
echo |
172 |
|
173 |
exit 0 |