-
Notifications
You must be signed in to change notification settings - Fork 5
/
script.sh
317 lines (257 loc) · 10.3 KB
/
script.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
#!/bin/sh
# _ _ _ _ _ _
# | |_ _ __ __ ___ _(_)___ __| | ___| |__ (_) __ _ _ __ _ __ ___| |_
# | __| '__/ _` \ \ / / / __| / _` |/ _ \ '_ \| |/ _` | '_ \ | '_ \ / _ \ __|
# | |_| | | (_| |\ V /| \__ \| (_| | __/ |_) | | (_| | | | |_| | | | __/ |_
# \__|_| \__,_| \_/ |_|___(_)__,_|\___|_.__/|_|\__,_|_| |_(_)_| |_|\___|\__|
#
#
# Documentation: <http://travis.debian.net>
## Copyright ##################################################################
#
# Copyright © 2015, 2016 Chris Lamb <[email protected]>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
## Functions ##################################################################
set -eu
Info () {
echo "I: ${*}" >&2
}
Error () {
echo "E: ${*}" >&2
}
## Configuration ##############################################################
SOURCE="$(dpkg-parsechangelog | awk '/^Source:/ { print $2 }')"
VERSION="$(dpkg-parsechangelog | awk '/^Version:/ { print $2 }')"
Info "Starting build of ${SOURCE} using travis.debian.net"
TRAVIS_DEBIAN_MIRROR="${TRAVIS_DEBIAN_MIRROR:-http://ftp.de.debian.org/debian}"
TRAVIS_DEBIAN_BUILD_DIR="${TRAVIS_DEBIAN_BUILD_DIR:-/build}"
TRAVIS_DEBIAN_TARGET_DIR="${TRAVIS_DEBIAN_TARGET_DIR:-../}"
TRAVIS_DEBIAN_NETWORK_ENABLED="${TRAVIS_DEBIAN_NETWORK_ENABLED:-false}"
TRAVIS_DEBIAN_INCREMENT_VERSION_NUMBER="${TRAVIS_DEBIAN_INCREMENT_VERSION_NUMBER:-false}"
#### Distribution #############################################################
TRAVIS_DEBIAN_BACKPORTS="${TRAVIS_DEBIAN_BACKPORTS:-false}"
TRAVIS_DEBIAN_EXPERIMENTAL="${TRAVIS_DEBIAN_EXPERIMENTAL:-false}"
if [ "${TRAVIS_DEBIAN_DISTRIBUTION:-}" = "" ]
then
Info "Automatically detecting distribution"
TRAVIS_DEBIAN_DISTRIBUTION="${TRAVIS_BRANCH:-}"
if [ "${TRAVIS_DEBIAN_DISTRIBUTION:-}" = "" ]
then
TRAVIS_DEBIAN_DISTRIBUTION="$(git rev-parse --abbrev-ref HEAD 2>/dev/null || echo master)"
fi
TRAVIS_DEBIAN_DISTRIBUTION="${TRAVIS_DEBIAN_DISTRIBUTION##debian/}"
# Detect backports
case "${TRAVIS_DEBIAN_DISTRIBUTION}" in
*-backports)
TRAVIS_DEBIAN_BACKPORTS="true"
TRAVIS_DEBIAN_DISTRIBUTION="${TRAVIS_DEBIAN_DISTRIBUTION%%-backports}"
;;
backports/*)
TRAVIS_DEBIAN_BACKPORTS="true"
TRAVIS_DEBIAN_DISTRIBUTION="${TRAVIS_DEBIAN_DISTRIBUTION##backports/}"
;;
esac
fi
# Detect codenames
case "${TRAVIS_DEBIAN_DISTRIBUTION}" in
oldstable)
TRAVIS_DEBIAN_DISTRIBUTION="wheezy"
;;
stable)
TRAVIS_DEBIAN_DISTRIBUTION="jessie"
;;
testing)
TRAVIS_DEBIAN_DISTRIBUTION="stretch"
;;
unstable|master)
TRAVIS_DEBIAN_DISTRIBUTION="sid"
;;
experimental)
TRAVIS_DEBIAN_DISTRIBUTION="sid"
TRAVIS_DEBIAN_EXPERIMENTAL="true"
;;
esac
case "${TRAVIS_DEBIAN_DISTRIBUTION}" in
wheezy)
TRAVIS_DEBIAN_GIT_BUILDPACKAGE="${TRAVIS_DEBIAN_GIT_BUILDPACKAGE:-git-buildpackage}"
TRAVIS_DEBIAN_GIT_BUILDPACKAGE_OPTIONS="${TRAVIS_DEBIAN_GIT_BUILDPACKAGE_OPTIONS:-}"
;;
*)
TRAVIS_DEBIAN_GIT_BUILDPACKAGE="${TRAVIS_DEBIAN_GIT_BUILDPACKAGE:-gbp buildpackage}"
TRAVIS_DEBIAN_GIT_BUILDPACKAGE_OPTIONS="${TRAVIS_DEBIAN_GIT_BUILDPACKAGE_OPTIONS:---git-submodules}"
;;
esac
case "${TRAVIS_DEBIAN_DISTRIBUTION}" in
wheezy|jessie)
TRAVIS_DEBIAN_AUTOPKGTEST_RUN="${TRAVIS_DEBIAN_AUTOPKGTEST_RUN:-adt-run}"
TRAVIS_DEBIAN_AUTOPKGTEST_SEPARATOR="${TRAVIS_DEBIAN_AUTOPKGTEST_SEPARATOR:----}"
;;
*)
TRAVIS_DEBIAN_AUTOPKGTEST_RUN="${TRAVIS_DEBIAN_AUTOPKGTEST_RUN:-autopkgtest}"
TRAVIS_DEBIAN_AUTOPKGTEST_SEPARATOR="${TRAVIS_DEBIAN_AUTOPKGTEST_SEPARATOR:---}"
;;
esac
case "${TRAVIS_DEBIAN_DISTRIBUTION}" in
sid)
TRAVIS_DEBIAN_SECURITY_UPDATES="${TRAVIS_DEBIAN_SECURITY_UPDATES:-false}"
;;
*)
TRAVIS_DEBIAN_SECURITY_UPDATES="${TRAVIS_DEBIAN_SECURITY_UPDATES:-true}"
;;
esac
## Detect autopkgtest tests ###################################################
if [ -e "debian/tests/control" ] || grep -E '^(XS-)?Testsuite: autopkgtest' debian/control
then
TRAVIS_DEBIAN_AUTOPKGTEST="${TRAVIS_DEBIAN_AUTOPKGTEST:-true}"
else
TRAVIS_DEBIAN_AUTOPKGTEST="${TRAVIS_DEBIAN_AUTOPKGTEST:-false}"
fi
## Print configuration ########################################################
Info "Using distribution: ${TRAVIS_DEBIAN_DISTRIBUTION}"
Info "Backports enabled: ${TRAVIS_DEBIAN_BACKPORTS}"
Info "Experimental enabled: ${TRAVIS_DEBIAN_EXPERIMENTAL}"
Info "Security updates enabled: ${TRAVIS_DEBIAN_SECURITY_UPDATES}"
Info "Will use extra repository: ${TRAVIS_DEBIAN_EXTRA_REPOSITORY:-<not set>}"
Info "Extra repository's key URL: ${TRAVIS_DEBIAN_EXTRA_REPOSITORY_GPG_URL:-<not set>}"
Info "Will build under: ${TRAVIS_DEBIAN_BUILD_DIR}"
Info "Will store results under: ${TRAVIS_DEBIAN_TARGET_DIR}"
Info "Using mirror: ${TRAVIS_DEBIAN_MIRROR}"
Info "Network enabled during build: ${TRAVIS_DEBIAN_NETWORK_ENABLED}"
Info "Builder command: ${TRAVIS_DEBIAN_GIT_BUILDPACKAGE}"
Info "Builder command options: ${TRAVIS_DEBIAN_GIT_BUILDPACKAGE_OPTIONS}"
Info "Increment version number: ${TRAVIS_DEBIAN_INCREMENT_VERSION_NUMBER}"
Info "Run autopkgtests after build: ${TRAVIS_DEBIAN_AUTOPKGTEST}"
Info "DEB_BUILD_OPTIONS: ${DEB_BUILD_OPTIONS:-<not set>}"
## Increment version number ###################################################
if [ "${TRAVIS_DEBIAN_INCREMENT_VERSION_NUMBER}" = true ]
then
cat >debian/changelog.new <<EOF
${SOURCE} (${VERSION}+travis${TRAVIS_BUILD_NUMBER}) UNRELEASED; urgency=medium
* Automatic build.
-- travis.debian.net <nobody@nobody> $(date --utc -R)
EOF
cat <debian/changelog >>debian/changelog.new
mv debian/changelog.new debian/changelog
git add debian/changelog
git commit -m "Incrementing version number."
fi
## Build ######################################################################
cat >Dockerfile <<EOF
FROM debian:${TRAVIS_DEBIAN_DISTRIBUTION}
RUN echo "deb ${TRAVIS_DEBIAN_MIRROR} ${TRAVIS_DEBIAN_DISTRIBUTION} main" > /etc/apt/sources.list
RUN echo "deb-src ${TRAVIS_DEBIAN_MIRROR} ${TRAVIS_DEBIAN_DISTRIBUTION} main" >> /etc/apt/sources.list
EOF
if [ "${TRAVIS_DEBIAN_BACKPORTS}" = true ]
then
cat >>Dockerfile <<EOF
RUN echo "deb ${TRAVIS_DEBIAN_MIRROR} ${TRAVIS_DEBIAN_DISTRIBUTION}-backports main" >> /etc/apt/sources.list
RUN echo "deb-src ${TRAVIS_DEBIAN_MIRROR} ${TRAVIS_DEBIAN_DISTRIBUTION}-backports main" >> /etc/apt/sources.list
EOF
fi
if [ "${TRAVIS_DEBIAN_SECURITY_UPDATES}" = true ]
then
cat >>Dockerfile <<EOF
RUN echo "deb http://security.debian.org/ ${TRAVIS_DEBIAN_DISTRIBUTION}/updates main" >> /etc/apt/sources.list
RUN echo "deb-src http://security.debian.org/ ${TRAVIS_DEBIAN_DISTRIBUTION}/updates main" >> /etc/apt/sources.list
EOF
fi
if [ "${TRAVIS_DEBIAN_EXPERIMENTAL}" = true ]
then
cat >>Dockerfile <<EOF
RUN echo "deb ${TRAVIS_DEBIAN_MIRROR} experimental main" >> /etc/apt/sources.list
RUN echo "deb-src ${TRAVIS_DEBIAN_MIRROR} experimental main" >> /etc/apt/sources.list
EOF
fi
EXTRA_PACKAGES=""
case "${TRAVIS_DEBIAN_EXTRA_REPOSITORY:-}" in
https:*)
EXTRA_PACKAGES="${EXTRA_PACKAGES} apt-transport-https"
;;
esac
if [ "${TRAVIS_DEBIAN_EXTRA_REPOSITORY_GPG_URL:-}" != "" ]
then
EXTRA_PACKAGES="${EXTRA_PACKAGES} wget gnupg"
fi
cat >>Dockerfile <<EOF
RUN apt-get update && apt-get dist-upgrade --yes
RUN apt-get install --yes --no-install-recommends build-essential devscripts pkg-config git-buildpackage ca-certificates debhelper fakeroot lintian ${EXTRA_PACKAGES}
WORKDIR $(pwd)
COPY . .
EOF
if [ "${TRAVIS_DEBIAN_EXTRA_REPOSITORY_GPG_URL:-}" != "" ]
then
cat >>Dockerfile <<EOF
RUN wget -O- "${TRAVIS_DEBIAN_EXTRA_REPOSITORY_GPG_URL}" | apt-key add -
EOF
fi
# We're adding the extra repository only after the essential tools have been
# installed, so that we have apt-transport-https if the repository needs it.
if [ "${TRAVIS_DEBIAN_EXTRA_REPOSITORY:-}" != "" ]
then
cat >>Dockerfile <<EOF
RUN echo "deb ${TRAVIS_DEBIAN_EXTRA_REPOSITORY}" >> /etc/apt/sources.list
RUN echo "deb-src ${TRAVIS_DEBIAN_EXTRA_REPOSITORY}" >> /etc/apt/sources.list
RUN apt-get update
EOF
fi
if [ "${TRAVIS_DEBIAN_BACKPORTS}" = "true" ]
then
cat >>Dockerfile <<EOF
RUN echo "Package: *" >> /etc/apt/preferences.d/travis_debian_net
RUN echo "Pin: release a=${TRAVIS_DEBIAN_DISTRIBUTION}-backports" >> /etc/apt/preferences.d/travis_debian_net
RUN echo "Pin-Priority: 500" >> /etc/apt/preferences.d/travis_debian_net
EOF
fi
cat >>Dockerfile <<EOF
RUN apt-get install --yes --no-install-recommends libnanomsg-dev postgresql-server-dev-all
RUN rm -f Dockerfile
RUN git checkout .travis.yml || true
RUN mkdir -p ${TRAVIS_DEBIAN_BUILD_DIR}
RUN git config remote.origin.fetch '+refs/heads/*:refs/remotes/origin/*'
RUN git fetch
RUN for X in \$(git branch -r | grep -v HEAD); do git branch --track \$(echo "\${X}" | sed -e 's@.*/@@g') \${X} || true; done
CMD make deb
EOF
Info "Using Dockerfile:"
sed -e 's@^@ @g' Dockerfile
TAG="travis.debian.net/${SOURCE}"
Info "Building Docker image ${TAG}"
docker build --tag="${TAG}" .
Info "Removing Dockerfile"
rm -f Dockerfile
CIDFILE="$(mktemp --dry-run)"
ARGS="--cidfile=${CIDFILE}"
if [ "${TRAVIS_DEBIAN_NETWORK_ENABLED}" != "true" ]
then
ARGS="${ARGS} --net=none"
fi
Info "Running build"
# shellcheck disable=SC2086
docker run --env=DEB_BUILD_OPTIONS="${DEB_BUILD_OPTIONS:-}" ${ARGS} "${TAG}"
Info "Copying build artefacts to ${TRAVIS_DEBIAN_TARGET_DIR}"
mkdir -p "${TRAVIS_DEBIAN_TARGET_DIR}"
docker cp "$(cat "${CIDFILE}")":"${TRAVIS_DEBIAN_BUILD_DIR}"/ - \
| tar xf - -C "${TRAVIS_DEBIAN_TARGET_DIR}" --strip-components=1
Info "Removing container"
docker rm "$(cat "${CIDFILE}")" >/dev/null
rm -f "${CIDFILE}"
Info "Build successful"
ls -la "${TRAVIS_DEBIAN_TARGET_DIR}"
# _ _ _ _ _ _
# | |_ _ __ __ ___ _(_)___ __| | ___| |__ (_) __ _ _ __ _ __ ___| |_
# | __| '__/ _` \ \ / / / __| / _` |/ _ \ '_ \| |/ _` | '_ \ | '_ \ / _ \ __|
# | |_| | | (_| |\ V /| \__ \| (_| | __/ |_) | | (_| | | | |_| | | | __/ |_
# \__|_| \__,_| \_/ |_|___(_)__,_|\___|_.__/|_|\__,_|_| |_(_)_| |_|\___|\__|
#