6136c1
From 88ac207cc619935c64923e6f8fdef324a5b733d8 Mon Sep 17 00:00:00 2001
6136c1
From: Frantisek Sumsal <frantisek@sumsal.cz>
6136c1
Date: Fri, 15 Jan 2021 15:13:53 +0100
6136c1
Subject: [PATCH] ci: move jobs from Travis CI to GH Actions
6136c1
6136c1
The OSS version of Travis CI is going to be merged with the commercial
6136c1
one soon, essentially dropping the free tier, so let's move the CI jobs
6136c1
to GitHub Actions to keep them up.
6136c1
6136c1
rhel-only
6136c1
Related: #1871827
6136c1
---
6136c1
 .../workflows/unit_tests.sh                   | 28 +++----
6136c1
 .github/workflows/unit_tests.yml              | 28 +++++++
6136c1
 .travis.yml                                   | 48 ------------
6136c1
 ci/travis-centos-rhel7.sh                     | 73 -------------------
6136c1
 ci/travis_wait.bash                           | 61 ----------------
6136c1
 5 files changed, 37 insertions(+), 201 deletions(-)
6136c1
 rename ci/travis-centos-rhel8.sh => .github/workflows/unit_tests.sh (82%)
6136c1
 create mode 100644 .github/workflows/unit_tests.yml
6136c1
 delete mode 100644 .travis.yml
6136c1
 delete mode 100755 ci/travis-centos-rhel7.sh
6136c1
 delete mode 100644 ci/travis_wait.bash
6136c1
6136c1
diff --git a/ci/travis-centos-rhel8.sh b/.github/workflows/unit_tests.sh
6136c1
similarity index 82%
6136c1
rename from ci/travis-centos-rhel8.sh
6136c1
rename to .github/workflows/unit_tests.sh
6136c1
index ffe5813b1a..ea4f7e7592 100755
6136c1
--- a/ci/travis-centos-rhel8.sh
6136c1
+++ b/.github/workflows/unit_tests.sh
6136c1
@@ -1,18 +1,9 @@
6136c1
 #!/bin/bash
6136c1
 
6136c1
-# Run this script from the root of the systemd's git repository
6136c1
-# or set REPO_ROOT to a correct path.
6136c1
-#
6136c1
-# Example execution on Fedora:
6136c1
-# dnf install docker
6136c1
-# systemctl start docker
6136c1
-# export CONT_NAME="my-fancy-container"
6136c1
-# ci/travis-centos.sh SETUP RUN CLEANUP
6136c1
-
6136c1
 PHASES=(${@:-SETUP RUN CLEANUP})
6136c1
 CENTOS_RELEASE="${CENTOS_RELEASE:-latest}"
6136c1
 CONT_NAME="${CONT_NAME:-centos-$CENTOS_RELEASE-$RANDOM}"
6136c1
-DOCKER_EXEC="${DOCKER_EXEC:-docker exec -it $CONT_NAME}"
6136c1
+DOCKER_EXEC="${DOCKER_EXEC:-docker exec $CONT_NAME}"
6136c1
 DOCKER_RUN="${DOCKER_RUN:-docker run}"
6136c1
 REPO_ROOT="${REPO_ROOT:-$PWD}"
6136c1
 ADDITIONAL_DEPS=(libasan libubsan net-tools strace nc e2fsprogs quota dnsmasq diffutils)
6136c1
@@ -71,9 +62,7 @@ function info() {
6136c1
     echo -e "\033[33;1m$1\033[0m"
6136c1
 }
6136c1
 
6136c1
-set -e
6136c1
-
6136c1
-source "$(dirname $0)/travis_wait.bash"
6136c1
+set -ex
6136c1
 
6136c1
 for phase in "${PHASES[@]}"; do
6136c1
     case $phase in
6136c1
@@ -86,6 +75,7 @@ for phase in "${PHASES[@]}"; do
6136c1
             $DOCKER_RUN -v $REPO_ROOT:/build:rw \
6136c1
                         -w /build --privileged=true --name $CONT_NAME \
6136c1
                         -dit --net=host quay.io/centos/centos:$CENTOS_RELEASE /sbin/init
6136c1
+
6136c1
             # Beautiful workaround for Fedora's version of Docker
6136c1
             sleep 1
6136c1
             $DOCKER_EXEC dnf makecache
6136c1
@@ -97,10 +87,10 @@ for phase in "${PHASES[@]}"; do
6136c1
             # Install systemd's build dependencies
6136c1
             $DOCKER_EXEC dnf -q -y --enablerepo "powertools" builddep systemd
6136c1
             ;;
6136c1
-        RUN)
6136c1
+        RUN|RUN_GCC)
6136c1
             info "Run phase"
6136c1
             # Build systemd
