Skip to content

Commit fdb6a32

Browse files
authored
PYTHON-5467 Fix codecov upload on Evergreen (#2702)
1 parent b1a0a1f commit fdb6a32

3 files changed

Lines changed: 35 additions & 16 deletions

File tree

.evergreen/generated_configs/functions.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -268,6 +268,8 @@ functions:
268268
- github_pr_number
269269
- github_pr_head_branch
270270
- github_author
271+
- is_patch
272+
- branch_name
271273
type: test
272274

273275
# Upload coverage

.evergreen/scripts/generate_config.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1087,6 +1087,8 @@ def create_upload_coverage_codecov_func():
10871087
"github_pr_number",
10881088
"github_pr_head_branch",
10891089
"github_author",
1090+
"is_patch",
1091+
"branch_name",
10901092
]
10911093
args = [
10921094
".evergreen/scripts/upload-codecov.sh",

.evergreen/scripts/upload-codecov.sh

Lines changed: 31 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -9,34 +9,49 @@ ROOT=$(dirname "$(dirname $HERE)")
99
pushd $ROOT > /dev/null
1010
export FNAME=coverage.xml
1111

12-
if [ -z "${github_pr_number:-}" ]; then
13-
echo "This is not a PR, not running codecov"
12+
if [ -n "${is_patch:-}" ]; then
13+
echo "This is a patch build, not running codecov"
1414
exit 0
1515
fi
1616

1717
if [ ! -f ".coverage" ]; then
18-
echo "There are no XML test results, not running codecov"
18+
echo "There are no coverage results, not running codecov"
1919
exit 0
2020
fi
2121

2222
echo "Uploading..."
23-
printf 'pr: %s\n' "$github_pr_number"
2423
printf 'sha: %s\n' "$github_commit"
25-
printf 'branch: %s:%s\n' "$github_author" "$github_pr_head_branch"
2624
printf 'flag: %s-%s\n' "$build_variant" "$task_name"
2725
printf 'file: %s\n' "$FNAME"
2826
uv tool run --with "coverage[toml]" coverage xml
29-
uv tool run --from codecov-cli codecovcli upload-process \
30-
--report-type coverage \
31-
--disable-search \
32-
--fail-on-error \
33-
--git-service github \
34-
--token ${CODECOV_TOKEN} \
35-
--pr ${github_pr_number} \
36-
--sha ${github_commit} \
37-
--branch "${github_author}:${github_pr_head_branch}" \
38-
--flag "${build_variant}-${task_name}" \
39-
--file $FNAME
27+
28+
codecov_args=(
29+
upload-process
30+
--report-type coverage
31+
--disable-search
32+
--fail-on-error
33+
--git-service github
34+
--token "${CODECOV_TOKEN}"
35+
--sha "${github_commit}"
36+
--flag "${build_variant}-${task_name}"
37+
--file "${FNAME}"
38+
)
39+
40+
if [ -n "${github_pr_number:-}" ]; then
41+
printf 'branch: %s:%s\n' "$github_author" "$github_pr_head_branch"
42+
printf 'pr: %s\n' "$github_pr_number"
43+
44+
uv tool run --from codecov-cli codecovcli \
45+
"${codecov_args[@]}" \
46+
--pr "${github_pr_number}" \
47+
--branch "${github_author}:${github_pr_head_branch}"
48+
else
49+
printf 'branch: %s\n' "$branch_name"
50+
51+
uv tool run --from codecov-cli codecovcli \
52+
"${codecov_args[@]}" \
53+
--branch "${branch_name}"
54+
fi
4055
echo "Uploading...done."
4156

4257
popd > /dev/null

0 commit comments

Comments
 (0)