From 375292ac71ecfc5bbcaa809dccdb0afe30acf134 Mon Sep 17 00:00:00 2001 From: Andrew Torgesen Date: Sat, 3 May 2025 21:53:07 -0700 Subject: [PATCH 01/10] Add code coverage CI job --- .github/_nixshell | 11 +++++++++++ .github/workflows/test.yml | 26 ++++++++++++++++++++++++++ CMakeLists.txt | 8 ++++++++ 3 files changed, 45 insertions(+) create mode 100644 .github/_nixshell diff --git a/.github/_nixshell b/.github/_nixshell new file mode 100644 index 0000000..e20e1f8 --- /dev/null +++ b/.github/_nixshell @@ -0,0 +1,11 @@ +let pkgs = import (builtins.fetchTarball + "https://github.com/goromal/anixpkgs/archive/refs/tags/v6.22.0.tar.gz") {}; +in with pkgs; mkShell { + nativeBuildInputs = [ + cmake + ]; + buildInputs = [ + boost + eigen + ]; +} diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 7d74bf0..45c07da 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -21,3 +21,29 @@ jobs: - run: > git config --global url."https://github.com/".insteadOf ssh://git@github.com/ - run: export NIXPKGS_ALLOW_UNFREE=1 && nix-build -E 'with (import (fetchTarball "https://github.com/goromal/anixpkgs/archive/refs/heads/master.tar.gz") {}); manif-geom-cpp.override { pkg-src = lib.cleanSource ./.; }' + code-cov: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - uses: cachix/install-nix-action@v20 + with: + nix_path: nixpkgs=channel:nixos-unstable + - uses: cachix/cachix-action@v12 + with: + name: github-public + authToken: '${{ secrets.CACHIX_AUTH_TOKEN }}' + - run: sudo apt-get update && sudo apt-get install -y lcov + - name: Build and test + run: | + mkdir build && cd build + nix-shell ../.github/_nixshell --run "cmake .. -DCMAKE_BUILD_TYPE=Debug && make unit-tests" + - name: Generate coverage HTML report + run: | + lcov --capture --directory . --output-file coverage.info + lcov --remove coverage.info '/usr/*' '*/test/*' --output-file coverage.info.cleaned + genhtml coverage.info.cleaned --output-directory coverage_report + - name: Upload coverage report artifact + uses: actions/upload-artifact@v3 + with: + name: coverage-report + path: coverage_report diff --git a/CMakeLists.txt b/CMakeLists.txt index 833c7ec..4917ef4 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,10 +1,18 @@ cmake_minimum_required (VERSION 3.16) project(manif-geom-cpp) +if(NOT CMAKE_BUILD_TYPE) + set(CMAKE_BUILD_TYPE Release CACHE STRING "Build type" FORCE) +endif() + set(CMAKE_CXX_STANDARD 17) option(BUILD_TESTS "Build Tests" ON) +if(CMAKE_CXX_COMPILER_ID MATCHES "GNU|Clang") + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fprofile-arcs -ftest-coverage -O0 -g") +endif() + find_package(Eigen3 REQUIRED NO_MODULE) add_library(manif-geom-cpp INTERFACE) From cca16a4943057c645ba89812402d5ab0a56d2e6b Mon Sep 17 00:00:00 2001 From: Andrew Torgesen Date: Sat, 3 May 2025 21:57:55 -0700 Subject: [PATCH 02/10] try again --- .github/workflows/test.yml | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 45c07da..8e2faea 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -42,8 +42,13 @@ jobs: lcov --capture --directory . --output-file coverage.info lcov --remove coverage.info '/usr/*' '*/test/*' --output-file coverage.info.cleaned genhtml coverage.info.cleaned --output-directory coverage_report - - name: Upload coverage report artifact - uses: actions/upload-artifact@v3 + - name: Setup LCOV + uses: hrishikesh-kadam/setup-lcov@v1 + - name: Report code coverage + uses: zgosalvez/github-actions-report-lcov@v4 with: - name: coverage-report - path: coverage_report + coverage-files: coverage.info.cleaned + minimum-coverage: 40 + artifact-name: code-coverage-report + github-token: ${{ secrets.GITHUB_TOKEN }} + update-comment: true From 28f8647b4eab7d4e784b659e3cd45dba3d8ca08a Mon Sep 17 00:00:00 2001 From: Andrew Torgesen Date: Sat, 3 May 2025 22:05:43 -0700 Subject: [PATCH 03/10] wip testing locally --- .github/_nixshell | 1 + .github/workflows/test.yml | 7 +++---- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/_nixshell b/.github/_nixshell index e20e1f8..4f76971 100644 --- a/.github/_nixshell +++ b/.github/_nixshell @@ -3,6 +3,7 @@ let pkgs = import (builtins.fetchTarball in with pkgs; mkShell { nativeBuildInputs = [ cmake + lcov ]; buildInputs = [ boost diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 8e2faea..9837ecf 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -32,16 +32,15 @@ jobs: with: name: github-public authToken: '${{ secrets.CACHIX_AUTH_TOKEN }}' - - run: sudo apt-get update && sudo apt-get install -y lcov - name: Build and test run: | mkdir build && cd build nix-shell ../.github/_nixshell --run "cmake .. -DCMAKE_BUILD_TYPE=Debug && make unit-tests" - name: Generate coverage HTML report run: | - lcov --capture --directory . --output-file coverage.info - lcov --remove coverage.info '/usr/*' '*/test/*' --output-file coverage.info.cleaned - genhtml coverage.info.cleaned --output-directory coverage_report + nix-shell ../.github/_nixshell --run "lcov --capture --directory . --output-file coverage.info && \ + lcov --remove coverage.info '/usr/*' '*/test/*' --output-file coverage.info.cleaned && \ + genhtml coverage.info.cleaned --output-directory coverage_report" - name: Setup LCOV uses: hrishikesh-kadam/setup-lcov@v1 - name: Report code coverage From 4d1913f235a65fafa9323c206a971846faf000ac Mon Sep 17 00:00:00 2001 From: Andrew Torgesen Date: Sat, 3 May 2025 22:08:53 -0700 Subject: [PATCH 04/10] wip --- .github/workflows/test.yml | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 9837ecf..ffc4d63 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -32,12 +32,10 @@ jobs: with: name: github-public authToken: '${{ secrets.CACHIX_AUTH_TOKEN }}' - - name: Build and test + - name: Build, test, and generate coverage HTML report run: | mkdir build && cd build nix-shell ../.github/_nixshell --run "cmake .. -DCMAKE_BUILD_TYPE=Debug && make unit-tests" - - name: Generate coverage HTML report - run: | nix-shell ../.github/_nixshell --run "lcov --capture --directory . --output-file coverage.info && \ lcov --remove coverage.info '/usr/*' '*/test/*' --output-file coverage.info.cleaned && \ genhtml coverage.info.cleaned --output-directory coverage_report" From 5c306519fc0a49752973081ce3ecd6a5caea5332 Mon Sep 17 00:00:00 2001 From: Andrew Torgesen Date: Sat, 3 May 2025 22:12:56 -0700 Subject: [PATCH 05/10] maybe works now --- .github/workflows/test.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index ffc4d63..b46359e 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -38,7 +38,7 @@ jobs: nix-shell ../.github/_nixshell --run "cmake .. -DCMAKE_BUILD_TYPE=Debug && make unit-tests" nix-shell ../.github/_nixshell --run "lcov --capture --directory . --output-file coverage.info && \ lcov --remove coverage.info '/usr/*' '*/test/*' --output-file coverage.info.cleaned && \ - genhtml coverage.info.cleaned --output-directory coverage_report" + genhtml --ignore-errors source coverage.info.cleaned --output-directory coverage_report" - name: Setup LCOV uses: hrishikesh-kadam/setup-lcov@v1 - name: Report code coverage From 2ee182ac4ad5fb3758b2a2a129f8bb16d89c643a Mon Sep 17 00:00:00 2001 From: Andrew Torgesen Date: Sat, 3 May 2025 22:18:53 -0700 Subject: [PATCH 06/10] wip --- .github/workflows/test.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index b46359e..d2a23b6 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -38,14 +38,14 @@ jobs: nix-shell ../.github/_nixshell --run "cmake .. -DCMAKE_BUILD_TYPE=Debug && make unit-tests" nix-shell ../.github/_nixshell --run "lcov --capture --directory . --output-file coverage.info && \ lcov --remove coverage.info '/usr/*' '*/test/*' --output-file coverage.info.cleaned && \ - genhtml --ignore-errors source coverage.info.cleaned --output-directory coverage_report" + genhtml --ignore-errors source --output-directory coverage_report coverage.info.cleaned" - name: Setup LCOV uses: hrishikesh-kadam/setup-lcov@v1 - name: Report code coverage uses: zgosalvez/github-actions-report-lcov@v4 with: coverage-files: coverage.info.cleaned - minimum-coverage: 40 + minimum-coverage: 90 artifact-name: code-coverage-report github-token: ${{ secrets.GITHUB_TOKEN }} update-comment: true From baa384d16fea0de203f283836ba5121f4798a775 Mon Sep 17 00:00:00 2001 From: Andrew Torgesen Date: Sat, 3 May 2025 22:19:48 -0700 Subject: [PATCH 07/10] change dir --- .github/workflows/test.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index d2a23b6..7f10df4 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -48,4 +48,5 @@ jobs: minimum-coverage: 90 artifact-name: code-coverage-report github-token: ${{ secrets.GITHUB_TOKEN }} + working-directory: build update-comment: true From 73ecb6b5f8e13fd84e5cbd5e04a7c608ae2c4003 Mon Sep 17 00:00:00 2001 From: Andrew Torgesen Date: Sat, 3 May 2025 22:26:16 -0700 Subject: [PATCH 08/10] try again --- .github/workflows/test.yml | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 7f10df4..b566abc 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -38,15 +38,14 @@ jobs: nix-shell ../.github/_nixshell --run "cmake .. -DCMAKE_BUILD_TYPE=Debug && make unit-tests" nix-shell ../.github/_nixshell --run "lcov --capture --directory . --output-file coverage.info && \ lcov --remove coverage.info '/usr/*' '*/test/*' --output-file coverage.info.cleaned && \ - genhtml --ignore-errors source --output-directory coverage_report coverage.info.cleaned" + genhtml --branch-coverage --ignore-errors source --output-directory coverage_report coverage.info.cleaned" - name: Setup LCOV uses: hrishikesh-kadam/setup-lcov@v1 - name: Report code coverage uses: zgosalvez/github-actions-report-lcov@v4 with: - coverage-files: coverage.info.cleaned + coverage-files: build/coverage.info.cleaned minimum-coverage: 90 artifact-name: code-coverage-report github-token: ${{ secrets.GITHUB_TOKEN }} - working-directory: build update-comment: true From 03742aed415b2b957f9815d10d6a058f33e1ab0c Mon Sep 17 00:00:00 2001 From: Andrew Torgesen Date: Sat, 3 May 2025 22:34:25 -0700 Subject: [PATCH 09/10] wip do it myself --- .github/workflows/test.yml | 30 ++++++++++++++++++++++-------- 1 file changed, 22 insertions(+), 8 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index b566abc..7e9e318 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -39,13 +39,27 @@ jobs: nix-shell ../.github/_nixshell --run "lcov --capture --directory . --output-file coverage.info && \ lcov --remove coverage.info '/usr/*' '*/test/*' --output-file coverage.info.cleaned && \ genhtml --branch-coverage --ignore-errors source --output-directory coverage_report coverage.info.cleaned" - - name: Setup LCOV - uses: hrishikesh-kadam/setup-lcov@v1 - - name: Report code coverage - uses: zgosalvez/github-actions-report-lcov@v4 + - name: Upload coverage report artifact + uses: actions/upload-artifact@v4 + with: + name: code-coverage-report + path: build/coverage_report + - name: Post PR comment with coverage artifact (optional) + if: github.event_name == 'pull_request' + uses: actions/github-script@v7 with: - coverage-files: build/coverage.info.cleaned - minimum-coverage: 90 - artifact-name: code-coverage-report github-token: ${{ secrets.GITHUB_TOKEN }} - update-comment: true + script: | + const artifactUrl = `https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}`; + const comment = ` + ### 🧪 Code Coverage Report + The code coverage report has been generated for this PR. + + ➡️ [View coverage artifact](${artifactUrl}) + `; + github.rest.issues.createComment({ + issue_number: context.issue.number, + owner: context.repo.owner, + repo: context.repo.repo, + body: comment + }); From 863a59d95daea812f33be8ca953628737ec19d65 Mon Sep 17 00:00:00 2001 From: Andrew Torgesen Date: Sat, 3 May 2025 22:49:06 -0700 Subject: [PATCH 10/10] try out auto commit step --- .github/workflows/test.yml | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 7e9e318..c552356 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -63,3 +63,15 @@ jobs: repo: context.repo.repo, body: comment }); + - name: Copy coverage report into docs/ + run: | + mkdir -p docs/coverage + cp -r build/coverage_report/* docs/coverage/ + - name: Commit coverage report to docs/ + if: github.ref == 'refs/heads/master' + run: | + git config --global user.name "github-actions" + git config --global user.email "github-actions@github.com" + git add docs/coverage + git commit -m "Update coverage report [skip ci]" || echo "No changes to commit" + git push