6136c1
-            docker exec -it -e CFLAGS='-g -O0 -ftrapv' $CONT_NAME meson build -Dtests=unsafe -Dslow-tests=true "${CONFIGURE_OPTS[@]}"
6136c1
+            docker exec -e CFLAGS='-g -O0 -ftrapv' $CONT_NAME meson build -Dtests=unsafe -Dslow-tests=true "${CONFIGURE_OPTS[@]}"
6136c1
             $DOCKER_EXEC ninja -v -C build
6136c1
             # Let's install the new systemd and "reboot" the container to avoid
6136c1
             # unexpected fails due to incompatibilities with older systemd
6136c1
@@ -108,16 +98,16 @@ for phase in "${PHASES[@]}"; do
6136c1
             docker restart $CONT_NAME
6136c1
             $DOCKER_EXEC ninja -C build test
6136c1
             ;;
6136c1
-        RUN_ASAN|RUN_CLANG_ASAN)
6136c1
+        RUN_ASAN|RUN_GCC_ASAN|RUN_CLANG_ASAN)
6136c1
             if [[ "$phase" = "RUN_CLANG_ASAN" ]]; then
6136c1
                 ENV_VARS="-e CC=clang -e CXX=clang++"
6136c1
                 MESON_ARGS="-Db_lundef=false" # See https://github.com/mesonbuild/meson/issues/764
6136c1
             fi
6136c1
-            docker exec $ENV_VARS -it $CONT_NAME meson build --werror -Dtests=unsafe -Db_sanitize=address,undefined $MESON_ARGS "${CONFIGURE_OPTS[@]}"
6136c1
-            docker exec -it $CONT_NAME ninja -v -C build
6136c1
+            docker exec $ENV_VARS $CONT_NAME meson build --werror -Dtests=unsafe -Db_sanitize=address,undefined $MESON_ARGS "${CONFIGURE_OPTS[@]}"
6136c1
+            docker exec $CONT_NAME ninja -v -C build
6136c1
 
6136c1
             # Never remove halt_on_error from UBSAN_OPTIONS. See https://github.com/systemd/systemd/commit/2614d83aa06592aedb.
6136c1
-            travis_wait docker exec --interactive=false \
6136c1
+            docker exec --interactive=false \
6136c1
                 -e UBSAN_OPTIONS=print_stacktrace=1:print_summary=1:halt_on_error=1 \
6136c1
                 -e ASAN_OPTIONS=strict_string_checks=1:detect_stack_use_after_return=1:check_initialization_order=1:strict_init_order=1 \
6136c1
                 -e "TRAVIS=$TRAVIS" \
