Add CI workflows for PR test coverage enforcement and Nix builds #2
Workflow file for this run
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Full Test Suite & Coverage Report | |
| on: | |
| pull_request: | |
| branches: | |
| - main | |
| jobs: | |
| test-coverage: | |
| name: Tests & Code Coverage | |
| runs-on: ubuntu-latest | |
| permissions: | |
| contents: read | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v4 | |
| - name: Install Nix | |
| uses: cachix/install-nix-action@v27 | |
| with: | |
| nix_path: nixpkgs=channel:nixos-unstable | |
| # - name: Config Cachix TODO | |
| # uses: cachix/cachix-action@v15 | |
| # with: | |
| # name: devenv | |
| - name: Configure & build project | |
| run: | | |
| nix develop --command bash -c "cmake --build . -j$(nproc)" | |
| - name: Run tests | |
| run: | | |
| nix develop --command bash -c "cmake --build . --target tests" | |
| - name: Measure code coverage | |
| run: | | |
| nix develop --command bash -c "cmake --build . --target coverage" | |
| - name: Export coverage report totals as text | |
| run: | | |
| nix develop --command bash -c "llvm-cov report src/main -instr-profile=coverage.profdata -ignore-filename-regex='test/.*' | grep TOTAL > coverage.txt && cat coverage.txt" | |
| # - name: Print coverage report stats | |
| # run: | | |
| # nix develop --command bash -c "cat coverage.txt | grep 'TOTAL' | awk '{print \"Functions: \" \$3 \" Lines: \" \$8}' > coverage_summary.txt && cat coverage_summary.txt" | |
| - name: Verify functions coverage is 100% | |
| run: | | |
| nix develop --command bash -c "cat coverage.txt | awk '{gsub(/%/, \"\", \$7); if (\$7 == 100) { exit 0 } else { exit 1 }}'" | |
| - name: Verify line coverage is at least 90% | |
| run: | | |
| nix develop --command bash -c "cat coverage.txt | awk '{gsub(/%/, \"\", \$10); if (\$10 >= 90) { exit 0 } else { exit 1 }}'" |