From b7bd4def8f78a1ff2935087f906be08d367e6bd2 Mon Sep 17 00:00:00 2001 From: Alvin Huang <17609145+alvin-huang@users.noreply.github.com> Date: Fri, 22 Nov 2019 11:49:02 -0500 Subject: [PATCH] add code coverage reporting (#6682) * add coverage reporting * add codecov reports * pass in SHA to codecov * ignore bindata_assetfs.go file from codecov --- .circleci/config.yml | 43 +++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 41 insertions(+), 2 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 04fb36793b..385a263d95 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -108,7 +108,13 @@ jobs: rm -rf /tmp/vault* - run: | PACKAGE_NAMES=$(go list ./... | circleci tests split --split-by=timings --timings-type=classname) - gotestsum --format=short-verbose --junitfile $TEST_RESULTS_DIR/gotestsum-report.xml -- -tags=$GOTAGS -p 3 $PACKAGE_NAMES + gotestsum --format=short-verbose --junitfile $TEST_RESULTS_DIR/gotestsum-report.xml -- -tags=$GOTAGS -p 3 -cover -coverprofile=cov_$CIRCLE_NODE_INDEX.part $PACKAGE_NAMES + + # save coverage report parts + - persist_to_workspace: + root: . + paths: + - cov_*.part - store_test_results: path: /tmp/test-results @@ -134,13 +140,42 @@ jobs: working_directory: api command: | PACKAGE_NAMES=$(go list ./... | circleci tests split --split-by=timings --timings-type=classname) - gotestsum --format=short-verbose --junitfile $TEST_RESULTS_DIR/gotestsum-report.xml -- -tags=$GOTAGS $PACKAGE_NAMES + gotestsum --format=short-verbose --junitfile $TEST_RESULTS_DIR/gotestsum-report.xml -- -tags=$GOTAGS -cover -coverprofile=cov_api.part $PACKAGE_NAMES + + # save coverage report parts + - persist_to_workspace: + root: ./api + paths: + - cov_*.part - store_test_results: path: /tmp/test-results - store_artifacts: path: /tmp/test-results + # combine code coverage results from the parallel circleci executors + coverage-merge: + docker: + - image: *GOLANG_IMAGE + environment: + <<: *ENVIRONMENT + steps: + - checkout + - attach_workspace: + at: . + - run: mkdir -p $TEST_RESULTS_DIR + - run: + name: merge coverage reports + command: | + echo "mode: set" > coverage.out + grep -h -v "mode: set" cov_*.part >> coverage.out + go tool cover -html=coverage.out -o /tmp/test-results/coverage.html + - run: + name: codecov upload + command: bash <(curl -s https://codecov.io/bash) -C $CIRCLE_SHA1 -f '!agent/bindata_assetfs.go' + - store_artifacts: + path: /tmp/test-results + # build all distros build-distros: &build-distros docker: @@ -540,6 +575,10 @@ workflows: requires: - dev-build - go-test-api: *go-test + - coverage-merge: + requires: + - go-test + - go-test-api build-distros: jobs: - check-vendor: