Skip to content

Merge pull request #27 from urboob21/dev_branch #69

Merge pull request #27 from urboob21/dev_branch

Merge pull request #27 from urboob21/dev_branch #69

# -------------------------------------------------------------
# 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
# TODO: need to update, I think we should not hard-code the executable name here
# -------------------------------------------------------
- name: Run tests
run: |
cd build
ls -l
./cpp_lab_project_unit_test
# -------------------------------------------------------
# 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