]> git.ipfire.org Git - thirdparty/systemd.git/blob - .semaphore/semaphore-runner.sh
Merge pull request #22983 from yuwata/login-use-symlinks-under-static_node-tags
[thirdparty/systemd.git] / .semaphore / semaphore-runner.sh
1 #!/usr/bin/env bash
2 # SPDX-License-Identifier: LGPL-2.1-or-later
3
4 set -eux
5 set -o pipefail
6
7 # default to Debian testing
8 DISTRO="${DISTRO:-debian}"
9 RELEASE="${RELEASE:-bullseye}"
10 BRANCH="${BRANCH:-upstream-ci}"
11 ARCH="${ARCH:-amd64}"
12 CONTAINER="${RELEASE}-${ARCH}"
13 CACHE_DIR="${SEMAPHORE_CACHE_DIR:-/tmp}"
14 AUTOPKGTEST_DIR="${CACHE_DIR}/autopkgtest"
15 # semaphore cannot expose these, but useful for interactive/local runs
16 ARTIFACTS_DIR=/tmp/artifacts
17 # shellcheck disable=SC2206
18 PHASES=(${@:-SETUP RUN})
19 UBUNTU_RELEASE="$(lsb_release -cs)"
20
21 create_container() {
22 # Create autopkgtest LXC image; this sometimes fails with "Unable to fetch
23 # GPG key from keyserver", so retry a few times with different keyservers.
24 for keyserver in "keys.openpgp.org" "" "keyserver.ubuntu.com" "keys.gnupg.net"; do
25 for retry in {1..5}; do
26 sudo lxc-create -n "$CONTAINER" -t download -- -d "$DISTRO" -r "$RELEASE" -a "$ARCH" ${keyserver:+--keyserver "$keyserver"} && break 2
27 sleep $((retry*retry))
28 done
29 done
30
31 # unconfine the container, otherwise some tests fail
32 echo 'lxc.apparmor.profile = unconfined' | sudo tee -a "/var/lib/lxc/$CONTAINER/config"
33
34 sudo lxc-start -n "$CONTAINER"
35
36 # enable source repositories so that apt-get build-dep works
37 sudo lxc-attach -n "$CONTAINER" -- sh -ex <<EOF
38 sed 's/^deb/deb-src/' /etc/apt/sources.list >> /etc/apt/sources.list.d/sources.list
39 # We might attach the console too soon
40 while ! systemctl --quiet --wait is-system-running; do sleep 1; done
41 # Manpages database trigger takes a lot of time and is not useful in a CI
42 echo 'man-db man-db/auto-update boolean false' | debconf-set-selections
43 # Speed up dpkg, image is thrown away after the test
44 mkdir -p /etc/dpkg/dpkg.cfg.d/
45 echo 'force-unsafe-io' > /etc/dpkg/dpkg.cfg.d/unsafe_io
46 # For some reason, it is necessary to run this manually or the interface won't be configured
47 # Note that we avoid networkd, as some of the tests will break it later on
48 dhclient
49 apt-get -q --allow-releaseinfo-change update
50 apt-get -y dist-upgrade
51 apt-get install -y eatmydata
52 # The following four are needed as long as these deps are not covered by Debian's own packaging
53 apt-get install -y fdisk tree libfdisk-dev libp11-kit-dev libssl-dev libpwquality-dev rpm
54 apt-get purge --auto-remove -y unattended-upgrades
55 systemctl unmask systemd-networkd
56 systemctl enable systemd-networkd
57 EOF
58 sudo lxc-stop -n "$CONTAINER"
59 }
60
61 for phase in "${PHASES[@]}"; do
62 case "$phase" in
63 SETUP)
64 # remove semaphore repos, some of them don't work and cause error messages
65 sudo rm -f /etc/apt/sources.list.d/*
66
67 # enable backports for latest LXC
68 echo "deb http://archive.ubuntu.com/ubuntu $UBUNTU_RELEASE-backports main restricted universe multiverse" | sudo tee -a /etc/apt/sources.list.d/backports.list
69 sudo apt-get -q update
70 sudo apt-get install -y -t "$UBUNTU_RELEASE-backports" lxc
71 sudo apt-get install -y python3-debian git dpkg-dev fakeroot python3-jinja2
72
73 [ -d "$AUTOPKGTEST_DIR" ] || git clone --quiet --depth=1 https://salsa.debian.org/ci-team/autopkgtest.git "$AUTOPKGTEST_DIR"
74
75 create_container
76 ;;
77 RUN)
78 # add current debian/ packaging
79 git fetch --depth=1 https://salsa.debian.org/systemd-team/systemd.git "$BRANCH"
80 git checkout FETCH_HEAD debian
81
82 # craft changelog
83 UPSTREAM_VER="$(git describe | sed 's/^v//;s/-/./g')"
84 cat << EOF > debian/changelog.new
85 systemd (${UPSTREAM_VER}.0) UNRELEASED; urgency=low
86
87 * Automatic build for upstream test
88
89 -- systemd test <pkg-systemd-maintainers@lists.alioth.debian.org> $(date -R)
90
91 EOF
92 cat debian/changelog >>debian/changelog.new
93 mv debian/changelog.new debian/changelog
94
95 # clean out patches
96 rm -rf debian/patches
97 # disable autopkgtests which are not for upstream
98 sed -i '/# NOUPSTREAM/ q' debian/tests/control
99 # TODO: rebooting via autopkgtest-reboot seems to be broken, disable these tests for now
100 sed -i -n '1,/Tests: boot-and-services/p;/Tests: udev/,$p' debian/tests/control
101 sed -i '/Tests: boot-and-services/d' debian/tests/control
102 sed -i '/Tests: boot-smoke/,$d' debian/tests/control
103 # enable more unit tests
104 sed -i '/^CONFFLAGS =/ s/=/= --werror -Dtests=unsafe -Dsplit-usr=true -Dslow-tests=true -Dfuzz-tests=true -Dman=true /' debian/rules
105 # no orig tarball
106 echo '1.0' > debian/source/format
107
108 # build source package
109 dpkg-buildpackage -S -I -I"$(basename "$CACHE_DIR")" -d -us -uc -nc
110
111 # now build the package and run the tests
112 rm -rf "$ARTIFACTS_DIR"
113 # autopkgtest exits with 2 for "some tests skipped", accept that
114 "$AUTOPKGTEST_DIR/runner/autopkgtest" --env DEB_BUILD_OPTIONS=noudeb \
115 --env TEST_UPSTREAM=1 ../systemd_*.dsc \
116 -o "$ARTIFACTS_DIR" \
117 -- lxc -s "$CONTAINER" \
118 || [ $? -eq 2 ]
119 ;;
120 *)
121 echo >&2 "Unknown phase '$phase'"
122 exit 1
123 esac
124 done