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