Skip to content

Commit

Permalink
ci: add code coverage workflow and badge
Browse files Browse the repository at this point in the history
Signed-off-by: Brian McGee <[email protected]>
  • Loading branch information
brianmcgee committed Nov 14, 2024
1 parent e41339a commit f5c135f
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 3 deletions.
26 changes: 26 additions & 0 deletions .github/workflows/coverage.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
name: Code Coverage

on: [push]

jobs:
coverage:
runs-on: "ubuntu-20.04"
name: Coverage
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Install Nix
uses: cachix/install-nix-action@v30
with:
extra_nix_config: |
accept-flake-config = true
experimental-features = nix-command flakes
- name: Run coverage
run: nix build .#treefmt.tests.coverage
- name: Upload coverage
uses: coverallsapp/github-action@v2
with:
github-token: ${{ secrets.github_token }}
file: result
format: golang
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,10 @@

**One CLI to format your repo**

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

<p>
<a href="https://coveralls.io/repos/github/numtide/treefmt"><img src="https://coveralls.io/repos/github/numtide/treefmt/badge.svg"></a>
<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>
<img alt="Static Badge" src="https://img.shields.io/badge/status-beta-yellow">
<a href="https://app.element.io/#/room/#home:numtide.com"><img src="https://img.shields.io/badge/Support-%23numtide-blue"/></a>
Expand Down
18 changes: 16 additions & 2 deletions nix/packages/treefmt/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,22 @@ in
git config --global user.name "Treefmt Test"
'';

passthru.tests = {
golangci-lint = perSystem.self.treefmt.overrideAttrs (old: {
passthru.tests = let
inherit (perSystem.self) treefmt;
in {
coverage = lib.optionalAttrs pkgs.stdenv.isx86_64 (treefmt.overrideAttrs (old: {
nativeBuildInputs = old.nativeBuildInputs ++ [pkgs.gcc];
CGO_ENABLED = 1;
buildPhase = ''
HOME=$TMPDIR
go test -race -covermode=atomic -coverprofile=coverage.out -v ./...
'';
installPhase = ''
mv coverage.out $out
'';
}));

golangci-lint = treefmt.overrideAttrs (old: {
nativeBuildInputs = old.nativeBuildInputs ++ [pkgs.golangci-lint];
buildPhase = ''
HOME=$TMPDIR
Expand Down

0 comments on commit f5c135f

Please sign in to comment.