6136c1
diff --git a/.github/workflows/unit_tests.yml b/.github/workflows/unit_tests.yml
6136c1
new file mode 100644
6136c1
index 0000000000..15f5127a75
6136c1
--- /dev/null
6136c1
+++ b/.github/workflows/unit_tests.yml
6136c1
@@ -0,0 +1,28 @@
6136c1
+---
6136c1
+# vi: ts=2 sw=2 et:
6136c1
+#
6136c1
+name: Unit tests
6136c1
+on:
6136c1
+  pull_request:
6136c1
+    branches:
6136c1
+      - master
6136c1
+
6136c1
+jobs:
6136c1
+  build:
6136c1
+    runs-on: ubuntu-20.04
6136c1
+    env:
6136c1
+      CENTOS_RELEASE: "centos8"
6136c1
+      CONT_NAME:      "systemd-centos8-ci"
6136c1
+    strategy:
6136c1
+      fail-fast: false
6136c1
+      matrix:
6136c1
+        run_phase: [GCC, GCC_ASAN]
6136c1
+    steps:
6136c1
+      - name: Repository checkout
6136c1
+        uses: actions/checkout@v1
6136c1
+      - name: Install build dependencies
6136c1
+        run: sudo -E .github/workflows/unit_tests.sh SETUP
6136c1
+      - name: Build & test (${{ matrix.run_phase }})
6136c1
+        run: sudo -E .github/workflows/unit_tests.sh RUN_${{ matrix.run_phase }}
6136c1
+      - name: Cleanup
6136c1
+        run: sudo -E .github/workflows/unit_tests.sh CLEANUP
6136c1
diff --git a/.travis.yml b/.travis.yml
6136c1
deleted file mode 100644
6136c1
index 70c60cf24e..0000000000
6136c1
--- a/.travis.yml
6136c1
+++ /dev/null
6136c1
@@ -1,48 +0,0 @@
6136c1
-sudo: required
6136c1
-dist: xenial
6136c1
-services:
6136c1
-    - docker
6136c1
-
6136c1
-env:
6136c1
-    global:
6136c1
-        - CI_ROOT="$TRAVIS_BUILD_DIR/ci/"
6136c1
-
6136c1
-jobs:
6136c1
-    include:
6136c1
-        - name: CentOS 8
6136c1
-          language: bash
6136c1
-          env:
6136c1
-              - CENTOS_RELEASE="centos8"
6136c1
-              - CONT_NAME="systemd-centos-$CENTOS_RELEASE"
6136c1
-              - DOCKER_EXEC="docker exec -ti $CONT_NAME"
6136c1
-          before_install:
6136c1
-              - sudo apt-get -y -o Dpkg::Options::="--force-confnew" install docker-ce
6136c1
-              - docker --version
6136c1
-          install:
6136c1
-              - $CI_ROOT/travis-centos-rhel8.sh SETUP
6136c1
-          script:
6136c1
-              - set -e
6136c1
-              # Build systemd
6136c1
-              - $CI_ROOT/travis-centos-rhel8.sh RUN
6136c1
-              - set +e
6136c1
-          after_script:
6136c1
-              - $CI_ROOT/travis-centos-rhel8.sh CLEANUP
6136c1
-
6136c1
-        - name: CentOS 8 (ASan+UBSan)
6136c1
-          language: bash
6136c1
-          env:
6136c1
-              - CENTOS_RELEASE="centos8"
6136c1
-              - CONT_NAME="systemd-centos-$CENTOS_RELEASE"
6136c1
-              - DOCKER_EXEC="docker exec -ti $CONT_NAME"
6136c1
-          before_install:
6136c1
-              - sudo apt-get -y -o Dpkg::Options::="--force-confnew" install docker-ce
6136c1
-              - docker --version
6136c1
-          install:
6136c1
-              - $CI_ROOT/travis-centos-rhel8.sh SETUP
6136c1
-          script:
6136c1
-              - set -e
6136c1
-              # Build systemd
6136c1
-              - $CI_ROOT/travis-centos-rhel8.sh RUN_ASAN
6136c1
-              - set +e
6136c1
-          after_script:
6136c1
-              - $CI_ROOT/travis-centos-rhel8.sh CLEANUP
6136c1
diff --git a/ci/travis-centos-rhel7.sh b/ci/travis-centos-rhel7.sh
6136c1
deleted file mode 100755
6136c1
index 73416798ed..0000000000
6136c1
--- a/ci/travis-centos-rhel7.sh
6136c1
+++ /dev/null
6136c1
@@ -1,73 +0,0 @@
6136c1
-#!/bin/bash
6136c1
-
6136c1
-# Run this script from the root of the systemd's git repository
6136c1
-# or set REPO_ROOT to a correct path.
6136c1
-#
6136c1
-# Example execution on Fedora:
6136c1
-# dnf install docker
6136c1
-# systemctl start docker
6136c1
-# export CONT_NAME="my-fancy-container"
6136c1
-# ci/travis-centos.sh SETUP RUN CLEANUP
6136c1
-
6136c1
-PHASES=(${@:-SETUP RUN CLEANUP})
6136c1
-CENTOS_RELEASE="${CENTOS_RELEASE:-latest}"
6136c1
-CONT_NAME="${CONT_NAME:-centos-$CENTOS_RELEASE-$RANDOM}"
6136c1
-DOCKER_EXEC="${DOCKER_EXEC:-docker exec -it $CONT_NAME}"
6136c1
-DOCKER_RUN="${DOCKER_RUN:-docker run}"
6136c1
-REPO_ROOT="${REPO_ROOT:-$PWD}"
6136c1
-ADDITIONAL_DEPS=(yum-utils iputils hostname libasan libubsan clang llvm)
6136c1
-
6136c1
-function info() {
6136c1
-    echo -e "\033[33;1m$1\033[0m"
6136c1
-}
6136c1
-
6136c1
-set -e
6136c1
-
6136c1
-source "$(dirname $0)/travis_wait.bash"
6136c1
-
6136c1
-for phase in "${PHASES[@]}"; do
6136c1
-    case $phase in
6136c1
-        SETUP)
6136c1
-            info "Setup phase"
6136c1
-            info "Using Travis $CENTOS_RELEASE"
6136c1
-            # Pull a Docker image and start a new container
6136c1
-            docker pull centos:$CENTOS_RELEASE
6136c1
-            info "Starting container $CONT_NAME"
6136c1
-            $DOCKER_RUN -v $REPO_ROOT:/build:rw \
6136c1
-                        -w /build --privileged=true --name $CONT_NAME \
6136c1
-                        -dit --net=host centos:$CENTOS_RELEASE /sbin/init
6136c1
-            # Beautiful workaround for Fedora's version of Docker
6136c1
-            sleep 1
6136c1
-            $DOCKER_EXEC yum makecache
6136c1
-            # Install necessary build/test requirements
6136c1
-            $DOCKER_EXEC yum -y upgrade
6136c1
-            $DOCKER_EXEC yum -y install "${ADDITIONAL_DEPS[@]}"
6136c1
-            $DOCKER_EXEC yum-builddep -y systemd
6136c1
-            ;;
6136c1
-        RUN)
6136c1
-            info "Run phase"
6136c1
-            # Build systemd
6136c1
-            $DOCKER_EXEC ./autogen.sh
6136c1
-            $DOCKER_EXEC ./configure --disable-timesyncd --disable-kdbus --disable-terminal \
6136c1
-                                     --enable-gtk-doc --enable-compat-libs --disable-sysusers \
6136c1
-                                     --disable-ldconfig --enable-lz4 --with-sysvinit-path=/etc/rc.d/init.d
6136c1
-            $DOCKER_EXEC make
6136c1
-            # Let's install the new systemd and "reboot" the container to avoid
6136c1
-            # unexpected fails due to incompatibilities with older systemd
6136c1
-            $DOCKER_EXEC make install
6136c1
-            docker restart $CONT_NAME
6136c1
-            if ! $DOCKER_EXEC make check; then
6136c1
-                $DOCKER_EXEC cat test-suite.log
6136c1
-                exit 1
6136c1
-            fi
6136c1
-            ;;
6136c1
-        CLEANUP)
6136c1
-            info "Cleanup phase"
6136c1
-            docker stop $CONT_NAME
6136c1
-            docker rm -f $CONT_NAME
6136c1
-            ;;
6136c1
-        *)
6136c1
-            echo >&2 "Unknown phase '$phase'"
6136c1
-            exit 1
6136c1
-    esac
6136c1
-done
6136c1
diff --git a/ci/travis_wait.bash b/ci/travis_wait.bash
6136c1
deleted file mode 100644
6136c1
index acf6ad15e4..0000000000
6136c1
--- a/ci/travis_wait.bash
6136c1
+++ /dev/null
6136c1
@@ -1,61 +0,0 @@
6136c1
-# This was borrowed from https://github.com/travis-ci/travis-build/tree/master/lib/travis/build/bash
6136c1
-# to get around https://github.com/travis-ci/travis-ci/issues/9979. It should probably be removed
6136c1
-# as soon as Travis CI has started to provide an easy way to export the functions to bash scripts.
6136c1
-
6136c1
-travis_jigger() {
6136c1
-  local cmd_pid="${1}"
6136c1
-  shift
6136c1
-  local timeout="${1}"
6136c1
-  shift
6136c1
-  local count=0
6136c1
-
6136c1
-  echo -e "\\n"
6136c1
-
6136c1
-  while [[ "${count}" -lt "${timeout}" ]]; do
6136c1
-    count="$((count + 1))"
6136c1
-    echo -ne "Still running (${count} of ${timeout}): ${*}\\r"
6136c1
-    sleep 60
6136c1
-  done
6136c1
-
6136c1
-  echo -e "\\n${ANSI_RED}Timeout (${timeout} minutes) reached. Terminating \"${*}\"${ANSI_RESET}\\n"
6136c1
-  kill -9 "${cmd_pid}"
6136c1
-}
6136c1
-
6136c1
-travis_wait() {
6136c1
-  local timeout="${1}"
6136c1
-
6136c1
-  if [[ "${timeout}" =~ ^[0-9]+$ ]]; then
6136c1
-    shift
6136c1
-  else
6136c1
-    timeout=20
6136c1
-  fi
6136c1
-
6136c1
-  local cmd=("${@}")
6136c1
-  local log_file="travis_wait_${$}.log"
6136c1
-
6136c1
-  "${cmd[@]}" &>"${log_file}" &
6136c1
-  local cmd_pid="${!}"
6136c1
-
6136c1
-  travis_jigger "${!}" "${timeout}" "${cmd[@]}" &
6136c1
-  local jigger_pid="${!}"
6136c1
-  local result
6136c1
-
6136c1
-  {
6136c1
-    set +e
6136c1
-    wait "${cmd_pid}" 2>/dev/null
6136c1
-    result="${?}"
6136c1
-    ps -p"${jigger_pid}" &>/dev/null && kill "${jigger_pid}"
6136c1
-    set -e
6136c1
-  }
6136c1
-
6136c1
-  if [[ "${result}" -eq 0 ]]; then
6136c1
-    echo -e "\\n${ANSI_GREEN}The command ${cmd[*]} exited with ${result}.${ANSI_RESET}"
6136c1
-  else
6136c1
-    echo -e "\\n${ANSI_RED}The command ${cmd[*]} exited with ${result}.${ANSI_RESET}"
6136c1
-  fi
6136c1
-
6136c1
-  echo -e "\\n${ANSI_GREEN}Log:${ANSI_RESET}\\n"
6136c1
-  cat "${log_file}"
6136c1
-
6136c1
-  return "${result}"
6136c1
-}