CI (GitHub & sourcehut): add clang-tidy checks.
[tinc] / .github / workflows / test.yml
index 1b819a6..900af01 100644 (file)
@@ -8,22 +8,43 @@ on:
       - synchronize
 
 jobs:
-  code-style:
+  static-analysis:
     runs-on: ubuntu-latest
+    timeout-minutes: 10
     steps:
       - name: Checkout code
         uses: actions/checkout@v2
 
-      - name: Install code formatting tools
+      - name: Install tools
         run: |
-          sudo apt-get install -y astyle
-          curl -OL 'https://github.com/koalaman/shellcheck/releases/download/v0.7.2/shellcheck-v0.7.2.linux.x86_64.tar.xz'
+          sudo apt-get install -y astyle clang-tidy-$CLANG
+          sudo update-alternatives --install /usr/bin/clang-tidy clang-tidy /usr/bin/clang-tidy-$CLANG 100
+          curl -OL "https://github.com/koalaman/shellcheck/releases/download/v$SHELLCHECK/shellcheck-v${SHELLCHECK}.linux.x86_64.tar.xz"
           tar -C ~ --strip-components=1 --wildcards -xf ./shellcheck-*.tar.xz 'shellcheck-*/shellcheck'
-          curl -o ~/shfmt -L 'https://github.com/mvdan/sh/releases/download/v3.3.0/shfmt_v3.3.0_linux_amd64'
+          curl -o ~/shfmt -L "https://github.com/mvdan/sh/releases/download/v$SHFMT/shfmt_v${SHFMT}_linux_amd64"
           chmod 755 ~/shfmt ~/shellcheck
+          pip3 install --user compiledb
+        env:
+          CLANG: 11
+          SHELLCHECK: 0.7.2
+          SHFMT: 3.3.0
+
+      - name: Install deps
+        run: >
+          sudo apt-get install -y
+          git binutils make autoconf automake diffutils texinfo netcat
+          zlib1g-dev lib{ssl,lzo2,ncurses,readline,vdeplug,miniupnpc,gcrypt}-dev
+
+      - name: Configure and compile
+        run: |
+          autoreconf -fsi
+          ./configure --enable-{uml,vde,miniupnpc}
+          make -j$(nproc)
+          compiledb -n make check
 
       - name: Check code formatting
         run: "! astyle -r --options=.astylerc --dry-run --formatted '*.c' '*.h' | grep '^Formatted'"
+        if: always()
 
       - name: Check scripts formatting
         run: find -type f -regextype egrep -regex '.+\.(sh|sh\.in|test)$' -exec ~/shfmt -d -i 2 -s '{}' +
@@ -33,19 +54,28 @@ jobs:
         run: find -type f -regextype egrep -regex '.+\.sh(\.in)?$' -exec shellcheck -x '{}' +
         if: always()
 
-      - name: Prepare test library and run static analysis on tests
+      - name: Run static analysis on tests
+        run: find -type f -name '*.test' -execdir shellcheck -x '{}' +
+        if: always()
+
+      - name: Run clang-tidy
         run: |
-          autoreconf -fsi
-          ./configure --disable-{lzo,readline,zlib,curses}
-          find -type f -name '*.test' -execdir shellcheck -x '{}' +
+          find src \
+            ! '(' -path src/solaris -prune ')' \
+            ! '(' -path src/mingw   -prune ')' \
+            ! '(' -path src/bsd     -prune ')' \
+            -name '*.c' \
+            -exec clang-tidy --header-filter='.*' '{}' +
         if: always()
 
   sanitizer:
     runs-on: ubuntu-latest
+    timeout-minutes: 10
     strategy:
       fail-fast: false
       matrix:
         sanitizer:
+          - address
           - thread
           - undefined
     env:
@@ -86,6 +116,7 @@ jobs:
 
   linux:
     runs-on: ubuntu-latest
+    timeout-minutes: 10
     strategy:
       fail-fast: false
       matrix:
@@ -103,20 +134,21 @@ jobs:
     container:
       image: ${{ matrix.os }}
       options: --privileged
-
+      env:
+        CI: 1
     steps:
       - name: Install deps (Alpine)
         run: >
           apk add git binutils make autoconf automake gcc linux-headers libtool
           diffutils texinfo procps openssl-dev zlib-dev lzo-dev ncurses-dev
-          readline-dev musl-dev lz4-dev socat
+          readline-dev musl-dev lz4-dev socat shadow sudo
         if: startsWith(matrix.os, 'alpine')
 
       - name: Install deps (Debian and Ubuntu)
         shell: bash
         run: |
           apt-get update
-          apt-get install -y git binutils make autoconf automake gcc diffutils \
+          apt-get install -y git binutils make autoconf automake gcc diffutils sudo \
             texinfo netcat procps socat zlib1g-dev lib{ssl,lzo2,lz4,ncurses,readline}-dev
         env:
           DEBIAN_FRONTEND: noninteractive
