Skip to content

ci(benchmarks): run PR benchmarks outside default build #33

ci(benchmarks): run PR benchmarks outside default build

ci(benchmarks): run PR benchmarks outside default build #33

Workflow file for this run

name: Build & SonarQube
on:
push:
branches: [ main, develop ]
paths-ignore:
- '*.md'
- '**/*.md'
pull_request:
types: [ opened, synchronize, reopened ]
paths-ignore:
- '*.md'
- '**/*.md'
permissions:
contents: read
pull-requests: read
jobs:
build:
name: GCC 15 • Build • Test • Coverage • Sonar
runs-on: ubuntu-latest
# Use a container that already has GCC 15
container:
image: gcc:15
env:
# Must match your sonar-project.properties:
# sonar.cfamily.compile-commands=build/bw-output/compile_commands.json
BUILD_WRAPPER_OUT_DIR: build/bw-output
CTEST_OUTPUT_ON_FAILURE: "1"
steps:
- name: Install prerequisites (cmake, ninja, coverage tools, git, ca-certs, unzip, python3)
run: |
apt-get update
DEBIAN_FRONTEND=noninteractive apt-get install -y \
cmake ninja-build gcovr lcov git ca-certificates unzip jq python3
update-ca-certificates
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Toolchain sanity check
run: |
gcc --version
g++ --version
gcov --version || true
ninja --version
cmake --version
- name: Install Sonar Build Wrapper
uses: SonarSource/sonarqube-scan-action/install-build-wrapper@v6
# Equivalent to: rm -rf build && cmake -S . -B build
- name: Configure (CMake • Debug • Ninja • GCC 15)
env:
CC: gcc
CXX: g++
run: |
rm -rf build "${BUILD_WRAPPER_OUT_DIR}"
cmake -S . -B build -G Ninja \
-DCMAKE_BUILD_TYPE=Debug \
-DCMAKE_EXPORT_COMPILE_COMMANDS=ON \
-DCMAKE_C_COMPILER="${CC}" \
-DCMAKE_CXX_COMPILER="${CXX}"
# Equivalent to: cmake --build build -j
- name: Build (unwrapped compile)
run: |
cmake --build build -j"$(nproc)"
# Equivalent to: cmake --build build --target sonar_bw -j
- name: Build (CMake target sonar_bw wrapped by build-wrapper)
run: |
cmake --build build --target sonar_bw -j"$(nproc)"
env:
# Ensure the install step put it on PATH; the CMake target will also auto-detect.
BUILD_WRAPPER_OUT_DIR: ${{ env.BUILD_WRAPPER_OUT_DIR }}
# Equivalent to: ctest --test-dir build --output-on-failure
- name: Test
run: |
ctest --test-dir build --output-on-failure
# Equivalent to: cmake --build build --target coverage
- name: Coverage
run: |
cmake --build build --target coverage
# Equivalent to: sonar-scanner
- name: SonarQube Scan
uses: SonarSource/sonarqube-scan-action@v6
env:
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
SONAR_HOST_URL: https://sonarcloud.io
with:
args: >
--define sonar.organization=stephenlclarke
--define sonar.projectKey=stephenlclarke_ScopeTimer
--define sonar.cfamily.compile-commands=${{ env.BUILD_WRAPPER_OUT_DIR }}/compile_commands.json
--define sonar.coverageReportPaths=build/sonarqube-coverage.xml
benchmarks:
name: GCC 15 • PR Benchmarks
if: github.event_name == 'pull_request'
runs-on: ubuntu-latest
container:
image: gcc:15
steps:
- name: Install prerequisites (cmake, ninja, git, ca-certs, python3)
run: |
apt-get update
DEBIAN_FRONTEND=noninteractive apt-get install -y \
cmake ninja-build git ca-certificates python3
update-ca-certificates
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Configure benchmark driver build
env:
CC: gcc
CXX: g++
run: |
rm -rf build build-bench
cmake -S . -B build -G Ninja \
-DCMAKE_BUILD_TYPE=Release \
-DENABLE_COVERAGE=OFF \
-DENABLE_SONAR=OFF \
-DAUTO_REFRESH_DOCS=OFF \
-DCMAKE_C_COMPILER="${CC}" \
-DCMAKE_CXX_COMPILER="${CXX}"
- name: Run benchmark matrix
run: |
cmake --build build --target demo_benchmark_matrix -j"$(nproc)"
- name: Upload benchmark report
uses: actions/upload-artifact@v4
with:
name: benchmark-report-pr-${{ github.event.pull_request.number }}
path: |
BENCHMARK.md
benchmarks/demo_benchmark_history.json