From 5d5af3f07e7599fe278e1c74a639e8b762c8bf2b Mon Sep 17 00:00:00 2001 From: Sergei Iudin Date: Mon, 14 Jun 2021 11:16:46 -0700 Subject: [PATCH] Migrate libbpf ci to GH actions changes to docker command require to run it in non-interactive mode --- .github/actions/debian/action.yml | 16 ++++++ .github/actions/setup/action.yml | 20 ++++++++ .github/actions/vmtest/action.yml | 15 ++++++ .github/workflows/test.yml | 85 +++++++++++++++++++++++++++++++ travis-ci/managers/debian.sh | 2 +- travis-ci/vmtest/helpers.sh | 26 +++++++--- travis-ci/vmtest/run.sh | 12 +++-- 7 files changed, 164 insertions(+), 12 deletions(-) create mode 100644 .github/actions/debian/action.yml create mode 100644 .github/actions/setup/action.yml create mode 100644 .github/actions/vmtest/action.yml create mode 100644 .github/workflows/test.yml diff --git a/.github/actions/debian/action.yml b/.github/actions/debian/action.yml new file mode 100644 index 0000000..23d48ec --- /dev/null +++ b/.github/actions/debian/action.yml @@ -0,0 +1,16 @@ +name: 'debian' +description: 'Build' +inputs: + target: + description: 'Run target' + required: true +runs: + using: "composite" + steps: + - run: | + source /tmp/ci_setup + bash -x $CI_ROOT/managers/debian.sh SETUP + bash -x $CI_ROOT/managers/debian.sh ${{ inputs.target }} + bash -x $CI_ROOT/managers/debian.sh CLEANUP + shell: bash + diff --git a/.github/actions/setup/action.yml b/.github/actions/setup/action.yml new file mode 100644 index 0000000..767f39d --- /dev/null +++ b/.github/actions/setup/action.yml @@ -0,0 +1,20 @@ +name: 'setup' +description: 'setup env, create /tmp/ci_setup' +runs: + using: "composite" + steps: + - id: variables + run: | + export REPO_ROOT=$GITHUB_WORKSPACE + export CI_ROOT=$REPO_ROOT/travis-ci + # this is somewhat ugly, but that is the easiest way to share this code with + # arch specific docker + echo export DEBIAN_FRONTEND=noninteractive > /tmp/ci_setup + echo sudo apt-get install -y aptitude qemu-kvm zstd binutils-dev elfutils libcap-dev libelf-dev libdw-dev >> /tmp/ci_setup + echo export PROJECT_NAME='libbpf' >> /tmp/ci_setup + echo export AUTHOR_EMAIL="$(git log -1 --pretty=\"%aE\")" >> /tmp/ci_setup + echo export REPO_ROOT=$GITHUB_WORKSPACE >> /tmp/ci_setup + echo export CI_ROOT=$REPO_ROOT/travis-ci >> /tmp/ci_setup + echo export VMTEST_ROOT=$CI_ROOT/vmtest >> /tmp/ci_setup + shell: bash + diff --git a/.github/actions/vmtest/action.yml b/.github/actions/vmtest/action.yml new file mode 100644 index 0000000..7a3e3e5 --- /dev/null +++ b/.github/actions/vmtest/action.yml @@ -0,0 +1,15 @@ +name: 'vmtest' +description: 'Build + run vmtest' +inputs: + kernel: + description: 'kernel or LATEST' + required: true + default: 'LATEST' +runs: + using: "composite" + steps: + - run: | + source /tmp/ci_setup + export KERNEL=${{ inputs.kernel }} + $CI_ROOT/vmtest/run_vmtest.sh + shell: bash diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml new file mode 100644 index 0000000..8a0f28f --- /dev/null +++ b/.github/workflows/test.yml @@ -0,0 +1,85 @@ +name: libbpf-ci + +on: + pull_request: + push: + schedule: + - cron: '0 18 * * *' + + +jobs: + vmtest: + runs-on: ubuntu-latest + name: Kernel ${{ matrix.kernel }} + selftests + strategy: + matrix: + include: + - kernel: 'LATEST' + - kernel: '5.5.0' + - kernel: '4.9.0' + steps: + - uses: actions/checkout@v2 + - uses: ./.github/actions/setup + - uses: ./.github/actions/vmtest + with: + kernel: ${{ matrix.kernel }} + + debian: + runs-on: ubuntu-latest + name: Debian Build (${{ matrix.name }}) + strategy: + matrix: + include: + - name: default + target: RUN + - name: ASan+UBSan + target: RUN_ASAN + - name: clang + target: RUN_CLANG + - name: clang ASan+UBSan + target: RUN_CLANG_ASAN + - name: gcc-10 + target: RUN_GCC10 + - name: gcc-10 ASan+UBSan + target: RUN_GCC10_ASAN + steps: + - uses: actions/checkout@v2 + - uses: ./.github/actions/setup + - uses: ./.github/actions/debian + with: + target: ${{ matrix.target }} + + ubuntu: + runs-on: ubuntu-latest + name: Ubuntu Focal Build (${{ matrix.arch }}) + strategy: + matrix: + include: + - arch: aarch64 + - arch: ppc64le + - arch: s390x + - arch: x86 + steps: + - uses: actions/checkout@v2 + - uses: ./.github/actions/setup + - run: source /tmp/ci_setup && sudo -E $CI_ROOT/managers/ubuntu.sh + if: matrix.arch == 'x86' + - uses: uraimo/run-on-arch-action@v2.0.5 + name: Build in docker + if: matrix.arch != 'x86' + with: + distro: + ubuntu20.04 + arch: + ${{ matrix.arch }} + setup: + cp /tmp/ci_setup $GITHUB_WORKSPACE + dockerRunArgs: | + --volume "${GITHUB_WORKSPACE}:${GITHUB_WORKSPACE}" + shell: /bin/bash + install: | + export DEBIAN_FRONTEND=noninteractive + export TZ="America/Los_Angeles" + apt-get update -y + apt-get install -y tzdata build-essential sudo + run: source ${GITHUB_WORKSPACE}/ci_setup && $CI_ROOT/managers/ubuntu.sh diff --git a/travis-ci/managers/debian.sh b/travis-ci/managers/debian.sh index 09d39e1..6b54865 100755 --- a/travis-ci/managers/debian.sh +++ b/travis-ci/managers/debian.sh @@ -18,7 +18,7 @@ function error() { } function docker_exec() { - docker exec $ENV_VARS -it $CONT_NAME "$@" + docker exec $ENV_VARS $CONT_NAME "$@" } set -eu diff --git a/travis-ci/vmtest/helpers.sh b/travis-ci/vmtest/helpers.sh index c6be1a0..0cb62d5 100644 --- a/travis-ci/vmtest/helpers.sh +++ b/travis-ci/vmtest/helpers.sh @@ -2,11 +2,23 @@ # $2 - fold identifier, no spaces # $3 - fold section description travis_fold() { - local YELLOW='\033[1;33m' - local NOCOLOR='\033[0m' - echo travis_fold:$1:$2 - if [ ! -z "${3:-}" ]; then - echo -e "${YELLOW}$3${NOCOLOR}" - fi - echo + local YELLOW='\033[1;33m' + local NOCOLOR='\033[0m' + if [ -z ${GITHUB_WORKFLOW+x} ]; then + echo travis_fold:$1:$2 + if [ ! -z "${3:-}" ]; then + echo -e "${YELLOW}$3${NOCOLOR}" + fi + echo + else + if [ $1 = "start" ]; then + line="::group::$2" + if [ ! -z "${3:-}" ]; then + line="$line - ${YELLOW}$3${NOCOLOR}" + fi + else + line="::endgroup" + fi + echo -e "$line" + fi } diff --git a/travis-ci/vmtest/run.sh b/travis-ci/vmtest/run.sh index ec22d3e..ad2d8ef 100755 --- a/travis-ci/vmtest/run.sh +++ b/travis-ci/vmtest/run.sh @@ -436,11 +436,15 @@ sudo umount "$mnt" echo "Starting VM with $(nproc) CPUs..." +if kvm-ok ; then + accel="-cpu kvm64 -enable-kvm" +else + accel="-cpu qemu64 -machine accel=tcg" +fi qemu-system-x86_64 -nodefaults -display none -serial mon:stdio \ - -cpu kvm64 -enable-kvm -smp "$(nproc)" -m 4G \ - -drive file="$IMG",format=raw,index=1,media=disk,if=virtio,cache=none \ - -kernel "$vmlinuz" -append "root=/dev/vda rw console=ttyS0,115200$APPEND" - + ${accel} -smp "$(nproc)" -m 4G \ + -drive file="$IMG",format=raw,index=1,media=disk,if=virtio,cache=none \ + -kernel "$vmlinuz" -append "root=/dev/vda rw console=ttyS0,115200$APPEND" sudo mount -o loop "$IMG" "$mnt" if exitstatus="$(cat "$mnt/exitstatus" 2>/dev/null)"; then printf '\nTests exit status: %s\n' "$exitstatus" >&2