add codecov

This commit is contained in:
Uday Patil 2025-06-17 17:38:01 -04:00
parent 7d0d84d5ce
commit 157d8e67f8
3 changed files with 94 additions and 2 deletions

63
.github/workflows/unit_tests.yml vendored Normal file
View file

@ -0,0 +1,63 @@
name: Unit Tests
on:
push:
branches:
- master
pull_request:
branches:
- master
jobs:
unit_tests:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v3
- name: Set up Go
uses: actions/setup-go@v4
with:
go-version: '1.21'
- name: Run unit tests
run: go run build/ci.go test -coverage
- name: Upload artifacts
uses: actions/upload-artifact@v4
with:
name: coverage
path: coverage.out
upload-coverage:
runs-on: ubuntu-latest
needs: unit_tests
steps:
- uses: actions/checkout@v3
- uses: actions/setup-go@v3
with:
go-version: 1.21
# Download all coverage reports from the 'tests' job
- name: Download coverage reports
uses: actions/download-artifact@v4
- name: Set GOPATH
run: echo "GOPATH=$(go env GOPATH)" >> $GITHUB_ENV
- name: Add GOPATH/bin to PATH
run: echo "GOBIN=$(go env GOPATH)/bin" >> $GITHUB_ENV
- name: Install gocovmerge
run: go get github.com/wadey/gocovmerge && go install github.com/wadey/gocovmerge
- name: Merge coverage reports
run: gocovmerge $(find . -type f -name '*profile.out') > coverage.txt
- name: Check coverage report lines
run: wc -l coverage.txt
continue-on-error: true
- name: Check coverage report files
run: ls **/*profile.out
continue-on-error: true

View file

@ -285,7 +285,7 @@ func doTest(cmdline []string) {
coverage = flag.Bool("coverage", false, "Whether to record code coverage")
verbose = flag.Bool("v", false, "Whether to log verbosely")
race = flag.Bool("race", false, "Execute the race detector")
short = flag.Bool("short", false, "Pass the 'short'-flag to go test")
short = flag.Bool("short", false, "Pass the 'short'-flag to go test")
cachedir = flag.String("cachedir", "./build/cache", "directory for caching downloads")
)
flag.CommandLine.Parse(cmdline)
@ -314,7 +314,7 @@ func doTest(cmdline []string) {
// and some tests run into timeouts under load.
gotest.Args = append(gotest.Args, "-p", "1")
if *coverage {
gotest.Args = append(gotest.Args, "-covermode=atomic", "-cover")
gotest.Args = append(gotest.Args, "-covermode=atomic", "-cover", "-coverprofile=coverage.out")
}
if *verbose {
gotest.Args = append(gotest.Args, "-v")

29
codecov.yml Normal file
View file

@ -0,0 +1,29 @@
coverage:
precision: 2
round: down
status:
project:
default:
target: 60%
threshold: 1% # allow this much decrease on project
patch:
default:
target: 70%
comment:
layout: "reach,diff,flags,tree,betaprofiling"
behavior: default # update if exists else create new
require_changes: true
ignore:
- "docs"
- "cmd"
- "tests"
- "swarm"
- "**/testdata"
- "lib/blocktest"
- "lib/cmdtest"
- "lib/testlog"
- "**/*pb*.go"
- "**/gen_*.go"
- "**/*.md"