diff --git a/.github/workflows/build-and-test.yml b/.github/workflows/build-and-test.yml index f8c1ecfb61..6d46a8d48b 100644 --- a/.github/workflows/build-and-test.yml +++ b/.github/workflows/build-and-test.yml @@ -19,6 +19,7 @@ jobs: - ubuntu_22.04-clang_14-vtk_9.2.2-py_3.8 env: OUTPUT_DIR: '/tmp/artifacts' + VT_TV_COVERAGE_ENABLED: ${{ matrix.image == 'ubuntu_22.04-gcc_11-vtk_9.2.2-py_3.8' && 'ON' || 'OFF' }} name: vt-tv build and test steps: - uses: actions/checkout@v4 @@ -51,6 +52,7 @@ jobs: file: ./ci/docker/build-and-test.dockerfile build-args: | BASE_IMAGE=pierrpebay/vt-tv:${{ matrix.image }} + VT_TV_COVERAGE_ENABLED=${{ env.VT_TV_COVERAGE_ENABLED }} outputs: type=local,dest=${{ env.OUTPUT_DIR }} - name: Upload artifacts @@ -70,7 +72,7 @@ jobs: output-to: step-summary - name: Coverage - if: contains(${{matrix.image }}, "gcc_11") + if: ${{ env.VT_TV_COVERAGE_ENABLED == 'ON' }} run: | echo '## Coverage' >> $GITHUB_STEP_SUMMARY echo '```shell' >> $GITHUB_STEP_SUMMARY diff --git a/ci/docker/build-and-test.dockerfile b/ci/docker/build-and-test.dockerfile index 1de1381a58..52e887a428 100644 --- a/ci/docker/build-and-test.dockerfile +++ b/ci/docker/build-and-test.dockerfile @@ -1,7 +1,10 @@ ARG BASE_IMAGE=pierrpebay/vt-tv:ubuntu_22.04-gcc_11-vtk_9.2.2-py_3.8 +ARG VT_TV_COVERAGE_ENABLED=OFF FROM ${BASE_IMAGE} AS base +ENV VT_TV_COVERAGE_ENABLED=$VT_TV_COVERAGE_ENABLED + # setup requirements for rendering tests (xvfb) + coverage report (lcov) RUN apt-get update && apt-get install -y \ xvfb \ @@ -11,8 +14,6 @@ COPY . /opt/src/vt-tv RUN mkdir -p /opt/build/vt-tv # Build -FROM base AS build -RUN bash -c 'if [[ "$CC" == "/usr/bin/gcc-11" ]]; then export VT_TV_COVERAGE_ENABLED=ON; fi' RUN /opt/src/vt-tv/ci/build.sh # Unit tests diff --git a/ci/test_cpp.sh b/ci/test_cpp.sh index 054cace8af..ff503ff1a9 100644 --- a/ci/test_cpp.sh +++ b/ci/test_cpp.sh @@ -27,24 +27,25 @@ cat /opt/build/vt-tv/Testing/Temporary/LastTest.log [ -f "/opt/src/vt-tv/output/test-render/ccm_example0.png" ] && cp "/opt/src/vt-tv/output/test-render/ccm_example0.png" /tmp/artifacts/ # coverage reporting -pushd /opt/src/vt-tv/output -lcov --capture --directory /opt/build/vt-tv --output-file lcov_vt-tv_test.info -lcov --remove lcov_vt-tv_test.info -o lcov_vt-tv_test_no_deps.info '*/lib/*' '/usr/include/*' '*/vtk/*' '*/tests/*' -lcov --list lcov_vt-tv_test_no_deps.info -# add simple coverage artifact -lcov --list lcov_vt-tv_test_no_deps.info > lcov-list-report.txt -cp lcov_vt-tv_test_no_deps.info /tmp/artifacts/ -cp /opt/src/vt-tv/output/lcov-list-report.txt /tmp/artifacts/ - -# extract total coverage (Lines) for later use in a badge in the CI -LCOV_SUMMARY=$(lcov --summary lcov_vt-tv_test_no_deps.info) -LCOV_TOTAL_LINES_COV=$(echo $LCOV_SUMMARY | grep -E -o 'lines......: ([0-9.]+)*' | grep -o -E '[0-9]+.[0-9]+') -echo $LCOV_TOTAL_LINES_COV > lcov-lines-total.txt -cp /opt/src/vt-tv/output/lcov-lines-total.txt /tmp/artifacts/ - -ls /tmp/artifacts - -popd +if [[ $VT_TV_COVERAGE_ENABLED=="ON" ]]; then + pushd /opt/src/vt-tv/output + lcov --capture --directory /opt/build/vt-tv --output-file lcov_vt-tv_test.info + lcov --remove lcov_vt-tv_test.info -o lcov_vt-tv_test_no_deps.info '*/lib/*' '/usr/include/*' '*/vtk/*' '*/tests/*' + lcov --list lcov_vt-tv_test_no_deps.info + # add simple coverage artifact + lcov --list lcov_vt-tv_test_no_deps.info > lcov-list-report.txt + cp lcov_vt-tv_test_no_deps.info /tmp/artifacts/ + cp /opt/src/vt-tv/output/lcov-list-report.txt /tmp/artifacts/ + + # extract total coverage (Lines) for later use in a badge in the CI + LCOV_SUMMARY=$(lcov --summary lcov_vt-tv_test_no_deps.info) + LCOV_TOTAL_LINES_COV=$(echo $LCOV_SUMMARY | grep -E -o 'lines......: ([0-9.]+)*' | grep -o -E '[0-9]+.[0-9]+') + echo $LCOV_TOTAL_LINES_COV > lcov-lines-total.txt + cp /opt/src/vt-tv/output/lcov-lines-total.txt /tmp/artifacts/ + + ls /tmp/artifacts + popd +fi popd