name: C++ Tests; Full Static Analysis on: push: branches: - develop - main paths: - '.github/workflows/cpp.yml' - 'cpp/**' - 'go/**' - 'proto/**' pull_request: branches: - develop - main types: - opened - synchronize - reopened paths: - '.github/workflows/cpp.yml' - 'cpp/**' - 'go/**' - 'proto/**' env: APT_PACKAGES: groff libspdlog-dev libpcap-dev libevdev2 libev-dev protobuf-compiler libgtest-dev libgmock-dev meson ninja-build GO_VERSION: '1.25.13' jobs: unit_tests: runs-on: ubuntu-24.04 defaults: run: working-directory: cpp steps: - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 - name: Install dependencies run: sudo apt-get install ${{ env.APT_PACKAGES }} - name: Build unit tests run: DEBUG=1 make -j $(nproc) test - name: Run unit tests run: (set -o pipefail && GTEST_SHUFFLE=1 bin/piscsi_test | tee piscsi_test_log.txt) - name: Upload logs uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1 with: name: piscsi_test_log.txt path: cpp/piscsi_test_log.txt unit_tests_meson: runs-on: ubuntu-24.04 defaults: run: working-directory: . steps: - uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0 - name: Install dependencies run: sudo apt-get install ${{ env.APT_PACKAGES }} - name: Configure build run: meson setup build - name: Build unit tests run: meson compile -C build - name: Run unit tests run: GTEST_SHUFFLE=1 meson test -C build - name: Upload logs uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1 with: name: testlog.txt path: build/meson-logs/testlog.txt sonarcloud: runs-on: ubuntu-24.04 if: > (github.event_name == 'push' && github.actor != 'dependabot[bot]' && github.actor != 'dependabot') || (github.event_name == 'pull_request' && !github.event.pull_request.head.repo.fork && github.actor != 'dependabot[bot]' && github.actor != 'dependabot') env: BUILD_WRAPPER_OUT_DIR: ${{ github.workspace }}/.build_wrapper_out steps: - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 with: fetch-depth: 0 - name: Install dependencies run: sudo apt-get install ${{ env.APT_PACKAGES }} - uses: actions/setup-go@v7 with: go-version: ${{ env.GO_VERSION }} cache-dependency-path: go/go.sum - name: Install Build Wrapper uses: SonarSource/sonarqube-scan-action/install-build-wrapper@22918119ff8e1ca75a623e15c8296b6ea4fbe28f # v8.2.1 - name: Generate coverage and compilation database run: | mkdir -p "${{ env.BUILD_WRAPPER_OUT_DIR }}" build-wrapper-linux-x86-64 --out-dir "${{ env.BUILD_WRAPPER_OUT_DIR }}" \ make -j "$(nproc)" -C cpp coverage - name: Validate compilation database env: COMPILATION_DATABASE: >- ${{ env.BUILD_WRAPPER_OUT_DIR }}/compile_commands.json run: | test -s "$COMPILATION_DATABASE" jq -e 'type == "array" and length > 0' "$COMPILATION_DATABASE" > /dev/null jq -r '.[].file' "$COMPILATION_DATABASE" | sort -u \ | wc -l - name: Run gcov working-directory: cpp run: gcov --preserve-paths $(find -name '*.gcno') - name: Generate Go sources working-directory: go run: | go install google.golang.org/protobuf/cmd/protoc-gen-go@v1.36.11 export PATH="$(go env GOPATH)/bin:$PATH" make proto - name: Generate Go coverage working-directory: go run: go test -tags nomsgpack -coverprofile=coverage.txt -covermode=atomic ./... - name: Run sonar-scanner uses: sonarsource/sonarqube-scan-action@22918119ff8e1ca75a623e15c8296b6ea4fbe28f # v8.2.1 env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} with: args: | --define sonar.cfamily.compile-commands=${{ env.BUILD_WRAPPER_OUT_DIR }}/compile_commands.json --define sonar.projectKey=akuker-PISCSI --define sonar.organization=piscsi --define sonar.sources=cpp,go --define sonar.cfamily.gcov.reportsPath=cpp --define sonar.go.coverage.reportPaths=go/coverage.txt --define sonar.coverage.exclusions=cpp/test/**,go/**/*_test.go --define sonar.cpd.exclusions=cpp/test/**