diff --git a/.codecov.yml b/.codecov.yml index 27efcc8ea..7b390d3a0 100644 --- a/.codecov.yml +++ b/.codecov.yml @@ -1,8 +1,15 @@ -comment: off +# https://docs.codecov.com/docs/pull-request-comments +comment: + layout: "diff, flags, files" + behavior: default + require_changes: false # if true: only post the comment if coverage changes + require_base: false # [true :: must have a base report to post] + require_head: true # [true :: must have a head report to post] + hide_project_coverage: false # [true :: only show coverage on the git diff] coverage: status: + project: + default: + threshold: 5% # allow 5% coverage decrease patch: off - -ignore: - - "opensearchapi/api.*.go" diff --git a/.github/workflows/test-integration.yml b/.github/workflows/test-integration.yml index 54e6df6a2..af162dc10 100644 --- a/.github/workflows/test-integration.yml +++ b/.github/workflows/test-integration.yml @@ -27,13 +27,12 @@ jobs: for attempt in `seq 25`; do sleep 5; \ if curl -s localhost:9200; \ then echo '=====> ready'; break; fi; if [ $attempt == 25 ]; then exit 1; fi; echo '=====> waiting...'; done - - run: make test-integ race=true - - uses: codecov/codecov-action@v1 + - run: make test-integ race=true coverage=true + - uses: codecov/codecov-action@v3 with: - file: tmp/integration-client.cov + file: tmp/integ.cov flags: integration - secured: name: Tests against secure cluster runs-on: ubuntu-latest diff --git a/.github/workflows/test-unit.yml b/.github/workflows/test-unit.yml index d09f8f376..f8da83062 100644 --- a/.github/workflows/test-unit.yml +++ b/.github/workflows/test-unit.yml @@ -21,7 +21,10 @@ jobs: with: { go-version: "${{ matrix.go }}" } - run: go version - run: make test-unit race=true - - uses: codecov/codecov-action@v1 + if: matrix.os != 'ubuntu-latest' + - run: make test-unit race=true coverage=true + if: matrix.os == 'ubuntu-latest' + - uses: codecov/codecov-action@v3 with: file: tmp/unit.cov flags: unit diff --git a/CHANGELOG.md b/CHANGELOG.md index e652af2b5..98225d4f1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -33,6 +33,7 @@ Inspired from [Keep a Changelog](https://keepachangelog.com/en/1.0.0/) - go: update to golang version 1.20 ([#421](https://github.com/opensearch-project/opensearch-go/pull/421)) - guids: updated to work for the new opensearchapi ([#421](https://github.com/opensearch-project/opensearch-go/pull/421)) - Test adjusted to new opensearchapi functions and structs ([#421](https://github.com/opensearch-project/opensearch-go/pull/421)) +- Change codecov to comment code coverage to each PR ([#410](https://github.com/opensearch-project/opensearch-go/pull/410)) ### Deprecated @@ -50,4 +51,4 @@ Inspired from [Keep a Changelog](https://keepachangelog.com/en/1.0.0/) ### Security -[Unreleased]: https://github.com/opensearch-project/opensearch-go/compare/v2.3.0...HEAD \ No newline at end of file +[Unreleased]: https://github.com/opensearch-project/opensearch-go/compare/v2.3.0...HEAD diff --git a/Makefile b/Makefile index 0ffd990ee..7742ba36c 100644 --- a/Makefile +++ b/Makefile @@ -10,15 +10,13 @@ test-unit: ## Run unit tests ifdef race $(eval testunitargs += "-race") endif - $(eval testunitargs += "-cover" "-coverprofile=tmp/unit.cov" "./...") - @mkdir -p tmp - @if which gotestsum > /dev/null 2>&1 ; then \ - echo "gotestsum --format=short-verbose --junitfile=tmp/unit-report.xml --" $(testunitargs); \ - gotestsum --format=short-verbose --junitfile=tmp/unit-report.xml -- $(testunitargs); \ - else \ - echo "go test -v" $(testunitargs); \ - go test -v $(testunitargs); \ - fi; + $(eval testunitargs += "-cover" "./..." "-args" "-test.gocoverdir=$(PWD)/tmp/unit") + @mkdir -p $(PWD)/tmp/unit + @echo "go test -v" $(testunitargs); \ + go test -v $(testunitargs); +ifdef coverage + @go tool covdata textfmt -i=$(PWD)/tmp/unit -o $(PWD)/tmp/unit.cov +endif test: test-unit test-integ: ## Run integration tests @@ -30,16 +28,13 @@ endif ifdef race $(eval testintegargs += "-race") endif - $(eval testintegargs += "-cover" "-coverprofile=tmp/integration-client.cov" "-tags='$(testintegtags)'" "-timeout=1h") - @mkdir -p tmp - @if which gotestsum > /dev/null 2>&1 ; then \ - echo "gotestsum --format=short-verbose --junitfile=tmp/integration-report.xml --" $(testintegargs); \ - gotestsum --format=short-verbose --junitfile=tmp/integration-report.xml -- $(testintegargs) "."; \ - gotestsum --format=short-verbose --junitfile=tmp/integration-report.xml -- $(testintegargs) "./opensearchtransport" "./opensearchapi" "./opensearchutil"; \ - else \ - echo "go test -v" $(testintegargs) "."; \ - go test -v $(testintegargs) "." "./opensearchtransport" "./opensearchapi" "./opensearchutil"; \ - fi; + $(eval testintegargs += "-cover" "-tags='$(testintegtags)'" "-timeout=1h" "./..." "-args" "-test.gocoverdir=$(PWD)/tmp/integration") + @mkdir -p $(PWD)/tmp/integration + @echo "go test -v" $(testintegargs); \ + go test -v $(testintegargs); +ifdef coverage + @go tool covdata textfmt -i=$(PWD)/tmp/integration -o $(PWD)/tmp/integ.cov +endif test-integ-secure: ##Run secure integration tests go test -tags=secure,integration ./opensearch_secure_integration_test.go @@ -63,8 +58,11 @@ gen-coverage: ## Generate test coverage report @mkdir tmp @mkdir tmp/unit @mkdir tmp/integration - @go test -cover ./... -args -test.gocoverdir="$(PWD)/tmp/unit" - @go test -cover -tags='integration' ./... -args -test.gocoverdir="$(PWD)/tmp/integration" + @make test-unit coverage=true + @make test-integ coverage=true + @make build-coverage + +build-coverage: @go tool covdata textfmt -i=$(PWD)/tmp/unit,$(PWD)/tmp/integration -o $(PWD)/tmp/total.cov ##@ Development