]> git.ipfire.org Git - thirdparty/systemd.git/blame - semaphoreci/semaphore-runner.sh
Merge pull request #12366 from lkundrak/lr/olpc-xo-175-keyboard
[thirdparty/systemd.git] / semaphoreci / semaphore-runner.sh
CommitLineData
d7707fae
FS
1#!/bin/bash
2
3set -eux
4
5# default to Debian testing
6DISTRO=${DISTRO:-debian}
7RELEASE=${RELEASE:-buster}
8ARCH=${ARCH:-amd64}
9CONTAINER=${RELEASE}-${ARCH}
10MAX_CACHE_AGE=604800 # one week
11CACHE_DIR=${SEMAPHORE_CACHE_DIR:=/tmp}
12CACHE="${CACHE_DIR}/${CONTAINER}.img.tar.gz"
13AUTOPKGTEST_DIR="${CACHE_DIR}/autopkgtest"
14# semaphore cannot expose these, but useful for interactive/local runs
15ARTIFACTS_DIR=/tmp/artifacts
16PHASES=(${@:-SETUP RUN})
17
18create_container() {
19 # create autopkgtest LXC image; this sometimes fails with "Unable to fetch
20 # GPG key from keyserver", so retry a few times
21 for retry in $(seq 5); do
22 sudo lxc-create -n $CONTAINER -t download -- -d $DISTRO -r $RELEASE -a $ARCH && break
23 sleep $((retry*retry))
24 done
25
26 # unconfine the container, otherwise some tests fail
27 echo 'lxc.apparmor.profile = unconfined' | sudo tee -a /var/lib/lxc/$CONTAINER/config
28
29 sudo lxc-start -n $CONTAINER
30
31 # enable source repositories so that apt-get build-dep works
32 sudo lxc-attach -n $CONTAINER -- sh -ex <<EOF
33sed 's/^deb/deb-src/' /etc/apt/sources.list >> /etc/apt/sources.list.d/sources.list
34# wait until online
35while [ -z "\$(ip route list 0/0)" ]; do sleep 1; done
36apt-get -q update
37apt-get -y dist-upgrade
38apt-get install -y eatmydata
39EOF
40 sudo lxc-stop -n $CONTAINER
41
42 # cache it
43 sudo tar cpzf "$CACHE" /var/lib/lxc/$CONTAINER
44}
45
46for phase in "${PHASES[@]}"; do
47 case $phase in
48 SETUP)
49 # remove semaphore repos, some of them don't work and cause error messages
50 sudo rm -f /etc/apt/sources.list.d/*
51
52 # enable backports for latest LXC
53 echo 'deb http://archive.ubuntu.com/ubuntu xenial-backports main restricted universe multiverse' | sudo tee -a /etc/apt/sources.list.d/backports.list
54 sudo apt-get -q update
55 sudo apt-get install -y -t xenial-backports lxc
56 sudo apt-get install -y python3-debian git dpkg-dev fakeroot
57
58 [ -d $AUTOPKGTEST_DIR ] || git clone --quiet --depth=1 https://salsa.debian.org/ci-team/autopkgtest.git "$AUTOPKGTEST_DIR"
59
60 # use cached container image, unless older than a week
61 if [ -e "$CACHE" ] && [ $(( $(date +%s) - $(stat -c %Y "$CACHE") )) -le $MAX_CACHE_AGE ]; then
62 sudo tar -C / -xpzf "$CACHE"
63 else
64 create_container
65 fi
66 ;;
67 RUN)
68 # add current debian/ packaging
69 git fetch --depth=1 https://salsa.debian.org/systemd-team/systemd.git master
70 git checkout FETCH_HEAD debian
71
72 # craft changelog
73 UPSTREAM_VER=$(git describe | sed 's/^v//')
74 cat << EOF > debian/changelog.new
75systemd (${UPSTREAM_VER}-0) UNRELEASED; urgency=low
76
77 * Automatic build for upstream test
78
79 -- systemd test <pkg-systemd-maintainers@lists.alioth.debian.org> $(date -R)
80
81EOF
82 cat debian/changelog >> debian/changelog.new
83 mv debian/changelog.new debian/changelog
84
85 # clean out patches
86 rm -rf debian/patches
87 # disable autopkgtests which are not for upstream
88 sed -i '/# NOUPSTREAM/ q' debian/tests/control
89 # enable more unit tests
90 sed -i '/^CONFFLAGS =/ s/=/= -Dtests=unsafe -Dsplit-usr=true -Dslow-tests=true /' debian/rules
91 # no orig tarball
92 echo '1.0' > debian/source/format
93
94 # build source package
95 dpkg-buildpackage -S -I -I$(basename "$CACHE_DIR") -d -us -uc -nc
96
97 # now build the package and run the tests
98 rm -rf "$ARTIFACTS_DIR"
99 # autopkgtest exits with 2 for "some tests skipped", accept that
100 $AUTOPKGTEST_DIR/runner/autopkgtest --apt-upgrade \
101 --env DEB_BUILD_OPTIONS=noudeb \
102 --env TEST_UPSTREAM=1 ../systemd_*.dsc \
103 -o "$ARTIFACTS_DIR" \
104 -- lxc -s $CONTAINER \
105 || [ $? -eq 2 ]
106 ;;
107 *)
108 echo >&2 "Unknown phase '$phase'"
109 exit 1
110 esac
111done