From 037d23a2a738b7de9c37d34bd819623eca9ba8ea Mon Sep 17 00:00:00 2001 From: Danilo Pantani Date: Wed, 16 Nov 2022 16:59:07 +0100 Subject: [PATCH] fix(CI): fix code coverage (#1903) * fix the code test coverage measure * fix folder type removal --- .codecov.yml => .github/codecov.yml | 20 ++++++++----------- .github/workflows/test.yml | 31 +++++++++++++++-------------- cmd/gaiad/cmd/testnet.go | 2 -- tools/tools.go | 2 ++ 4 files changed, 26 insertions(+), 29 deletions(-) rename .codecov.yml => .github/codecov.yml (56%) diff --git a/.codecov.yml b/.github/codecov.yml similarity index 56% rename from .codecov.yml rename to .github/codecov.yml index 758acd488e491..0939a269aa2e3 100644 --- a/.codecov.yml +++ b/.github/codecov.yml @@ -1,22 +1,14 @@ -# -# This codecov.yml is the default configuration for -# all repositories on Codecov. You may adjust the settings -# below in your own codecov.yml in your repository. -# coverage: precision: 2 round: down range: 70...100 - status: - # Learn more at https://docs.codecov.io/docs/commit-status project: default: threshold: 1% # allow this much decrease on project app: target: 80% paths: "app/" - changes: false comment: @@ -25,9 +17,13 @@ comment: require_changes: true ignore: + - "*.pb.go" + - "*.pb.gw.go" - "*.md" - "*.rst" - - "cmd/" - - "contrib/" - - "docs/" - - "networks/" + - "cmd" + - "client" + - "contrib" + - "docs" + - "proto" + - "tests/e2e" diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 6a4fd4613355c..bb53fbe193909 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -1,4 +1,5 @@ -name: Build & Test +name: Test + on: workflow_call: pull_request: @@ -18,17 +19,14 @@ jobs: test-coverage-upload: runs-on: ubuntu-latest steps: - - uses: actions/setup-go@v3.0.0 - with: - go-version: 1.18 - uses: actions/checkout@v3.1.0 - - uses: technote-space/get-diff-action@v6.0.1 + - uses: technote-space/get-diff-action@v6.1.1 with: PATTERNS: | **/**.go go.mod go.sum - - uses: actions/cache@v3.0.10 + - uses: actions/cache@v3.0.11 with: path: | ~/.cache/go-build @@ -36,25 +34,28 @@ jobs: key: ${{ runner.os }}-go-${{ hashFiles('**/go.mod') }} restore-keys: | ${{ runner.os }}-go- - - name: build - run: make build + - uses: actions/setup-go@v3.3.1 + with: + go-version: 1.18 - name: test & coverage report creation run: | - make test-unit-cover - - name: filter out DONTCOVER + go test -v -coverprofile=coverage.txt -covermode=atomic -coverpkg=./... $(go list ./...) + - name: filter non-testable files run: | excludelist="$(find ./ -type f -name '*.go' | xargs grep -l 'DONTCOVER')" excludelist+=" $(find ./ -type f -name '*.pb.go')" - excludelist+=" $(find ./ -type f -path './tests/mocks/*.go')" + excludelist+=" $(find ./ -type f -name '*.pb.gw.go')" + excludelist+=" $(find ./cmd -type d)" + excludelist+=" $(find ./tests -type d)" for filename in ${excludelist}; do - filename=$(echo $filename | sed 's/^./github.com\/cosmos\/cosmos-sdk/g') + filename=${filename#".//"} echo "Excluding ${filename} from coverage report..." - sed -i.bak "/$(echo $filename | sed 's/\//\\\//g')/d" coverage.txt + filename=$(echo "$filename" | sed 's/\//\\\//g') + sed -i.bak "/""$filename""/d" coverage.txt done - - uses: codecov/codecov-action@v3.1.1 with: - file: ./coverage.txt # optional + file: ./coverage.txt fail_ci_if_error: true test-e2e: diff --git a/cmd/gaiad/cmd/testnet.go b/cmd/gaiad/cmd/testnet.go index d43e97a4d5809..0ebe2402a311a 100644 --- a/cmd/gaiad/cmd/testnet.go +++ b/cmd/gaiad/cmd/testnet.go @@ -1,7 +1,5 @@ package cmd -// DONTCOVER - import ( "bufio" "encoding/json" diff --git a/tools/tools.go b/tools/tools.go index 939aaabbab93e..a8180c6cf9245 100644 --- a/tools/tools.go +++ b/tools/tools.go @@ -7,6 +7,8 @@ // REF: https://github.com/golang/go/wiki/Modules#how-can-i-track-tool-dependencies-for-a-module package tools +// DONTCOVER + import ( _ "github.com/golangci/golangci-lint/cmd/golangci-lint" )