Skip to content

Commit

Permalink
Add code-coverage Github action
Browse files Browse the repository at this point in the history
  • Loading branch information
SuhashiniNaik committed Nov 12, 2024
1 parent 75c5d33 commit 5abf6d1
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 20 deletions.
58 changes: 40 additions & 18 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: CMake on a single platform
name: Compile, Cache, and Test

on: [workflow_call, push, pull_request]

Expand All @@ -11,21 +11,43 @@ jobs:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4
- name: Setup cmake
uses: jwlawson/actions-setup-cmake@v2
with:
cmake-version: '3.22.x'
- name: Configure CMake
run: cmake -B cmake-build-posix -S executables/referenceApp -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}}

- name: Build
run: cmake --build cmake-build-posix --target app.referenceApp -j --config ${{env.BUILD_TYPE}}

- name: Test
# Execute tests defined by the CMake configuration.
run: |
cmake -B cmake-build-unit-tests -S executables/unitTest -DBUILD_UNIT_TESTS=ON
cmake --build cmake-build-unit-tests -j4
ctest --test-dir cmake-build-unit-tests -j4
- uses: actions/checkout@v4

# Setup CMake
- name: Setup CMake
uses: jwlawson/actions-setup-cmake@v2
with:
cmake-version: '3.22.x'

- name: Cache Build Results
uses: actions/cache@v3
id: cache
with:
path: cmake-build-posix
key: ${{ github.ref }}-cmake-build-posix

- name: Configure CMake
if: steps.cache.outputs.cache-hit != 'true'
run: cmake -B cmake-build-posix -S executables/referenceApp -DCMAKE_BUILD_TYPE=${{ env.BUILD_TYPE }}

- name: Build Project
if: steps.cache.outputs.cache-hit != 'true'
run: cmake --build cmake-build-posix --target app.referenceApp -j --config ${{ env.BUILD_TYPE }}

- name: Cache Unit Test Build
uses: actions/cache@v3
id: test-cache
with:
path: cmake-build-unit-tests
key: ${{ github.ref }}-unit-tests

- name: Configure Unit Tests
if: steps.test-cache.outputs.cache-hit != 'true'
run: cmake -B cmake-build-unit-tests -S executables/unitTest -DBUILD_UNIT_TESTS=ON

- name: Build Unit Tests
if: steps.test-cache.outputs.cache-hit != 'true'
run: cmake --build cmake-build-unit-tests -j4

- name: Run Unit Tests
run: ctest --test-dir cmake-build-unit-tests -j4
21 changes: 19 additions & 2 deletions .github/workflows/code-coverage.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,22 @@ jobs:
steps:
- uses: actions/checkout@v4

# Code coverage
- name: Restore CMake Build Cache (Posix)
uses: actions/cache@v3
id: posix-cache
with:
path: cmake-build-posix
key: ${{ github.ref }}-cmake-build-posix


- name: Restore Unit Test Build Cache
uses: actions/cache@v3
id: unit-tests-cache
with:
path: cmake-build-unit-tests
key: ${{ github.ref }}-unit-tests

# Install lcov for code coverage
- name: Install lcov
run: sudo apt install -y lcov

Expand All @@ -44,7 +59,8 @@ jobs:
echo "Generating HTML coverage report..."
genhtml cmake-build-unit-tests/coverage.info \
--output-directory cmake-build-unit-tests/coverage
# Deploy to GitHub Pages
- name: Deploy to GitHub Pages
uses: peaceiris/actions-gh-pages@v4
with:
Expand All @@ -53,6 +69,7 @@ jobs:
destination_dir: code-coverage
force_orphan: false

# Optionally zip and upload the coverage report as an artifact
# - name: Zip coverage report
# run: |
# echo "Zipping coverage report..."
Expand Down

0 comments on commit 5abf6d1

Please sign in to comment.