From 9a4a2d3caf75541ad94a47cd7cf0272314ec47d0 Mon Sep 17 00:00:00 2001 From: Jeffrey Lau Date: Mon, 13 Dec 2021 07:54:15 +0800 Subject: [PATCH] ci: Switch to GitHub Action (wip) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Use ubuntu-18.04 to try to fix build errors Error: time.c:88:28: error: conflicting types for ‘gettimeofday’ 88 | int RETRACE_IMPLEMENTATION(gettimeofday)(struct timeval *tv, struct timezone *tz) | ^~~~~~~~~~~~ common.h:170:39: note: in definition of macro ‘RETRACE_IMPLEMENTATION’ 170 | #define RETRACE_IMPLEMENTATION(func) (func) | ^~~~ In file included from common.h:9, from time.c:26: /usr/include/x86_64-linux-gnu/sys/time.h:66:12: note: previous declaration of ‘gettimeofday’ was here 66 | extern int gettimeofday (struct timeval *__restrict __tv, | ^~~~~~~~~~~~ --- .github/workflows/checkpatch.yml | 23 +++++++++ .github/workflows/macos.yml | 45 +++++++++++++++++ .github/workflows/ubuntu.yml | 43 ++++++++++++++++ .github/workflows/windows.yml | 50 +++++++++++++++++++ .travis.yml | 44 ----------------- ci/before_install.sh | 30 +++++++++--- ci/checkpatch.sh | 84 +++++++++++++++++++------------- ci/env-freebsd.sh | 1 - ci/env-macos.sh | 1 - ci/env-openbsd.sh | 3 +- ci/install.sh | 45 ++--------------- ci/install_functions.sh | 54 ++++++++++++++++++++ ci/main.sh | 38 +++++++++------ 13 files changed, 315 insertions(+), 146 deletions(-) create mode 100644 .github/workflows/checkpatch.yml create mode 100644 .github/workflows/macos.yml create mode 100644 .github/workflows/ubuntu.yml create mode 100644 .github/workflows/windows.yml delete mode 100644 .travis.yml create mode 100644 ci/install_functions.sh diff --git a/.github/workflows/checkpatch.yml b/.github/workflows/checkpatch.yml new file mode 100644 index 00000000..0d34f017 --- /dev/null +++ b/.github/workflows/checkpatch.yml @@ -0,0 +1,23 @@ +name: Checkpatch + +on: + push: + branches: [master] + pull_request: + branches: [master] + +jobs: + build: + + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v2 + - name: Set up environment + run: | + echo CHECKPATCH_INSTALL="${HOME}/builds/checkpatch-install" >> "${GITHUB_ENV}" + ./ci/before_install.sh + - name: Install more prerequisites + run: ./ci/install.sh checkpatch + - name: Check patch + run: ./ci/checkpatch.sh diff --git a/.github/workflows/macos.yml b/.github/workflows/macos.yml new file mode 100644 index 00000000..23cf1031 --- /dev/null +++ b/.github/workflows/macos.yml @@ -0,0 +1,45 @@ +name: macOS + +on: + push: + branches: + - master + - 'release/**' + paths-ignore: + - 'docs/**' + - '**.adoc' + - '**.md' + - '.github/workflows/*.yml' + - '!.github/workflows/macos.yml' + pull_request: + paths-ignore: + - 'docs/**' + - '**.adoc' + - '**.md' + +jobs: + build: + runs-on: ${{ matrix.os }} + strategy: + fail-fast: false + matrix: + os: [macos-10.15, macos-11.0] + if: "!contains(github.event.head_commit.message, 'skip ci')" + + steps: + - uses: actions/checkout@v2 + with: + fetch-depth: 1 + - name: Set up environment + run: | + echo CMOCKA_INSTALL="${HOME}/builds/cmocka-install" >> "${GITHUB_ENV}" + - name: Install more prerequisites + run: | + ./ci/before_install.sh + ./ci/install.sh cmocka libnereon + - name: Configure + run: | + ./autogen.sh + ./configure --enable-tests + - name: Build + run: ./ci/main.sh diff --git a/.github/workflows/ubuntu.yml b/.github/workflows/ubuntu.yml new file mode 100644 index 00000000..b1745fe7 --- /dev/null +++ b/.github/workflows/ubuntu.yml @@ -0,0 +1,43 @@ +name: Ubuntu + +on: + push: + branches: + - master + - 'release/**' + paths-ignore: + - 'docs/**' + - '**.adoc' + - '**.md' + - '.github/workflows/*.yml' + - '!.github/workflows/ubuntu.yml' + pull_request: + paths-ignore: + - 'docs/**' + - '**.adoc' + - '**.md' + +jobs: + build: + runs-on: ubuntu-18.04 + strategy: + fail-fast: false + if: "!contains(github.event.head_commit.message, 'skip ci')" + + steps: + - uses: actions/checkout@v2 + with: + fetch-depth: 1 + - name: Set up environment + run: | + echo CMOCKA_INSTALL="${HOME}/builds/cmocka-install" >> "${GITHUB_ENV}" + - name: Install more prerequisites + run: | + ./ci/before_install.sh + ./ci/install.sh cmocka libnereon + - name: Configure + run: | + ./autogen.sh + ./configure --enable-tests + - name: Build + run: ./ci/main.sh diff --git a/.github/workflows/windows.yml b/.github/workflows/windows.yml new file mode 100644 index 00000000..86c730e7 --- /dev/null +++ b/.github/workflows/windows.yml @@ -0,0 +1,50 @@ +name: Windows + +on: + push: + branches: + - master + - 'release/**' + paths-ignore: + - 'docs/**' + - '**.adoc' + - '**.md' + - '.github/workflows/*.yml' + - '!.github/workflows/windows.yml' + pull_request: + paths-ignore: + - 'docs/**' + - '**.adoc' + - '**.md' + +jobs: + build: + runs-on: windows-latest + strategy: + fail-fast: false + if: "!contains(github.event.head_commit.message, 'skip ci')" + + steps: + - uses: actions/checkout@v2 + with: + fetch-depth: 1 + - uses: msys2/setup-msys2@v2 + with: + path-type: inherit + - name: Set up environment + shell: msys2 {0} + run: | + echo CMOCKA_INSTALL="${HOME}/builds/cmocka-install" >> "${GITHUB_ENV}" + - name: Install more prerequisites + shell: msys2 {0} + run: | + ./ci/before_install.sh + ./ci/install.sh libnereon + - name: Configure + shell: msys2 {0} + run: | + ./autogen.sh + ./configure --enable-tests + - name: Build + shell: msys2 {0} + run: ./ci/main.sh diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index b473dd6e..00000000 --- a/.travis.yml +++ /dev/null @@ -1,44 +0,0 @@ -dist: trusty -sudo: required -language: c - -branches: - only: - - master - - coverity_scan - -env: - global: - - CMOCKA_INSTALL="$HOME/builds/cmocka-install" - - CHECKPATCH_INSTALL="$HOME/builds/checkpatch-install" - - LOGNAME="Travis" - - secure: "bpdJ8XFtVDkKqecKO+d3fusCDj7Lqk4ArAdwVGvbBBAk1jDztUZQymqiwBmiPf3G6y60PIl40R5BIA8pfA2RvNuTLya54x0n7fGm7AMXyhZCV6zh5JSyvCU2ODgpn7M4MysqfjMye+WgHpiAa1+bgyaJJQD4KyGCnVrFxL2Hg9WDj25fUpEiZnu2bLFn90zOZy2qMKoRh4Z6uTTOrhodS+oUulodOx+YfAU8eTOVlYbSGz2ksJrlO/4t7is56sQ5rAun17UmxzZmQu0YGGyzQSEruz86gRFNJcC5lIa1S48REoTW2/95FuOXAtlw6D6AiiqdHnP9PvFmY6PgefJyG9y+aSHhO4VHCQ5EuFkedGJ1AnSnyNd2d2VzPlrdpUGsZ4F6EvGUGTGfROYEy2IUqsnGuR5muMyzp37qG0XURYhb3T1DrCmdBcVYs6iYGuscnBBKwff3RLemsMwKryI6rY29NfKyM/nR46b71G8wXxfC+AogdUEI4HKZ9x0l4j2le0BDehUGhGl5F2JAaNZfC5xbQMZ/x6ERyyqQRfQmzBFk4Rku7NznJj7+Y616TuF/cgGASRdSG7bjBV75BVa1OPc9kviajEok03hC0gJDDeox+aN2k5n0OPSM2ahEsnfeT2Bp9+moTwNnrNrgXlJLConMpxhAtU4vbAmccWjjb9A=" - - -before_install: - - ./ci/before_install.sh - -addons: - coverity_scan: - project: - name: "riboseinc/retrace" - build_command_prepend: "./autogen.sh; ./configure; make clean" - build_command: "make -j4" - branch_pattern: coverity_scan - -after_failure: cat test/test-suite.log - -cache: - directories: - - "$CMOCKA_INSTALL" - -install: - - ./ci/install.sh - -script: - - ./ci/main.sh - - ./ci/checkpatch.sh - -os: - - linux - - osx diff --git a/ci/before_install.sh b/ci/before_install.sh index 774a6244..ce77f048 100755 --- a/ci/before_install.sh +++ b/ci/before_install.sh @@ -1,13 +1,13 @@ -#!/bin/sh +#!/usr/bin/env bash set -ex # https://gist.github.com/marcusandre/4b88c2428220ea255b83 get_os() { - if [ -z $OSTYPE ]; then - echo "$(uname | tr '[:upper:]' '[:lower:]')" + if [ -z "$OSTYPE" ]; then + uname else - echo "$(echo $OSTYPE | tr '[:upper:]' '[:lower:]')" - fi + echo "$OSTYPE" + fi | tr '[:upper:]' '[:lower:]' } macos_install() { @@ -24,9 +24,9 @@ macos_install() { ruby " for p in ${packages}; do - brew install ${p} || brew upgrade ${p} + brew install "${p}" || brew upgrade "${p}" done - mkdir -p ${CMOCKA_INSTALL} + mkdir -p "${CMOCKA_INSTALL}" gem install mustache } @@ -53,6 +53,20 @@ netbsd_install() { } linux_install() { + sudo gem install mustache +} + +msys_install() { + packages=( + automake + mingw-w64-x86_64-cmocka + mingw64/mingw-w64-x86_64-ninja + mingw64/mingw-w64-x86_64-cmake + mingw64/mingw-w64-x86_64-graphviz # for doxygen's dot component + openssl-devel + doxygen + ) + pacman --noconfirm -S --needed "${packages[@]}" gem install mustache } @@ -72,6 +86,8 @@ main() { macos_install ;; linux*) linux_install ;; + msys*) + msys_install ;; *) echo "unknown"; exit 1 ;; esac diff --git a/ci/checkpatch.sh b/ci/checkpatch.sh index a5aa8e6d..551f6bd0 100755 --- a/ci/checkpatch.sh +++ b/ci/checkpatch.sh @@ -4,49 +4,63 @@ set -eu CHECKPATCH=$CHECKPATCH_INSTALL/checkpatch.pl CHECKPATCH_TYPEDEFS=$CHECKPATCH_INSTALL/typedefs.checkpatch -CHECKPATCH_FLAGS+=" --no-tree" -CHECKPATCH_FLAGS+=" --ignore COMPLEX_MACRO" -CHECKPATCH_FLAGS+=" --ignore TRAILING_SEMICOLON" -CHECKPATCH_FLAGS+=" --ignore LONG_LINE" -CHECKPATCH_FLAGS+=" --ignore LONG_LINE_STRING" -CHECKPATCH_FLAGS+=" --ignore LONG_LINE_COMMENT" -CHECKPATCH_FLAGS+=" --ignore SYMBOLIC_PERMS" -CHECKPATCH_FLAGS+=" --ignore NEW_TYPEDEFS" -CHECKPATCH_FLAGS+=" --ignore SPLIT_STRING" -CHECKPATCH_FLAGS+=" --ignore USE_FUNC" -CHECKPATCH_FLAGS+=" --ignore COMMIT_LOG_LONG_LINE" -CHECKPATCH_FLAGS+=" --ignore FILE_PATH_CHANGES" -CHECKPATCH_FLAGS+=" --ignore MISSING_SIGN_OFF" -CHECKPATCH_FLAGS+=" --ignore RETURN_PARENTHESES" -CHECKPATCH_FLAGS+=" --ignore STATIC_CONST_CHAR_ARRAY" -CHECKPATCH_FLAGS+=" --ignore ARRAY_SIZE" -CHECKPATCH_FLAGS+=" --ignore NAKED_SSCANF" -CHECKPATCH_FLAGS+=" --ignore SSCANF_TO_KSTRTO" -CHECKPATCH_FLAGS+=" --ignore EXECUTE_PERMISSIONS" -CHECKPATCH_FLAGS+=" --ignore MULTISTATEMENT_MACRO_USE_DO_WHILE" -CHECKPATCH_FLAGS+=" --ignore STORAGE_CLASS" -CHECKPATCH_FLAGS+=" --ignore SPDX_LICENSE_TAG" -CHECKPATCH_FLAGS+=" --ignore PREFER_ALIGNED" -CHECKPATCH_FLAGS+=" --ignore EMAIL_SUBJECT" +CHECKPATCH_FLAGS=( + --no-tree + --ignore COMPLEX_MACRO + --ignore TRAILING_SEMICOLON + --ignore LONG_LINE + --ignore LONG_LINE_STRING + --ignore LONG_LINE_COMMENT + --ignore SYMBOLIC_PERMS + --ignore NEW_TYPEDEFS + --ignore SPLIT_STRING + --ignore USE_FUNC + --ignore COMMIT_LOG_LONG_LINE + --ignore FILE_PATH_CHANGES + --ignore MISSING_SIGN_OFF + --ignore RETURN_PARENTHESES + --ignore STATIC_CONST_CHAR_ARRAY + --ignore ARRAY_SIZE + --ignore NAKED_SSCANF + --ignore SSCANF_TO_KSTRTO + --ignore EXECUTE_PERMISSIONS + --ignore MULTISTATEMENT_MACRO_USE_DO_WHILE + --ignore STORAGE_CLASS + --ignore SPDX_LICENSE_TAG + --ignore PREFER_ALIGNED + --ignore EMAIL_SUBJECT +) # checkpatch.pl will ignore the following paths -CHECKPATCH_IGNORE+=" checkpatch.pl.patch Makefile test/Makefile test/http.redirect/hello.txt src/v2/parson.c src/v2/parson.h *.json" -CHECKPATCH_EXCLUDE=$(for p in $CHECKPATCH_IGNORE; do echo ":(exclude)$p" ; done) +CHECKPATCH_IGNORE=(checkpatch.pl.patch Makefile test/Makefile test/http.redirect/hello.txt src/v2/parson.c src/v2/parson.h "*.json") +CHECKPATCH_EXCLUDE=("${CHECKPATCH_IGNORE[@]/#/":(exclude)"}") -function _checkpatch() { - $CHECKPATCH $CHECKPATCH_FLAGS --typedefsfile=$CHECKPATCH_TYPEDEFS --no-tree - +_checkpatch() { + "$CHECKPATCH" "${CHECKPATCH_FLAGS[@]}" "--typedefsfile=$CHECKPATCH_TYPEDEFS" --no-tree - } -function checkpatch() { - git show --oneline --no-patch $1 - git format-patch -1 $1 --stdout -- $CHECKPATCH_EXCLUDE . | _checkpatch +checkpatch() { + local commit="${1:?Missing commit}" + git show --oneline --no-patch "${commit}" + git format-patch -1 "${commit}" --stdout -- "${CHECKPATCH_EXCLUDE[@]}" . | _checkpatch } # checkpatch -if [ "$TRAVIS_PULL_REQUEST" == "false" ]; then +# +# Check HEAD for pull requests. +# +# NOTE: $GITHUB_HEAD_REF is only set for pull requests. +# See: https://docs.github.com/en/actions/learn-github-actions/environment-variables +if [[ -z "${GITHUB_HEAD_REF:-}" ]]; then checkpatch HEAD + +# XXX: HEAD^2 seems to only makes sense for merge commits +elif git show --format=short | head -n2 | grep -q ^Merge: +then + while read -r c; do + checkpatch "$c" + done < <(git rev-list HEAD^1..HEAD^2) else - for c in $(git rev-list HEAD^1..HEAD^2); do - checkpatch $c - done + >&2 echo "Warning: this should not be run." + exit 1 fi diff --git a/ci/env-freebsd.sh b/ci/env-freebsd.sh index 74ea6cd8..4893308f 100755 --- a/ci/env-freebsd.sh +++ b/ci/env-freebsd.sh @@ -5,4 +5,3 @@ export PATH=/usr/local/bin:$PATH export MD5SUM=/sbin/md5sum export CMOCKA_INSTALL=$(pwd)/builds/cmocka-install export CHECKPATCH_INSTALL=$(pwd)/builds/checkpatch-install -export TRAVIS_PULL_REQUEST="true" diff --git a/ci/env-macos.sh b/ci/env-macos.sh index 3438cd37..c45ecceb 100755 --- a/ci/env-macos.sh +++ b/ci/env-macos.sh @@ -5,4 +5,3 @@ export PATH=/usr/local/bin:$PATH export MD5SUM=/sbin/md5 export CMOCKA_INSTALL=$(pwd)/builds/cmocka-install export CHECKPATCH_INSTALL=$(pwd)/builds/checkpatch-install -export TRAVIS_PULL_REQUEST="true" diff --git a/ci/env-openbsd.sh b/ci/env-openbsd.sh index bf936421..a28a0f7e 100755 --- a/ci/env-openbsd.sh +++ b/ci/env-openbsd.sh @@ -5,6 +5,5 @@ export PATH=/usr/local/bin:$PATH export MD5SUM=/bin/md5 export CMOCKA_INSTALL=$(pwd)/builds/cmocka-install export CHECKPATCH_INSTALL=$(pwd)/builds/checkpatch-install -export TRAVIS_PULL_REQUEST="true" export AUTOCONF_VERSION=2.69 -export AUTOMAKE_VERSION=1.15 \ No newline at end of file +export AUTOMAKE_VERSION=1.15 diff --git a/ci/install.sh b/ci/install.sh index d21e07dc..896871c4 100755 --- a/ci/install.sh +++ b/ci/install.sh @@ -2,44 +2,9 @@ set -x set -eu -SPWD="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" +. ci/install_functions.sh -CORES="2" && [ -r /proc/cpuinfo ] && CORES=$(grep -c '^$' /proc/cpuinfo) - -# cmocka -if [ ! -e "${CMOCKA_INSTALL}/lib/libcmocka.so" ] && [ ! -e "${CMOCKA_INSTALL}/lib/libcmocka.dylib" ]; then - git clone git://git.cryptomilk.org/projects/cmocka.git ~/builds/cmocka - cd ~/builds/cmocka - git checkout tags/cmocka-1.1.1 - - cd ~/builds/ - mkdir -p cmocka-build - cd cmocka-build - cmake \ - -DCMAKE_INSTALL_DIR="${CMOCKA_INSTALL}" \ - -DLIB_INSTALL_DIR="${CMOCKA_INSTALL}/lib" \ - -DINCLUDE_INSTALL_DIR="${CMOCKA_INSTALL}/include" \ - ~/builds/cmocka - make -j${CORES} all install -fi - -# checkpatch.pl -if [ ! -e "${CHECKPATCH_INSTALL}/checkpatch.pl" ]; then - mkdir -p ${CHECKPATCH_INSTALL} - cd ${CHECKPATCH_INSTALL} - wget https://raw.githubusercontent.com/torvalds/linux/master/scripts/checkpatch.pl - chmod a+x checkpatch.pl - wget https://raw.githubusercontent.com/torvalds/linux/master/scripts/spelling.txt - patch -p0 < $SPWD/checkpatch.pl.patch - echo "invalid.struct.name" > const_structs.checkpatch - echo "JSON_Object" > typedefs.checkpatch -fi - -# install libnereon -git clone -b v0.9.4 https://github.com/riboseinc/libnereon -cd libnereon -mkdir build -cd build -cmake .. -make -sudo make install +for item in "$@" +do + install_"${item}" +done diff --git a/ci/install_functions.sh b/ci/install_functions.sh new file mode 100644 index 00000000..272c7123 --- /dev/null +++ b/ci/install_functions.sh @@ -0,0 +1,54 @@ +#!/bin/bash +set -x +set -eu + +SPWD="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" + +CORES="2" && [ -r /proc/cpuinfo ] && CORES=$(grep -c '^$' /proc/cpuinfo) + +: "${CMOCKA_VERSION:=1.1.1}" +: "${LIBNEREON_VERSION:=v0.9.4}" + +# cmocka +install_cmocka() { + if [ ! -e "${CMOCKA_INSTALL}/lib/libcmocka.so" ] && [ ! -e "${CMOCKA_INSTALL}/lib/libcmocka.dylib" ]; then + git clone https://git.cryptomilk.org/projects/cmocka.git ~/builds/cmocka + cd ~/builds/cmocka + git checkout tags/cmocka-"${CMOCKA_VERSION}" + + cd ~/builds/ + mkdir -p cmocka-build + cd cmocka-build + cmake \ + -DCMAKE_INSTALL_DIR="${CMOCKA_INSTALL}" \ + -DLIB_INSTALL_DIR="${CMOCKA_INSTALL}/lib" \ + -DINCLUDE_INSTALL_DIR="${CMOCKA_INSTALL}/include" \ + ~/builds/cmocka + make -j"${CORES}" all install + fi +} + +# checkpatch.pl +install_checkpatch() { + if [ ! -e "${CHECKPATCH_INSTALL}/checkpatch.pl" ]; then + mkdir -p "${CHECKPATCH_INSTALL}" + cd "${CHECKPATCH_INSTALL}" + wget https://raw.githubusercontent.com/torvalds/linux/master/scripts/checkpatch.pl + chmod a+x checkpatch.pl + wget https://raw.githubusercontent.com/torvalds/linux/master/scripts/spelling.txt + patch -p0 < "$SPWD"/checkpatch.pl.patch + echo "invalid.struct.name" > const_structs.checkpatch + echo "JSON_Object" > typedefs.checkpatch + fi +} + +# install libnereon +install_libnereon() { + git clone -b "${LIBNEREON_VERSION}" https://github.com/riboseinc/libnereon + cd libnereon + mkdir build + cd build + cmake .. + make + sudo make install +} diff --git a/ci/main.sh b/ci/main.sh index 728ca4df..10cdd0a7 100755 --- a/ci/main.sh +++ b/ci/main.sh @@ -7,24 +7,30 @@ CFLAGS="-I${CMOCKA_INSTALL}/include" export LD_LIBRARY_PATH CFLAGS LDFLAGS +install_retrace() { + sh autogen.sh && \ + ./configure \ + --disable-silent-rules \ + --with-cmocka="${CMOCKA_INSTALL}" \ + --enable-tests && \ + make clean && \ + make -sh autogen.sh && \ + sudo make install + make check +} + +test_retrace() { + make clean ./configure \ - --disable-silent-rules \ - --with-cmocka=${CMOCKA_INSTALL} \ + --enable-v2 \ --enable-tests && \ - make clean && \ - make + make clean + make V=1 -sudo make install -make check - -make clean -./configure \ - --enable-v2 \ - --enable-tests && \ - make clean - make V=1 + sudo make install + make check +} -sudo make install -make check +install_retrace +test_retrace