Skip to content

Commit

Permalink
Merge code coverage output into single file for codecov.io (#514)
Browse files Browse the repository at this point in the history
* Merge code coverage output

This fixes an issue where code coverage was not being reported.
Fixes #300

* fixup! Merge code coverage output

* BSD and GNU Linux -i parameter incompatibility

Resort to two-step process

* fixup! BSD and GNU Linux -i parameter incompatibility
  • Loading branch information
evantorrie committed Jan 7, 2021
1 parent 26c2b18 commit cede46c
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 9 deletions.
3 changes: 1 addition & 2 deletions .github/workflows/build_and_test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,7 @@ jobs:
run: |
make ci
mkdir -p $TEST_RESULTS
find . -name 'coverage.html' > "${TEST_RESULTS}/coverage.lst"
tar -n -cf - -T "${TEST_RESULTS}/coverage.lst" | tar -C "${TEST_RESULTS}" -xvf -
cp coverage.{txt,html} $TEST_RESULTS
- uses: codecov/codecov-action@v1
with:
file: ./coverage.txt
Expand Down
18 changes: 11 additions & 7 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ endif

GOTEST_MIN = go test -v -timeout 30s
GOTEST = $(GOTEST_MIN) -race
GOTEST_WITH_COVERAGE = $(GOTEST) -coverprofile=coverage.txt -covermode=atomic
GOTEST_WITH_COVERAGE = $(GOTEST) -coverprofile=coverage.out -covermode=atomic -coverpkg=./...

.DEFAULT_GOAL := precommit

Expand All @@ -47,12 +47,16 @@ precommit: dependabot-check license-check generate build lint test

.PHONY: test-with-coverage
test-with-coverage:
set -e; for dir in $(ALL_COVERAGE_MOD_DIRS); do \
set -e; \
printf "" > coverage.txt; \
for dir in $(ALL_COVERAGE_MOD_DIRS); do \
echo "go test ./... + coverage in $${dir}"; \
(cd "$${dir}" && \
$(GOTEST_WITH_COVERAGE) ./... && \
go tool cover -html=coverage.txt -o coverage.html); \
done
go tool cover -html=coverage.out -o coverage.html); \
[ -f "$${dir}/coverage.out" ] && cat "$${dir}/coverage.out" >> coverage.txt; \
done; \
sed -i.bak -e '2,$$ { /^mode: /d; }' coverage.txt && rm coverage.txt.bak

.PHONY: ci
ci: precommit check-clean-work-tree test-with-coverage test-386
Expand All @@ -65,7 +69,7 @@ test-gocql:
CMD=cassandra IMG_NAME=cass-integ ./tools/wait.sh; \
(cd instrumentation/github.com/gocql/gocql/otelgocql && \
$(GOTEST_WITH_COVERAGE) . && \
go tool cover -html=coverage.txt -o coverage.html); \
go tool cover -html=coverage.out -o coverage.html); \
docker stop cass-integ; \
fi

Expand All @@ -77,7 +81,7 @@ test-mongo-driver:
CMD=mongo IMG_NAME=mongo-integ ./tools/wait.sh; \
(cd instrumentation/go.mongodb.org/mongo-driver/mongo/otelmongo && \
$(GOTEST_WITH_COVERAGE) . && \
go tool cover -html=coverage.txt -o coverage.html); \
go tool cover -html=coverage.out -o coverage.html); \
docker stop mongo-integ; \
fi

Expand All @@ -89,7 +93,7 @@ test-gomemcache:
CMD=gomemcache IMG_NAME=gomemcache-integ ./tools/wait.sh; \
(cd instrumentation/github.com/bradfitz/gomemcache/memcache/otelmemcache && \
$(GOTEST_WITH_COVERAGE) . && \
go tool cover -html=coverage.txt -o coverage.html); \
go tool cover -html=coverage.out -o coverage.html); \
docker stop gomemcache-integ ; \
fi

Expand Down

0 comments on commit cede46c

Please sign in to comment.