-
Notifications
You must be signed in to change notification settings - Fork 2
64 lines (54 loc) · 1.71 KB
/
c-cpp.yml
File metadata and controls
64 lines (54 loc) · 1.71 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
name: C/C++ CI
on:
push:
branches: [ "main" ]
pull_request:
branches: [ "main" ]
jobs:
build:
runs-on: ubuntu-latest
strategy:
matrix:
compiler: [gcc, clang]
env:
CMAKE_BUILD_TYPE: Release
steps:
- uses: actions/checkout@v4
# Setup compiler
- name: Set up ${{ matrix.compiler }}
run: |
if [ "${{ matrix.compiler }}" == "gcc" ]; then
sudo apt-get update
sudo apt-get install -y build-essential gcc g++ cmake cppcheck
else
sudo apt-get update
sudo apt-get install -y build-essential clang cmake cppcheck
fi
# Configure project with CMake
- name: Configure project
run: cmake -S . -B build -DCMAKE_BUILD_TYPE=${{ env.CMAKE_BUILD_TYPE }}
# Build project
- name: Build
run: cmake --build build -- -j$(nproc)
# Run tests
- name: Run tests
run: ctest --output-on-failure --test-dir build
# Static analysis
- name: Static analysis
run: cppcheck --enable=all --inconclusive --std=c++17 --force .
# Optional: Clang-Tidy (if using clang)
- name: Clang-Tidy analysis
if: matrix.compiler == 'clang'
run: |
clang-tidy $(find . -name '*.cpp') -- -I.
# Optional: Generate coverage report
- name: Coverage (if using GCC)
if: matrix.compiler == 'gcc'
run: |
sudo apt-get install -y lcov
cmake -S . -B build -DCMAKE_BUILD_TYPE=Debug -DCMAKE_CXX_FLAGS="--coverage"
cmake --build build -- -j$(nproc)
ctest --test-dir build
lcov --capture --directory build --output-file coverage.info
lcov --remove coverage.info '/usr/*' --output-file coverage.info
lcov --list coverage.info