Skip to content

Commit ad31fea

Browse files
committed
Add test coverage reporting and refactor CI configuration
Added comprehensive test coverage reporting with HPC (Haskell Program Coverage) that generates both text and HTML coverage reports. Coverage runs in a separate CI job to avoid interfering with regular build caching. Coverage reports include: - Text summary with expression, boolean, alternative, and declaration coverage percentages - HTML reports with line-by-line highlighting - Automatic upload as GitHub Actions artifacts Refactored CI configuration into modular structure with auto-discovery: - Split monolithic ci.nix into ci/ directory - Separate files for each workflow (check.nix, pages.nix) - Automatic discovery of workflow files in ci/ directory - Easier to add new workflows by simply adding files Updated .gitignore to exclude coverage artifacts (*.tix, .hpc/, coverage/).
1 parent 18079bf commit ad31fea

8 files changed

Lines changed: 233 additions & 162 deletions

File tree

.github/workflows/check.yml

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,27 @@ jobs:
2121
uses: DeterminateSystems/nix-installer-action@v21
2222
- name: Run flake check
2323
run: nix flake check
24+
coverage:
25+
name: Test coverage
26+
runs-on: ubuntu-latest
27+
steps:
28+
- name: Checkout
29+
uses: actions/checkout@v4
30+
- name: Install Nix
31+
uses: DeterminateSystems/nix-installer-action@v21
32+
- name: Run tests with coverage
33+
run: |
34+
nix develop -c cabal test --enable-coverage
35+
TIX_FILE=$(find dist-newstyle -name "terranix-codegen-tests.tix" -type f | head -1)
36+
MIX_DIRS=$(find dist-newstyle -type d -name "mix" -path "*/hpc/vanilla/mix" | sed "s/^/--hpcdir=/")
37+
mkdir -p coverage
38+
nix develop -c hpc report $MIX_DIRS "$TIX_FILE" | tee coverage/coverage.txt
39+
nix develop -c hpc markup $MIX_DIRS --destdir=coverage "$TIX_FILE"
40+
- name: Upload coverage report
41+
uses: actions/upload-artifact@v4
42+
with:
43+
name: coverage-report
44+
path: coverage/
2445
name: Check
2546
"on":
2647
pull_request: {}

.gitignore

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,11 @@ dist-*
44
cabal.project.local
55
cabal.project.local~
66

7+
# coverage
8+
*.tix
9+
.hpc
10+
coverage/
11+
712
# nix
813
result
914
result-*

nix/flake/ci.nix

Lines changed: 0 additions & 160 deletions
This file was deleted.

nix/flake/ci/check.nix

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
_: {
2+
perSystem = _: {
3+
githubActions.workflows.check = {
4+
name = "Check";
5+
6+
on = {
7+
push = {};
8+
pullRequest = {};
9+
};
10+
11+
permissions = {
12+
contents = "read";
13+
id-token = "write";
14+
};
15+
16+
defaults.job = {
17+
runsOn = "ubuntu-latest";
18+
};
19+
20+
jobs = {
21+
check = {
22+
name = "Run flake check";
23+
steps = [
24+
{
25+
name = "Checkout";
26+
uses = "actions/checkout@v4";
27+
}
28+
{
29+
name = "Install Nix";
30+
uses = "DeterminateSystems/nix-installer-action@v21";
31+
}
32+
{
33+
name = "Run flake check";
34+
run = "nix flake check";
35+
}
36+
];
37+
};
38+
39+
build = {
40+
name = "Build package";
41+
steps = [
42+
{
43+
name = "Checkout";
44+
uses = "actions/checkout@v4";
45+
}
46+
{
47+
name = "Install Nix";
48+
uses = "DeterminateSystems/nix-installer-action@v21";
49+
}
50+
{
51+
name = "Build package";
52+
run = "nix build";
53+
}
54+
];
55+
};
56+
57+
coverage = {
58+
name = "Test coverage";
59+
steps = [
60+
{
61+
name = "Checkout";
62+
uses = "actions/checkout@v4";
63+
}
64+
{
65+
name = "Install Nix";
66+
uses = "DeterminateSystems/nix-installer-action@v21";
67+
}
68+
{
69+
name = "Run tests with coverage";
70+
run = ''
71+
nix develop -c cabal test --enable-coverage
72+
TIX_FILE=$(find dist-newstyle -name "terranix-codegen-tests.tix" -type f | head -1)
73+
MIX_DIRS=$(find dist-newstyle -type d -name "mix" -path "*/hpc/vanilla/mix" | sed "s/^/--hpcdir=/")
74+
mkdir -p coverage
75+
nix develop -c hpc report $MIX_DIRS "$TIX_FILE" | tee coverage/coverage.txt
76+
nix develop -c hpc markup $MIX_DIRS --destdir=coverage "$TIX_FILE"
77+
'';
78+
}
79+
{
80+
name = "Upload coverage report";
81+
uses = "actions/upload-artifact@v4";
82+
with_ = {
83+
name = "coverage-report";
84+
path = "coverage/";
85+
};
86+
}
87+
];
88+
};
89+
};
90+
};
91+
};
92+
}

nix/flake/ci/default.nix

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
{inputs, ...}: {
2+
imports = let
3+
# Auto-discover all workflow files in this directory
4+
workflowFiles = builtins.filter (name: name != "default.nix") (
5+
builtins.attrNames (builtins.readDir ./.)
6+
);
7+
in
8+
[
9+
inputs.files.flakeModules.default
10+
inputs.github-actions-nix.flakeModules.default
11+
]
12+
++ map (name: ./${name}) workflowFiles;
13+
14+
perSystem = {
15+
config,
16+
lib,
17+
...
18+
}: {
19+
files.files = let
20+
go = name: drv: {
21+
path_ = ".github/workflows/${name}";
22+
inherit drv;
23+
};
24+
in
25+
lib.mapAttrsToList go config.githubActions.workflowFiles;
26+
27+
apps.write-files = {
28+
type = "app";
29+
program = config.files.writer.drv;
30+
};
31+
32+
githubActions.enable = true;
33+
};
34+
}

0 commit comments

Comments
 (0)