Skip to content

Add CI workflows for PR test coverage enforcement and Nix builds #7

Add CI workflows for PR test coverage enforcement and Nix builds

Add CI workflows for PR test coverage enforcement and Nix builds #7

Workflow file for this run

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 build -j$(nproc)"
- name: Run tests
run: |
nix develop --command bash -c "cmake --build build --target tests"
- name: Run main
run: |
nix develop --command bash -c "cmake --build build --target run"
- name: Measure code coverage
run: |
nix develop --command bash -c "cmake --build build --target coverage"
- name: Export coverage report totals as text
run: |
nix develop --command bash -c "llvm-cov report build/src/main -instr-profile=build/coverage.profdata -ignore-filename-regex='test/.*' > build/coverage.txt"
cat build/coverage.txt
- name: Verify functions coverage is 100%
run: |
grep TOTAL build/coverage.txt | awk '{ if ($7 + 0 == 100) exit 0; else exit 1 }'
- name: Verify line coverage is at least 90%
run: |
grep TOTAL build/coverage.txt | awk '{ if ($10 + 0 > 90) exit 0; else exit 1 }'