From 157d8e67f8eb6f053e85eabbbca3f1be42b7cee4 Mon Sep 17 00:00:00 2001 From: Uday Patil Date: Tue, 17 Jun 2025 17:38:01 -0400 Subject: [PATCH] add codecov --- .github/workflows/unit_tests.yml | 63 ++++++++++++++++++++++++++++++++ build/ci.go | 4 +- codecov.yml | 29 +++++++++++++++ 3 files changed, 94 insertions(+), 2 deletions(-) create mode 100644 .github/workflows/unit_tests.yml create mode 100644 codecov.yml diff --git a/.github/workflows/unit_tests.yml b/.github/workflows/unit_tests.yml new file mode 100644 index 0000000000..fc0d1b82e7 --- /dev/null +++ b/.github/workflows/unit_tests.yml @@ -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 \ No newline at end of file diff --git a/build/ci.go b/build/ci.go index 39c9149f47..520fa2662f 100644 --- a/build/ci.go +++ b/build/ci.go @@ -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") diff --git a/codecov.yml b/codecov.yml new file mode 100644 index 0000000000..e931e0179e --- /dev/null +++ b/codecov.yml @@ -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"