From 5abf6d1081d4d85f3972fca7d04b17028e84d598 Mon Sep 17 00:00:00 2001 From: Suhashini Naik Date: Tue, 12 Nov 2024 16:22:06 +0530 Subject: [PATCH] Add code-coverage Github action --- .github/workflows/build.yml | 58 ++++++++++++++++++++--------- .github/workflows/code-coverage.yml | 21 ++++++++++- 2 files changed, 59 insertions(+), 20 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 8b57148788..2b51f9a7d8 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -1,4 +1,4 @@ -name: CMake on a single platform +name: Compile, Cache, and Test on: [workflow_call, push, pull_request] @@ -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 diff --git a/.github/workflows/code-coverage.yml b/.github/workflows/code-coverage.yml index 7fd7d36959..ed4b8fb804 100644 --- a/.github/workflows/code-coverage.yml +++ b/.github/workflows/code-coverage.yml @@ -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 @@ -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: @@ -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..."