From ab5eed22e48eee8987740b475f56a0bd62e15361 Mon Sep 17 00:00:00 2001 From: Even Rouault Date: Sun, 25 Jun 2023 19:15:20 +0200 Subject: [PATCH] CI: add a coverage job --- .github/workflows/coverage/build.sh | 19 +++++++ .github/workflows/coverage/test.sh | 23 +++++++++ .github/workflows/linux_build.yml | 53 +++++++++++++++++++- .github/workflows/ubuntu_20.04/Dockerfile.ci | 1 + 4 files changed, 95 insertions(+), 1 deletion(-) create mode 100755 .github/workflows/coverage/build.sh create mode 100755 .github/workflows/coverage/test.sh diff --git a/.github/workflows/coverage/build.sh b/.github/workflows/coverage/build.sh new file mode 100755 index 000000000000..efc2f27935a8 --- /dev/null +++ b/.github/workflows/coverage/build.sh @@ -0,0 +1,19 @@ +#!/bin/sh + +set -eu + +export CXXFLAGS="--coverage" +export CFLAGS="--coverage" +export LDFLAGS="-lgcov" + +cmake ${GDAL_SOURCE_DIR:=..} \ + -DUSE_CCACHE=ON \ + -DCMAKE_BUILD_TYPE=Debug \ + -DCMAKE_INSTALL_PREFIX=/usr \ + -DGDAL_USE_TIFF_INTERNAL=ON \ + -DGDAL_USE_GEOTIFF_INTERNAL=ON \ + -DECW_ROOT=/opt/libecwj2-3.3 \ + -DMRSID_ROOT=/usr/local \ + -DFileGDB_ROOT=/usr/local/FileGDB_API + +make -j$(nproc) diff --git a/.github/workflows/coverage/test.sh b/.github/workflows/coverage/test.sh new file mode 100755 index 000000000000..6ec448466f6e --- /dev/null +++ b/.github/workflows/coverage/test.sh @@ -0,0 +1,23 @@ +#!/bin/bash + +set -eu + +export OGR_HANA_CONNECTION_STRING='DRIVER=/usr/sap/hdbclient/libodbcHDB.so;HOST=917df316-4e01-4a10-be54-eac1b6ab15fb.hana.prod-us10.hanacloud.ondemand.com;PORT=443;USER=GDALCI;PASSWORD=u7t!Ukeugzq7' + +ctest -V -j $(nproc) + +lcov --directory . --capture --output-file gdal.info 2>/dev/null +cp gdal.info gdal_filtered.info +lcov --remove gdal_filtered.info '/usr/*' --output-file gdal_filtered.info +lcov --remove gdal_filtered.info '/opt/*' --output-file gdal_filtered.info +lcov --remove gdal_filtered.info '*jpeg/libjpeg*' --output-file gdal_filtered.info +lcov --remove gdal_filtered.info '*pcraster/libcsf*' --output-file gdal_filtered.info +lcov --remove gdal_filtered.info '*googletest-src*' --output-file gdal_filtered.info +genhtml -o ./coverage_html --ignore-errors source --num-spaces 2 gdal_filtered.info >/dev/null + +if test "${COVERALLS_REPO_TOKEN:-}" != ""; then + pip install cpp-coveralls + echo "Running git config --global --add safe.directory ${GDAL_SOURCE_DIR}" + git config --global --add safe.directory ${GDAL_SOURCE_DIR} + coveralls -n -l gdal_filtered.info +fi diff --git a/.github/workflows/linux_build.yml b/.github/workflows/linux_build.yml index c00929fc84f2..380d2f0ed121 100644 --- a/.github/workflows/linux_build.yml +++ b/.github/workflows/linux_build.yml @@ -35,7 +35,7 @@ jobs: GDAL_SOURCE_DIR: /gdal # Directory to which workspace (source root) will be mounted inside container permissions: - contents: read + contents: write # for Git to git push packages: write strategy: @@ -84,6 +84,13 @@ jobs: build_script: build.sh test_script: test.sh + - name: Ubuntu 20.04, coverage + id: coverage + travis_branch: ubuntu_2004 + container: ubuntu_20.04 + build_script: build.sh + test_script: test.sh + - name: Ubuntu 20.04, Intel compiler id: icc container: icc @@ -248,6 +255,8 @@ jobs: -e GITHUB_WORKFLOW \ -e TRAVIS \ -e TRAVIS_BRANCH \ + -e GDAL_SOURCE_DIR \ + -e "COVERALLS_REPO_TOKEN=${{ secrets.COVERALLS_REPO_TOKEN }}" \ --security-opt seccomp=unconfined \ --add-host=host.docker.internal:host-gateway \ --rm \ @@ -265,3 +274,45 @@ jobs: run: | docker push ${CONTAINER_NAME_FULL} + - name: Upload coverage artifacts + uses: actions/upload-artifact@v3 + if: ${{ matrix.id == 'coverage' }} + with: + name: coverage_index.html + path: build-${{ matrix.id }}/coverage_html/index.html + + - name: Upload coverage artifacts + uses: actions/upload-artifact@v3 + if: ${{ matrix.id == 'coverage' }} + with: + name: HTML + path: build-${{ matrix.id }}/coverage_html/* + + - name: Deploy ssh key (for coverage) + if: ${{ matrix.id == 'coverage' && github.event_name == 'push' && github.ref_name == 'master' && github.repository == 'OSGeo/gdal' }} + shell: bash -l {0} + run: | + mkdir $HOME/.ssh && echo "${{ secrets.GDAL_TEST_COVERAGE_RESULTS_SSH_KEY }}" > $HOME/.ssh/id_rsa + chmod 700 $HOME/.ssh && chmod 600 $HOME/.ssh/id_rsa + ssh-keyscan -t rsa github.com >> $HOME/.ssh/known_hosts + eval `ssh-agent -s` + ssh-add $HOME/.ssh/id_rsa + + - name: Deploy to https://github.com/OSGeo/gdal-test-coverage-results + if: ${{ matrix.id == 'coverage' && github.event_name == 'push' && github.ref_name == 'master' && github.repository == 'OSGeo/gdal' }} + shell: bash -l {0} + run: | + set -x + set -e + mkdir -p output_html/coverage_html + cp -r $GITHUB_WORKSPACE/build-${{ matrix.id }}/coverage_html/* output_html/coverage_html/ + cd output_html + git init + git config user.email "gdal-test-coverage-results-bot@example.com" + git config user.name "GDAL test coverage results bot" + git remote add origin git@github.com:gdalautotest-coverage-results/gdalautotest-coverage-results.github.io + git remote -v + echo "Results of coverage of GDAL autotest See https://gdalautotest-coverage-results.github.io/coverage_html/index.html" > README.md + git add -A + git commit -m "Update with OSGeo/gdal commit $GITHUB_SHA" + git push -f origin master diff --git a/.github/workflows/ubuntu_20.04/Dockerfile.ci b/.github/workflows/ubuntu_20.04/Dockerfile.ci index 57b39cf9b969..5defacd5c149 100644 --- a/.github/workflows/ubuntu_20.04/Dockerfile.ci +++ b/.github/workflows/ubuntu_20.04/Dockerfile.ci @@ -20,6 +20,7 @@ RUN apt-get update -y \ curl \ git \ gnupg \ + lcov \ libarmadillo-dev \ libblosc-dev \ libboost-dev \