-
Notifications
You must be signed in to change notification settings - Fork 0
145 lines (127 loc) · 5.8 KB
/
Copy pathcpp-build-test-coverage.yml
File metadata and controls
145 lines (127 loc) · 5.8 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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
# -------------------------------------------------------------
# GitHub Actions Workflow: C++ Tests, Static Analysis, and Coverage
# -------------------------------------------------------------
# Purpose:
# Runs cppcheck (static analysis), builds your C++ project,
# runs the unit tests and one smoke test per example,
# generates a coverage report, and repeats the tests with
# AddressSanitizer + UndefinedBehaviorSanitizer.
# -------------------------------------------------------------
name: C++ Tests and Coverage
# -------------------------------------------------------------
# Triggers:
# Run this workflow automatically whenever code is pushed
# or a pull request is opened against the master branch.
# -------------------------------------------------------------
on:
push:
branches: [master]
pull_request:
branches: [master]
jobs:
build-and-test:
# ---------------------------------------------------------
# The GitHub-hosted runner type to use (the host machine).
# Ubuntu 24.04 provides Docker, Git, and build tools.
# ---------------------------------------------------------
runs-on: ubuntu-24.04
# ---------------------------------------------------------
# Run all job steps inside this Docker container.
# This ensures a consistent C++ build environment
# with specific compiler and tool versions.
# ---------------------------------------------------------
container:
image: urboob21/cpp-lab:latest
steps:
# -------------------------------------------------------
# Step 1: Checkout the repository source code
# -------------------------------------------------------
- name: Checkout source
uses: actions/checkout@v4
# -------------------------------------------------------
# Step 2: Run Cppcheck (Static Analysis)
# - Scans for common C++ issues (style, memory, logic)
# - -I include lets cppcheck understand the LAB_EXAMPLE macro
# - https://cppcheck.sourceforge.io/manual.pdf
# -------------------------------------------------------
- name: Run static analysis with Cppcheck
run: |
echo "Running Cppcheck..."
cppcheck --enable=warning,style,performance,portability \
--inconclusive \
--quiet \
--inline-suppr \
--error-exitcode=1 \
-I include \
--suppressions-list=.cppcheck-suppressions \
./src ./include
# -------------------------------------------------------
# Step 3: Configure and build the project
# -------------------------------------------------------
- name: Build
run: |
cmake -S . -B build -DCMAKE_BUILD_TYPE=Debug -DENABLE_COVERAGE=ON
cmake --build build -j "$(nproc)"
# -------------------------------------------------------
# Step 4: Run unit tests and example smoke tests
# -------------------------------------------------------
- name: Run tests
run: ctest --test-dir build --output-on-failure -j "$(nproc)"
# -------------------------------------------------------
# Step 5: Generate code coverage report
# -------------------------------------------------------
- name: Generate coverage report
run: |
cd build
lcov --rc geninfo_unexecuted_blocks=1 --ignore-errors mismatch -d . -c -o coverage.info
lcov -r coverage.info "*/_deps/*" "/usr/*" "*/tests/*" -o coverageFiltered.info
lcov --list coverageFiltered.info
# -------------------------------------------------------
# Step 6: Upload coverage summary to GitHub summary
# -------------------------------------------------------
- name: Upload coverage to GitHub summary
run: |
cd build
echo "## Test Coverage Summary" >> $GITHUB_STEP_SUMMARY
lcov --summary coverageFiltered.info >> $GITHUB_STEP_SUMMARY
# # -------------------------------------------------------
# # Step 7: Run Clang-Tidy (experimenting, not enforced)
# # - Modern C++ static analysis, configured by .clang-tidy
# # -------------------------------------------------------
# - name: Run clang-tidy
# run: |
# clang-tidy -p build -header-filter='^src/.*' $(find src -name "*.cpp")
release:
# ---------------------------------------------------------
# A Release build with warnings as errors: optimizations enable extra
# compiler diagnostics that a Debug build never reports.
# ---------------------------------------------------------
runs-on: ubuntu-24.04
container:
image: urboob21/cpp-lab:latest
steps:
- name: Checkout source
uses: actions/checkout@v4
- name: Build and test in Release
run: |
cmake -S . -B build-release -DCMAKE_BUILD_TYPE=Release \
-DCPPLAB_WARNINGS_AS_ERRORS=ON -DCPPLAB_BUILD_GUI=OFF
cmake --build build-release -j "$(nproc)"
ctest --test-dir build-release --output-on-failure -j "$(nproc)"
sanitizers:
# ---------------------------------------------------------
# Same tests with AddressSanitizer + UndefinedBehaviorSanitizer:
# memory errors, leaks and undefined behavior fail the job.
# ---------------------------------------------------------
runs-on: ubuntu-24.04
container:
image: urboob21/cpp-lab:latest
steps:
- name: Checkout source
uses: actions/checkout@v4
- name: Build with sanitizers
run: |
cmake -S . -B build-asan -DCMAKE_BUILD_TYPE=Debug -DCPPLAB_ENABLE_SANITIZERS=ON -DCPPLAB_BUILD_GUI=OFF
cmake --build build-asan -j "$(nproc)"
- name: Run tests with sanitizers
run: ctest --test-dir build-asan --output-on-failure -j "$(nproc)"