Skip to content

Commit

Permalink
ci: coverage report on test failure (#43)
Browse files Browse the repository at this point in the history
* ci: coverage report on test failure

* ci(perf): add mod and build caching

* ci: fix continue on error

* ci: remove dont cover and mod based cache key

* ci: handle failed test

* ci: remove test envs
  • Loading branch information
pratikbin authored Sep 14, 2022
1 parent b4ed961 commit 5e76617
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 17 deletions.
37 changes: 22 additions & 15 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,29 +12,31 @@ jobs:
test-coverage-upload:
runs-on: ubuntu-latest
steps:

- uses: actions/setup-go@v3
with:
go-version: 1.16
go-version: 1.17

- uses: actions/checkout@v3

- run: make test

- name: filter out DONTCOVER
if: github.event_name == 'pull_request'
- uses: actions/cache@v3
with:
path: |
~/.cache/go-build
~/go/pkg/mod
key: ${{ runner.os }}-go-${{ hashFiles('**/go.mod') }}
restore-keys: |
${{ runner.os }}-go-
- name: Test
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')"
for filename in ${excludelist}; do
filename=$(echo $filename | sed 's/^./github.com\/cosmos\/cosmos-sdk/g')
echo "Excluding ${filename} from coverage report..."
sed -i "/$(echo $filename | sed 's/\//\\\//g')/d" ./coverage.out
done
set +e -x
make test
TEST_FAILED=false
[[ $? == 0 ]] && echo "TEST_FAILED=true" >> $GITHUB_ENV
id: test_status

- name: Convert coverage to lcov
if: github.evnte_name == 'pull_request'
if: github.event_name == 'pull_request'
uses: jandelgado/gcov2lcov-action@v1

- name: Code Coverage Report
Expand All @@ -43,3 +45,8 @@ jobs:
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
lcov-file: coverage.lcov

- name: Fail CI if test was failed
if: ${{ env.TEST_FAILED }}
run: |
false
6 changes: 4 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ distclean:
.PHONY: distclean

### Testing
TEST_TARGET ?= ./...
TEST_ARGS ?= -timeout 12m -race -coverprofile=./coverage.out -covermode=atomic -v

test: test-unit
test-all: test-unit test-ledger-mock test-race test-cover
Expand All @@ -55,7 +57,7 @@ test-ledger: test-ledger-mock
@go test -mod=readonly -v `go list github.com/cosmos/cosmos-sdk/crypto` -tags='cgo ledger'

test-unit:
@VERSION=$(VERSION) go test -mod=readonly $(PACKAGES_NOSIMULATION) -tags='ledger test_ledger_mock'
@VERSION=$(VERSION) go test -mod=readonly -tags='ledger test_ledger_mock' $(PACKAGES_NOSIMULATION) $(TEST_TARGET) $(TEST_ARGS)

test-race:
@VERSION=$(VERSION) go test -mod=readonly -race $(PACKAGES_NOSIMULATION)
Expand Down Expand Up @@ -150,4 +152,4 @@ lintci-update: lintci-remove lintci-install
.PHONY: lintci-update

goimports:
goimports -local="github.com/AssetMantle/modules" -w .
goimports -local="github.com/AssetMantle/modules" -w .

0 comments on commit 5e76617

Please sign in to comment.