From 62c770d4e3bdf0284f333f803807a5515866e6c3 Mon Sep 17 00:00:00 2001 From: Uriah Xuan Date: Wed, 20 Nov 2024 18:20:45 +0800 Subject: [PATCH] Add Codecov (#12) * Try: Add CI for codecov * Try: Add CI for codecov * Try: Add CI for codecov * Try: Add CI for codecov * Implement: Coverage test * Fix: Use sh instead of bash * Fix: Add gcovr * Fix: Mount coverage_build dir * Fix: Mount coverage_build dir * Fix: Mount coverage_build dir * Fix: Specific file * Fix: Docker volume * Fix: Name issue --- .github/workflows/codecov.yml | 34 ++++++++++++++++++++++++++++++++++ CMakeLists.txt | 13 ++++++++++--- Dockerfile | 2 +- Dockerfile.coverage | 8 ++++++++ scripts/coverage.sh | 9 +++++++-- 5 files changed, 60 insertions(+), 6 deletions(-) create mode 100644 .github/workflows/codecov.yml create mode 100644 Dockerfile.coverage mode change 100644 => 100755 scripts/coverage.sh diff --git a/.github/workflows/codecov.yml b/.github/workflows/codecov.yml new file mode 100644 index 0000000..178a887 --- /dev/null +++ b/.github/workflows/codecov.yml @@ -0,0 +1,34 @@ +name: Run tests and upload coverage + +on: + push + +jobs: + test: + name: Run tests and collect coverage + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v4 + with: + fetch-depth: 0 + + - uses: actions/checkout@v3 + - name: Build Docker image + run: | + docker build -t polygondust -f ./Dockerfile.coverage . + + - name: Create coverage_build directory + run: | + mkdir coverage_build + + - name: Run Test + run: | + docker run -v ./coverage_build/:/polygondust/coverage_build polygondust sh scripts/coverage.sh xml + + - name: Upload results to Codecov + uses: codecov/codecov-action@v4 + with: + fail_ci_if_error: true + files: ./coverage_build/polygondust-coverage-xml.xml + token: ${{ secrets.CODECOV_TOKEN }} \ No newline at end of file diff --git a/CMakeLists.txt b/CMakeLists.txt index 2a63e3a..d15066b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -61,10 +61,17 @@ if(COVERAGE) endif() append_coverage_compiler_flags() + setup_target_for_coverage_gcovr_html( - NAME polygondust-coverage - DEPENDENCIES PolygonDust - EXCLUDE ${COVERAGE_EXCLUDE} + NAME polygondust-coverage + DEPENDENCIES PolygonDust + EXCLUDE ${COVERAGE_EXCLUDE} + ) + + setup_target_for_coverage_gcovr_xml( + NAME polygondust-coverage-xml + DEPENDENCIES PolygonDust + EXCLUDE ${COVERAGE_EXCLUDE} ) endif() diff --git a/Dockerfile b/Dockerfile index 6137b38..8387353 100644 --- a/Dockerfile +++ b/Dockerfile @@ -7,4 +7,4 @@ COPY . /polygondust WORKDIR /polygondust RUN cmake . -RUN make -j 10 \ No newline at end of file +RUN make -j 10 diff --git a/Dockerfile.coverage b/Dockerfile.coverage new file mode 100644 index 0000000..653d533 --- /dev/null +++ b/Dockerfile.coverage @@ -0,0 +1,8 @@ +FROM python:3.11-alpine + +RUN apk add --update alpine-sdk py3-pip cmake openssl gcc py3-pybind11 +RUN python3 -m pip install "pybind11[global]" gcovr + +COPY . /polygondust + +WORKDIR /polygondust \ No newline at end of file diff --git a/scripts/coverage.sh b/scripts/coverage.sh old mode 100644 new mode 100755 index ab3ddc8..e0d7467 --- a/scripts/coverage.sh +++ b/scripts/coverage.sh @@ -18,6 +18,11 @@ cmake \ cmake --build $BUILD_DIR -"./${BUILD_DIR}/build/polygondust-gtest" +"./${BUILD_DIR}/build/PolygonDust-gtest" -cmake --build $BUILD_DIR --target polygondust-coverage \ No newline at end of file +if [ "$1" == 'xml' ] +then + cmake --build $BUILD_DIR --target polygondust-coverage-xml; +else + cmake --build $BUILD_DIR --target polygondust-coverage; +fi \ No newline at end of file