Skip to content

Commit ef9fd92

Browse files
committed
ci: add code coverage workflow and badge
Signed-off-by: Brian McGee <[email protected]>
1 parent e41339a commit ef9fd92

File tree

3 files changed

+44
-3
lines changed

3 files changed

+44
-3
lines changed

.github/workflows/coverage.yml

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
name: Code Coverage
2+
3+
on: [push]
4+
5+
jobs:
6+
coverage:
7+
runs-on: "ubuntu-20.04"
8+
name: Coverage
9+
steps:
10+
- uses: actions/checkout@v4
11+
with:
12+
fetch-depth: 0
13+
- name: Install Nix
14+
uses: cachix/install-nix-action@v30
15+
with:
16+
extra_nix_config: |
17+
accept-flake-config = true
18+
experimental-features = nix-command flakes
19+
- name: Run coverage
20+
run: nix build .#treefmt.tests.coverage
21+
- name: Upload coverage
22+
uses: coverallsapp/github-action@v2
23+
with:
24+
github-token: ${{ secrets.github_token }}
25+
file: result
26+
format: golang

README.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,10 @@
66

77
**One CLI to format your repo**
88

9-
*A <a href="https://numtide.com/">numtide</a> project.*
9+
_A <a href="https://numtide.com/">numtide</a> project._
1010

1111
<p>
12+
<a href='https://coveralls.io/github/numtide/treefmt?branch=new-README'><img src='https://coveralls.io/repos/github/numtide/treefmt/badge.svg?branch=new-README' alt='Coverage Status' /></a>
1213
<a href="https://github.com/numtide/treefmt/actions/workflows/release.yml"><img src="https://github.com/numtide/treefmt/actions/workflows/release.yml/badge.svg"/></a>
1314
<img alt="Static Badge" src="https://img.shields.io/badge/status-beta-yellow">
1415
<a href="https://app.element.io/#/room/#home:numtide.com"><img src="https://img.shields.io/badge/Support-%23numtide-blue"/></a>

nix/packages/treefmt/default.nix

+16-2
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,22 @@ in
6363
git config --global user.name "Treefmt Test"
6464
'';
6565

66-
passthru.tests = {
67-
golangci-lint = perSystem.self.treefmt.overrideAttrs (old: {
66+
passthru.tests = let
67+
inherit (perSystem.self) treefmt;
68+
in {
69+
coverage = lib.optionalAttrs pkgs.stdenv.isx86_64 (treefmt.overrideAttrs (old: {
70+
nativeBuildInputs = old.nativeBuildInputs ++ [pkgs.gcc];
71+
CGO_ENABLED = 1;
72+
buildPhase = ''
73+
HOME=$TMPDIR
74+
go test -race -covermode=atomic -coverprofile=coverage.out -v ./...
75+
'';
76+
installPhase = ''
77+
mv coverage.out $out
78+
'';
79+
}));
80+
81+
golangci-lint = treefmt.overrideAttrs (old: {
6882
nativeBuildInputs = old.nativeBuildInputs ++ [pkgs.golangci-lint];
6983
buildPhase = ''
7084
HOME=$TMPDIR

0 commit comments

Comments
 (0)