From 072972aec197fa3573043d61e619bc332a96e2fa Mon Sep 17 00:00:00 2001 From: Brad House Date: Tue, 23 Jul 2024 13:22:12 -0400 Subject: [PATCH] CI: MacOS: move to GitHub Actions instead of Cirrus-CI (#825) We've been using a lot of time on Cirrus-CI and our credits run out quickly. MacOS costs 15 compute credits vs 3 compute credits for Linux. Move MacOS testing to GitHub Actions. Fix By: Brad House (@bradh352) --- .cirrus.yml | 14 +------ .github/workflows/macos.yml | 74 +++++++++++++++++++++++++++++++++++++ .github/workflows/msys2.yml | 2 +- ci/build.sh | 2 + ci/test.sh | 18 ++++++--- 5 files changed, 90 insertions(+), 20 deletions(-) create mode 100644 .github/workflows/macos.yml diff --git a/.cirrus.yml b/.cirrus.yml index 932cc2b9..727f6950 100644 --- a/.cirrus.yml +++ b/.cirrus.yml @@ -73,18 +73,6 @@ task: TEST_SYMBOL_VISIBILITY: "yes" freebsd_instance: image_family: freebsd-13-3 - - name: "MacOS" - env: - DIST: "MACOS" - SCAN_BUILD: "/opt/homebrew/opt/llvm/bin/scan-build-py" - MAKE: "make" - TEST_DEBUGGER: "lldb" - BUILD_ASAN: "yes" - BUILD_UBSAN: "yes" - BUILD_ANALYZE: "yes" - TEST_SYMBOL_VISIBILITY: "yes" - macos_instance: - image: ghcr.io/cirruslabs/macos-sonoma-xcode:latest - name: "iOS" env: DIST: "iOS" @@ -150,7 +138,7 @@ task: env: BUILD_TYPE: "valgrind" TEST_WRAP: "valgrind --leak-check=full" - TEST_FILTER: "--gtest_filter=-*Container*:-*LiveSearchANY*" + TEST_FILTER: "-4 --gtest_filter=-*Container*:-*LiveSearchANY*" install_script: - | diff --git a/.github/workflows/macos.yml b/.github/workflows/macos.yml new file mode 100644 index 00000000..946875e1 --- /dev/null +++ b/.github/workflows/macos.yml @@ -0,0 +1,74 @@ +# Copyright (C) The c-ares project and its contributors +# SPDX-License-Identifier: MIT +name: MacOS +on: + push: + pull_request: + +concurrency: + group: ${{ github.ref }}-macos + cancel-in-progress: true + +env: + TEST_FILTER: "-v --gtest_filter=-*LiveSearchTXT*:*LiveSearchANY*:*LiveGetLocalhostByAddr*" + CMAKE_FLAGS: "-DCMAKE_BUILD_TYPE=DEBUG -DCARES_STATIC=ON -DCARES_STATIC_PIC=ON -G Ninja" + MAKE: make + +jobs: + build: + runs-on: macos-latest + name: "MacOS" + steps: + - name: Install packages + run: brew install cmake googletest llvm autoconf automake libtool make ninja + - name: Checkout c-ares + uses: actions/checkout@v4 + - name: "CMake: build and test c-ares" + env: + BUILD_TYPE: CMAKE + CMAKE_TEST_FLAGS: "-DCARES_BUILD_TESTS=ON" + TEST_DEBUGGER: lldb + run: | + ./ci/build.sh + ./ci/test.sh + - name: "Autotools: build and test c-ares" + env: + BUILD_TYPE: autotools + TEST_DEBUGGER: lldb + run: | + ./ci/build.sh + ./ci/test.sh + - name: "CMake: UBSAN: build and test c-ares" + env: + BUILD_TYPE: "ubsan" + CC: "clang" + CMAKE_TEST_FLAGS: "-DCARES_BUILD_TESTS=ON" + CFLAGS: "-fsanitize=undefined -fno-sanitize-recover" + CXXFLAGS: "-fsanitize=undefined -fno-sanitize-recover" + LDFLAGS: "-fsanitize=undefined" + TEST_DEBUGGER: "none" + run: | + ./ci/build.sh + ./ci/test.sh + - name: "CMake: ASAN: build and test c-ares" + env: + BUILD_TYPE: "asan" + CC: "clang" + CMAKE_TEST_FLAGS: "-DCARES_BUILD_TESTS=ON" + CFLAGS: "-fsanitize=address" + CXXFLAGS: "-fsanitize=address" + LDFLAGS: "-fsanitize=address" + TEST_DEBUGGER: "none" + run: | + ./ci/build.sh + ./ci/test.sh + - name: "Cmake: Static Analyzer: build c-ares" + env: + BUILD_TYPE: "analyze" + CC: "clang" + SCAN_WRAP: "/opt/homebrew/opt/llvm/bin/scan-build-py -v --status-bugs" + CMAKE_TEST_FLAGS: "-DCARES_BUILD_TESTS=OFF" + TEST_DEBUGGER: "lldb" + run: | + ./ci/build.sh + ./ci/test.sh diff --git a/.github/workflows/msys2.yml b/.github/workflows/msys2.yml index 58f060b6..7976c102 100644 --- a/.github/workflows/msys2.yml +++ b/.github/workflows/msys2.yml @@ -6,7 +6,7 @@ on: pull_request: concurrency: - group: ${{ github.ref }} + group: ${{ github.ref }}-msys2 cancel-in-progress: true env: diff --git a/ci/build.sh b/ci/build.sh index eb764d12..e4e9f771 100755 --- a/ci/build.sh +++ b/ci/build.sh @@ -17,6 +17,7 @@ fi if [ "$BUILD_TYPE" = "autotools" -o "$BUILD_TYPE" = "coverage" ]; then autoreconf -fi + rm -rf atoolsbld mkdir atoolsbld cd atoolsbld if [ "$DIST" = "iOS" ] ; then @@ -30,6 +31,7 @@ if [ "$BUILD_TYPE" = "autotools" -o "$BUILD_TYPE" = "coverage" ]; then $SCAN_WRAP make else # Use cmake for everything else + rm -rf cmakebld mkdir cmakebld cd cmakebld if [ "$DIST" = "iOS" ] ; then diff --git a/ci/test.sh b/ci/test.sh index 874f5c23..3dd6c166 100755 --- a/ci/test.sh +++ b/ci/test.sh @@ -1,13 +1,13 @@ #!/bin/sh # Copyright (C) The c-ares project and its contributors # SPDX-License-Identifier: MIT -set -e -x +set -e -x -o pipefail # Travis on MacOS uses CloudFlare's DNS (1.1.1.1/1.0.0.1) which rejects ANY requests. # Also, LiveSearchTXT is known to fail on Cirrus-CI on some MacOS hosts, we don't get # a truncated UDP response so we never follow up with TCP. # Note res_ninit() and /etc/resolv.conf actually have different configs, bad Travis -[ -z "$TEST_FILTER" ] && export TEST_FILTER="--gtest_filter=-*LiveSearchTXT*:*LiveSearchANY*" +[ -z "$TEST_FILTER" ] && export TEST_FILTER="-4 --gtest_filter=-*LiveSearchTXT*:*LiveSearchANY*" # No tests for ios as it is a cross-compile if [ "$BUILD_TYPE" = "ios" -o "$BUILD_TYPE" = "ios-cmake" -o "$DIST" = "iOS" ] ; then @@ -37,13 +37,19 @@ $TEST_WRAP "${TOOLSBIN}/ahost" www.google.com cd "${TESTSBIN}" if [ "$TEST_WRAP" != "" ] ; then - $TEST_WRAP ./arestest -4 $TEST_FILTER + $TEST_WRAP ./arestest $TEST_FILTER elif [ "$TEST_DEBUGGER" = "gdb" ] ; then - gdb --batch --batch-silent --return-child-result -ex "handle SIGPIPE nostop noprint pass" -ex "run" -ex "thread apply all bt" -ex "quit" --args ./arestest -4 $TEST_FILTER + gdb --batch --batch-silent --return-child-result -ex "handle SIGPIPE nostop noprint pass" -ex "run" -ex "thread apply all bt" -ex "quit" --args ./arestest $TEST_FILTER elif [ "$TEST_DEBUGGER" = "lldb" ] ; then - lldb --batch -o "settings set target.process.extra-startup-command 'process handle SIGPIPE -n true -p true -s false'" -o "process launch --shell-expand-args 0" -k "thread backtrace all" -k "quit 1" -- ./arestest -4 $TEST_FILTER + # LLDB won't return the exit code of the child process, so we need to extract it from the test output and verify it. + lldb --batch -o "settings set target.process.extra-startup-command 'process handle SIGPIPE -n true -p true -s false'" -o "process launch --shell-expand-args 0" -k "thread backtrace all" -k "quit 1" -- ./arestest $TEST_FILTER 2>&1 | tee test_output.txt + exit_code=`grep "Process [0-9]* exited with status = [0-9]* (.*)" test_output.txt | sed 's/.* = \([0-9]*\).*/\1/'` + echo "Test Exit Code: ${exit_code}" + if [ "${exit_code}" != "0" ] ; then + exit 1 + fi else - ./arestest -4 $TEST_FILTER + ./arestest $TEST_FILTER fi ./aresfuzz ${TESTDIR}/fuzzinput/*