Skip to content

Commit

Permalink
feat_: add UNIT_TEST_REPORT_CODECOV ci flag
Browse files Browse the repository at this point in the history
  • Loading branch information
igor-sirotin committed Sep 3, 2024
1 parent 40e659e commit 277eec4
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 2 deletions.
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -367,6 +367,7 @@ test-unit: export UNIT_TEST_FAILFAST ?= true
test-unit: export UNIT_TEST_RERUN_FAILS ?= true
test-unit: export UNIT_TEST_USE_DEVELOPMENT_LOGGER ?= true
test-unit: export UNIT_TEST_REPORT_CODECLIMATE ?= false
test-unit: export UNIT_TEST_REPORT_CODECOV ?= false
test-unit: export UNIT_TEST_PACKAGES ?= $(call sh, go list ./... | \
grep -v /vendor | \
grep -v /t/e2e | \
Expand Down
6 changes: 6 additions & 0 deletions _assets/ci/Jenkinsfile.tests
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,11 @@ pipeline {
defaultValue: true,
description: 'Should the job report test coverage to CodeClimate?'
)
booleanParam(
name: 'UNIT_TEST_REPORT_CODECOV',
defaultValue: false,
description: 'Should the job report test coverage to Codecov?'
)
booleanParam(
name: 'UNIT_TEST_DRY_RUN',
defaultValue: false,
Expand Down Expand Up @@ -77,6 +82,7 @@ pipeline {
UNIT_TEST_RERUN_FAILS = "${params.UNIT_TEST_RERUN_FAILS}"
UNIT_TEST_USE_DEVELOPMENT_LOGGER = "${params.UNIT_TEST_USE_DEVELOPMENT_LOGGER}"
UNIT_TEST_REPORT_CODECLIMATE = "${params.UNIT_TEST_REPORT_CODECLIMATE}"
UNIT_TEST_REPORT_CODECOV = "${params.UNIT_TEST_REPORT_CODECOV}"
UNIT_TEST_DRY_RUN = "${params.UNIT_TEST_DRY_RUN}"
}

Expand Down
11 changes: 9 additions & 2 deletions _assets/scripts/run_unit_tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -144,15 +144,22 @@ grep -v '^github.com/status-im/status-go/cmd/' ${merged_coverage_report} > ${fin
echo -e "${GRN}Generating HTML coverage report${RST}"
go tool cover -html ${final_coverage_report} -o test-coverage.html

# https://docs.codeclimate.com/docs/jenkins#jenkins-ci-builds
GIT_COMMIT=$(git log | grep -m1 -oE '[^ ]+$')

# Upload coverage report to CodeClimate
if [[ $UNIT_TEST_REPORT_CODECLIMATE == 'true' ]]; then
echo -e "${GRN}Uploading coverage report to CodeClimate${RST}"
# https://docs.codeclimate.com/docs/jenkins#jenkins-ci-builds
GIT_COMMIT=$(git log | grep -m1 -oE '[^ ]+$')
cc-test-reporter format-coverage --prefix=github.com/status-im/status-go # To generate 'coverage/codeclimate.json'
cc-test-reporter after-build --prefix=github.com/status-im/status-go
fi

if [[ $UNIT_TEST_REPORT_CODECOV == 'true' ]]; then
echo -e "${GRN}Uploading coverage report to Codecov${RST}"
# https://docs.codeclimate.com/docs/jenkins#jenkins-ci-builds
codecov -t ${CODECOV_TOKEN} -f ${final_coverage_report} -F "unit" ${GIT_COMMIT}
fi

# Generate report with test stats
shopt -s globstar nullglob # Enable recursive globbing
if [[ "${UNIT_TEST_COUNT}" -gt 1 ]]; then
Expand Down

0 comments on commit 277eec4

Please sign in to comment.