-
Notifications
You must be signed in to change notification settings - Fork 0
116 lines (105 loc) · 4.54 KB
/
cpp-build-test-coverage.yml
File metadata and controls
116 lines (105 loc) · 4.54 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
# -------------------------------------------------------------
# GitHub Actions Workflow: C++ Tests, Static Analysis, and Coverage
# -------------------------------------------------------------
# Purpose:
# Runs cppcheck (static analysis), builds your C++ project,
# runs unit tests, and generates a coverage report.
# -------------------------------------------------------------
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)
# - You can adjust `--enable=` options as needed
# - 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 \
./src ./include
# -------------------------------------------------------
# Step 3: Configure and build the project
# -------------------------------------------------------
- name: Prepare build
run: |
rm -rf build
mkdir build
cd build
cmake -DCMAKE_BUILD_TYPE=Debug -DENABLE_COVERAGE=ON ..
cmake --build .
# -------------------------------------------------------
# Step 4: Run unit tests
# -------------------------------------------------------
- name: Run tests
run: |
cd build
ctest --output-on-failure
# -------------------------------------------------------
# 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 exit)
# # - Modern C++ static analysis
# # - Enforces best practices
# # - Add `--warnings-as-errors=*` to exit code 1
# # -------------------------------------------------------
# - name: Run clang-tidy
# # run: |
# # echo "Running clang-tidy..."
# # clang-tidy \
# # -checks='clang-analyzer-*,modernize-*,performance-*,readability-*' \
# # -p build \
# # $(find ./src -name '*.cpp')
# run: |
# echo "Running clang-tidy using .clang-tidy options"
# clang-tidy \
# -p build \
# -header-filter='^src/.*' $(find src -name "*.cpp")