From b1b43fae74f0dd07a8a99e5295afd6d7db93c2cd Mon Sep 17 00:00:00 2001 From: Srinivas Baride Date: Sat, 17 Jul 2021 23:36:09 +0530 Subject: [PATCH] Added tests and code coverage GitHub workflow --- .github/workflows/test.yml | 33 +++++++++++++++++++++++++++++++++ .gitignore | 1 + Makefile | 6 +++++- README.md | 3 ++- 4 files changed, 41 insertions(+), 2 deletions(-) create mode 100644 .github/workflows/test.yml diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml new file mode 100644 index 00000000..5605f485 --- /dev/null +++ b/.github/workflows/test.yml @@ -0,0 +1,33 @@ +name: Tests and Code coverage + +on: + pull_request: + push: + branches: + - development + - master + +jobs: + test-coverage: + runs-on: ubuntu-latest + timeout-minutes: 30 + steps: + - uses: actions/checkout@v2.3.4 + - uses: actions/setup-go@v2.1.3 + with: + go-version: 1.16 + - name: Run tests with coverage + run: make test-coverage + - name: Exclude files from coverage report + run: | + filepaths+=" $(find ./ -type f -name '*.go' -exec grep -l 'DONOTCOVER' {} \;)" + filepaths+=" $(find ./ -type f -name '*.pb.go')" + filepaths+=" $(find ./ -type f -name '*.pb.gw.go')" + for filepath in ${filepaths}; do + filepath=$(echo ${filepath} | sed 's/^./github.com\/sentinel-official\/hub/g') + echo "Excluding file ${filepath} from coverage report..." + sed -i "/$(echo ${filepath} | sed 's/\//\\\//g')/d" ./coverage.txt + done + - uses: codecov/codecov-action@v1.5.2 + with: + file: ./coverage.txt diff --git a/.gitignore b/.gitignore index 7eb4d7ff..a44612f8 100644 --- a/.gitignore +++ b/.gitignore @@ -2,3 +2,4 @@ /.idea/ /vendor/ /build/ +/coverage.txt diff --git a/Makefile b/Makefile index fbc5f37f..c080c989 100644 --- a/Makefile +++ b/Makefile @@ -52,7 +52,11 @@ proto-lint: .PHONY: test test: - @go test -mod=readonly -v -cover ${PACKAGES} + @go test -mod=readonly -timeout 15m -v ${PACKAGES} + +.PHONT: test-coverage +test-coverage: + @go test -mod=readonly -timeout 15m -v -covermode=atomic -coverprofile=coverage.txt ${PACKAGES} .PHONY: tools tools: diff --git a/README.md b/README.md index 45b0cde3..d97e4dfa 100644 --- a/README.md +++ b/README.md @@ -1,9 +1,10 @@ # Sentinel Hub -[![Tag](https://img.shields.io/github/tag/sentinel-official/hub.svg)](https://github.com/sentinel-official/hub/releases/latest) +[![Codecov](https://codecov.io/gh/sentinel-official/hub/branch/development/graph/badge.svg)](https://codecov.io/gh/sentinel-official/hub?branch=development) [![GoReportCard](https://goreportcard.com/badge/github.com/sentinel-official/hub)](https://goreportcard.com/report/github.com/sentinel-official/hub) [![Licence](https://img.shields.io/github/license/sentinel-official/hub.svg)](https://github.com/sentinel-official/hub/blob/development/LICENSE) [![LoC](https://tokei.rs/b1/github/sentinel-official/hub)](https://github.com/sentinel-official/hub) +[![Tag](https://img.shields.io/github/tag/sentinel-official/hub.svg)](https://github.com/sentinel-official/hub/releases/latest) ## Installation