Skip to content

Commit

Permalink
Add Codecov (#12)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
ntut-xuan authored Nov 20, 2024
1 parent b1ee7ee commit 62c770d
Show file tree
Hide file tree
Showing 5 changed files with 60 additions and 6 deletions.
34 changes: 34 additions & 0 deletions .github/workflows/codecov.yml
Original file line number Diff line number Diff line change
@@ -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 }}
13 changes: 10 additions & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@ COPY . /polygondust

WORKDIR /polygondust
RUN cmake .
RUN make -j 10
RUN make -j 10
8 changes: 8 additions & 0 deletions Dockerfile.coverage
Original file line number Diff line number Diff line change
@@ -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
9 changes: 7 additions & 2 deletions scripts/coverage.sh
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -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
if [ "$1" == 'xml' ]
then
cmake --build $BUILD_DIR --target polygondust-coverage-xml;
else
cmake --build $BUILD_DIR --target polygondust-coverage;
fi

0 comments on commit 62c770d

Please sign in to comment.