Skip to content

Commit 5ff06bc

Browse files
committed
Added github action
Aslo updateed Dockerfile - removed build stage
1 parent 7d89843 commit 5ff06bc

2 files changed

Lines changed: 106 additions & 8 deletions

File tree

Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
# -------------------------------------------------------------
2+
# GitHub Actions Workflow: C++ Tests, Static Analysis, and Coverage
3+
# -------------------------------------------------------------
4+
# Purpose:
5+
# Runs cppcheck (static analysis), builds your C++ project,
6+
# runs unit tests, and generates a coverage report.
7+
# -------------------------------------------------------------
8+
9+
name: C++ Tests and Coverage
10+
11+
# -------------------------------------------------------------
12+
# Triggers:
13+
# Run this workflow automatically whenever code is pushed
14+
# or a pull request is opened against the master branch.
15+
# -------------------------------------------------------------
16+
on:
17+
push:
18+
branches: [master]
19+
pull_request:
20+
branches: [master]
21+
22+
jobs:
23+
build-and-test:
24+
# ---------------------------------------------------------
25+
# The GitHub-hosted runner type to use (the host machine).
26+
# Ubuntu 24.04 provides Docker, Git, and build tools.
27+
# ---------------------------------------------------------
28+
runs-on: ubuntu-24.04
29+
30+
# ---------------------------------------------------------
31+
# Run all job steps inside this Docker container.
32+
# This ensures a consistent C++ build environment
33+
# with specific compiler and tool versions.
34+
# ---------------------------------------------------------
35+
container:
36+
image: urboob21/cpp-lab:latest
37+
38+
steps:
39+
# -------------------------------------------------------
40+
# Step 1: Checkout the repository source code
41+
# -------------------------------------------------------
42+
- name: Checkout source
43+
uses: actions/checkout@v4
44+
45+
# -------------------------------------------------------
46+
# Step 2: Run Cppcheck (Static Analysis)
47+
# - Scans for common C++ issues (style, memory, logic)
48+
# - You can adjust `--enable=` options as needed
49+
# -------------------------------------------------------
50+
- name: Run static analysis with Cppcheck
51+
run: |
52+
echo "Running Cppcheck..."
53+
cppcheck --enable=warning,style,performance,portability \
54+
--inconclusive \
55+
--quiet \
56+
--error-exitcode=1 \
57+
./src ./include
58+
59+
# -------------------------------------------------------
60+
# Step 3: Configure and build the project
61+
# -------------------------------------------------------
62+
- name: Prepare build
63+
run: |
64+
rm -rf build
65+
mkdir build
66+
cd build
67+
cmake ..
68+
cmake --build .
69+
70+
# -------------------------------------------------------
71+
# Step 4: Run unit tests
72+
# TODO: need to update, I think we should not hard-code the executable name here
73+
# -------------------------------------------------------
74+
- name: Run tests
75+
run: |
76+
ls -l
77+
./build/cpp_lab_project_test
78+
79+
# -------------------------------------------------------
80+
# Step 5: Generate code coverage report
81+
# -------------------------------------------------------
82+
- name: Generate coverage report
83+
run: |
84+
lcov -d . -c -o coverage.info
85+
lcov -r coverage.info "*/build/*" "*/tests/*" "*/c++/*" -o coverageFiltered.info
86+
lcov --list coverageFiltered.info
87+
88+
# -------------------------------------------------------
89+
# Step 6: Upload coverage summary to GitHub summary
90+
# -------------------------------------------------------
91+
- name: Upload coverage to GitHub summary
92+
run: |
93+
echo "## Test Coverage Summary" >> $GITHUB_STEP_SUMMARY
94+
lcov --summary coverageFiltered.info >> $GITHUB_STEP_SUMMARY

Dockerfile

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
# Define a new image from Ubuntu 2404
2+
# Dockerfile → defines your environment (compiler, cmake, libraries, tools).
3+
24
FROM ubuntu:24.04
35

46
# Install prerequisites
@@ -9,7 +11,9 @@ RUN \
911
apt-get update && \
1012
# install cmake, gcc, g++
1113
apt-get install -y cmake && \
12-
apt-get install -y gcc g++
14+
apt-get install -y gcc g++ && \
15+
# install cppcheck
16+
apt-get install -y cppcheck
1317

1418
# Set the working directory inside the Docker image
1519
WORKDIR /cpp-lab
@@ -19,10 +23,10 @@ WORKDIR /cpp-lab
1923
# COPY . .
2024
COPY . /cpp-lab
2125

22-
# Build the main and test targets
23-
RUN \
24-
# create a build folder
25-
rm -rf build && mkdir build && \
26-
cd build && \
27-
cmake .. && \
28-
cmake --build .
26+
# # Build the main and test targets
27+
# RUN \
28+
# # create a build folder
29+
# rm -rf build && mkdir build && \
30+
# cd build && \
31+
# cmake .. && \
32+
# cmake --build .

0 commit comments

Comments
 (0)