Files
Egor RachkovskiiandEgor Rachkovskii c6b0bd7260 ci(tests): report coverage to Codecov on PRs (#7582)
* ci(tests): report coverage to Codecov on PRs

codecov upload-process relied on codecov-cli auto-detection, which doesn't
associate uploads with the pull request (and on merge-commit heads uploads to
the wrong commit), so Codecov posts no status checks on PRs while develop keeps
reporting.

Pass commit/branch/PR explicitly from Jenkins env (GIT_COMMIT, params.BRANCH,
utils.changeId()). No change to develop reporting (no PR -> --pr omitted).

* ci(tests): drop redundant null guards in codecov upload

Keep the -n guards (they omit --pr on develop where there is no PR, and keep local runs working when the vars are unset).

---------

Co-authored-by: Egor Rachkovskii <egorrachkovskii@status.im>
2026-07-02 11:13:07 +01:00

43 lines
1.6 KiB
Bash
Executable File

#!/usr/bin/env bash
source "${GIT_ROOT}/scripts/colors.sh"
report_to_codecov() {
# https://go.dev/blog/integration-test-coverage
echo -e "${GRN}Uploading coverage report to Codecov${RST}"
local tests_report_wildcard="${1}"
local coverage_report="${2}"
local flag="${3}"
# Gather report files with given wildcard
local report_files_args=""
for file in ${tests_report_wildcard}; do
report_files_args+="--file ${file} "
done
# Print codecov version
codecov --version
# Don't upload test results to Codecov while we re-run tests on failure.
# This results in having both failure and success results in the same report, which Codecov treats as a failure
# and doesn't report coverage to Github. More details here: https://github.com/status-im/status-go/issues/5963
# codecov do-upload --token "${CODECOV_TOKEN}" --report-type test_results ${report_files_args}
# Pass PR/commit/branch explicitly; codecov-cli auto-detection fails to associate PR uploads.
local context_args=()
[[ -n "${CODECOV_SHA:-}" ]] && context_args+=(-C "${CODECOV_SHA}")
[[ -n "${CODECOV_BRANCH:-}" ]] && context_args+=(-B "${CODECOV_BRANCH}")
[[ -n "${CODECOV_PR:-}" ]] && context_args+=(--pr "${CODECOV_PR}")
codecov upload-process --token "${CODECOV_TOKEN}" -f ${coverage_report} -F "${flag}" ${context_args[@]+"${context_args[@]}"}
}
convert_coverage_to_html() {
echo -e "${GRN}Generating HTML coverage report${RST}"
local input_coverage_report="${1}"
local output_coverage_report="${2}"
go tool cover -html "${input_coverage_report}" -o "${output_coverage_report}"
}