@@ -130,14 +162,15 @@ jobs:
             dnf config-manager --enable powertools
           fi
           yum install -y epel-release
-          yum install -y git binutils make autoconf automake gcc diffutils \
-            texinfo netcat procps socat {lzo,zlib,lz4,openssl,ncurses,readline}-devel
+          yum install -y git binutils make autoconf automake gcc diffutils sudo \
+            texinfo netcat procps socat {lzo,zlib,lz4,ncurses,readline}-devel
+          yum install -y openssl11-devel || yum install -y openssl-devel
         if: startsWith(matrix.os, 'centos') || startsWith(matrix.os, 'alma')
 
       - name: Install deps (SUSE)
         shell: bash
         run: >
-          zypper install -y tar git binutils make autoconf automake gcc procps
+          zypper install -y tar git binutils make autoconf automake gcc procps sudo
           makeinfo diffutils gzip socat {openssl,zlib,lzo,liblz4,ncurses,readline}-devel
         if: startsWith(matrix.os, 'opensuse')
 
@@ -149,11 +182,17 @@ jobs:
       - name: Assign name for test results artifact
         run: echo TEST_ARTIFACT="$(echo '${{ matrix.os }}' | sed 's|[:/]|_|g')" >>"$GITHUB_ENV"
 
+      - name: Create a non-privileged user
+        run: |
+          useradd --user-group build
+          chown -R build:build .
+          echo 'build ALL=(ALL) NOPASSWD: ALL' >/etc/sudoers.d/build
+
       - name: Run tests with default settings
-        run: sh .github/workflows/test/run.sh default
+        run: sudo -u build CI=1 sh .github/workflows/test/run.sh default
 
       - name: Run tests without legacy protocol
-        run: sh .github/workflows/test/run.sh nolegacy
+        run: sudo -u build CI=1 sh .github/workflows/test/run.sh nolegacy
 
       - name: Upload test results
         uses: actions/upload-artifact@v2
@@ -171,6 +210,7 @@ jobs:
         os: [ubuntu-18.04, ubuntu-20.04]
 
     runs-on: ${{ matrix.os }}
+    timeout-minutes: 5
 
     steps:
       - name: Checkout code
@@ -219,6 +259,7 @@ jobs:
         os: [ubuntu-18.04, ubuntu-20.04]
 
     runs-on: ${{ matrix.os }}
+    timeout-minutes: 5
 
     steps:
       - name: Download built packages
@@ -250,6 +291,7 @@ jobs:
 
   macos:
     runs-on: macos-latest
+    timeout-minutes: 10
 
     strategy:
       fail-fast: false
@@ -263,18 +305,42 @@ jobs:
           fetch-depth: 0
 
       - name: Install build deps
-        run: brew install coreutils netcat automake lzo lz4 miniupnpc
+        run: |
+          brew install coreutils netcat automake lzo lz4 miniupnpc
+          pip3 install --user compiledb
 
-      - name: Configure project
+      - name: Configure and compile
         run: |
+          export CPPFLAGS="-I/usr/local/include"
+          export CPPFLAGS="$CPPFLAGS -I$(brew --prefix libgcrypt)/include"
+          export CPPFLAGS="$CPPFLAGS -I$(brew --prefix openssl)/include"
+          export CPPFLAGS="$CPPFLAGS -I$(brew --prefix libgcrypt)/include"
+
           autoreconf -fsi
-          ./configure --with-openssl=/usr/local/opt/openssl@1.1 --enable-{tunemu,miniupnpc} ${{ matrix.legacy_protocol }}
+          ./configure \
+            --with-openssl="$(brew --prefix openssl)" \
+            --with-miniupnpc="$(brew --prefix miniupnpc)" \
+            --enable-{tunemu,miniupnpc} \
+            ${{ matrix.legacy_protocol }}
 
-      - name: Compile project
-        run: make -j$(sysctl -n hw.ncpu)
+          make -j$(sysctl -n hw.ncpu)
 
       - name: Run tests
-        run: make check-recursive VERBOSE=1
+        run: |
+          export PATH="$PATH:$HOME/Library/Python/3.9/bin"
+          compiledb make -j$(sysctl -n hw.ncpu) check VERBOSE=1
+
+      - name: Run clang-tidy
+        run: |
+          export PATH="$PATH:$(brew --prefix llvm)/bin/"
+          find src \
+            ! '(' -path src/solaris -prune ')' \
+            ! '(' -path src/mingw   -prune ')' \
+            ! '(' -path src/linux   -prune ')' \
+            ! -name vde_device.c \
+            -name '*.c' \
+            -exec clang-tidy --header-filter='.*' '{}' +
+        if: ${{ matrix.legacy_protocol == '' }}
 
       - name: Archive test results
         run: sudo tar -c -z -f test-results.tar.gz test/
@@ -289,6 +355,7 @@ jobs:
 
   windows:
     runs-on: windows-latest
+    timeout-minutes: 20
 
     strategy:
       fail-fast: false