Skip to content

Commit

Permalink
create code-coverage-comment.yml file to create a comment of code cov…
Browse files Browse the repository at this point in the history
…erage (#410)

* changelog: update codecov config and update workflows

Signed-off-by: Tanner Jones <alltechguyblog@gmail.com>

* modified the .codecov.yml for pr comment for code coverage

Signed-off-by: Tanner Jones <alltechguyblog@gmail.com>

* Makefile: create coverage during test

Signed-off-by: Jakob Hahn <jakob.hahn@hetzner.com>

* adjust workflows to new codecov version

Signed-off-by: Jakob Hahn <jakob.hahn@hetzner.com>

---------

Signed-off-by: Tanner Jones <alltechguyblog@gmail.com>
Signed-off-by: Jakob Hahn <jakob.hahn@hetzner.com>
Co-authored-by: Jakob Hahn <jakob.hahn@hetzner.com>
  • Loading branch information
tannerjones4075 and Jakob3xD authored Nov 20, 2023
1 parent 63667a2 commit 81200d8
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 31 deletions.
15 changes: 11 additions & 4 deletions .codecov.yml
Original file line number Diff line number Diff line change
@@ -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"
7 changes: 3 additions & 4 deletions .github/workflows/test-integration.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 4 additions & 1 deletion .github/workflows/test-unit.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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
[Unreleased]: https://github.com/opensearch-project/opensearch-go/compare/v2.3.0...HEAD
40 changes: 19 additions & 21 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down

0 comments on commit 81200d8

Please sign in to comment.