Skip to content

Commit 2d821ae

Browse files
authored
Codecov - Fix canonical paths issues (#186)
Signed-off-by: Reza Barazesh <[email protected]>
1 parent a7e18cd commit 2d821ae

File tree

1 file changed

+82
-12
lines changed

1 file changed

+82
-12
lines changed

buildkite/scripts/upload_codecov.sh

Lines changed: 82 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -9,34 +9,104 @@ STEP_LABEL="${1:-unknown}"
99
# Convert step label to flag format (lowercase, replace special chars with underscores)
1010
FLAG=$(echo "$STEP_LABEL" | tr '[:upper:]' '[:lower:]' | sed 's/[() %,+]/_/g' | sed 's/__*/_/g' | sed 's/^_//;s/_$//')
1111

12-
# Check if codecov token and coverage.xml exist
13-
if [ -z "${CODECOV_TOKEN:-}" ]; then
14-
echo "CODECOV_TOKEN not set, skipping upload"
12+
# Skip coverage upload for problematic tests
13+
if [ "$FLAG" = "multi-modal_models_test_standard" ]; then
14+
echo "Skipping coverage upload for $STEP_LABEL (known multi-directory test issue)"
1515
exit 0
1616
fi
1717

18-
if [ ! -f coverage.xml ]; then
19-
echo "coverage.xml not found, skipping upload"
18+
# Find and normalize ALL coverage.xml files in the workspace
19+
# This handles cases where tests run from different directories (e.g., whisper tests with cd ..)
20+
COVERAGE_FILES=$(find /vllm-workspace -name "coverage.xml" -type f 2>/dev/null || true)
21+
22+
if [ -z "$COVERAGE_FILES" ]; then
23+
echo "No coverage.xml files found in /vllm-workspace, skipping upload"
2024
exit 0
2125
fi
2226

27+
echo "Found coverage.xml files:"
28+
echo "$COVERAGE_FILES"
29+
30+
# Normalize paths in ALL coverage.xml files
31+
for cov_file in $COVERAGE_FILES; do
32+
echo ""
33+
echo "Processing: $cov_file"
34+
echo "Sample paths before normalization:"
35+
grep 'filename=' "$cov_file" | head -3 || true
36+
37+
# Normalize filenames to ensure consistent paths across uploads
38+
# Map any site/dist-packages and workspace-relative paths to canonical "vllm/"
39+
if sed -i \
40+
-e 's@filename="[^"]*/site-packages/vllm/@filename="vllm/@g' \
41+
-e 's@filename="[^"]*/dist-packages/vllm/@filename="vllm/@g' \
42+
-e 's@filename="/vllm-workspace/vllm/@filename="vllm/@g' \
43+
-e 's@filename="\./vllm/@filename="vllm/@g' \
44+
-e 's@filename="\.\./vllm/@filename="vllm/@g' \
45+
"$cov_file" 2>/dev/null; then
46+
echo "✓ Path normalization successful for $cov_file"
47+
else
48+
echo "⚠ Warning: sed path normalization failed for $cov_file"
49+
fi
50+
51+
echo "Sample paths after normalization:"
52+
grep 'filename=' "$cov_file" | head -3 || true
53+
done
54+
55+
# Use coverage.xml in current directory for upload
56+
if [ ! -f coverage.xml ]; then
57+
echo "Warning: No coverage.xml in current directory $(pwd), using first found file"
58+
FIRST_COV=$(echo "$COVERAGE_FILES" | head -1)
59+
ln -s "$FIRST_COV" coverage.xml || cp "$FIRST_COV" coverage.xml
60+
fi
61+
62+
# Ensure Codecov does not re-generate coverage from local DBs anywhere; upload XML as-is
63+
find /vllm-workspace -type f -name ".coverage*" -delete 2>/dev/null || true
64+
rm -f .coverage .coverage.* 2>/dev/null || true
65+
2366
# Download codecov CLI if not present
2467
if [ ! -f codecov ]; then
2568
curl -Os https://cli.codecov.io/latest/linux/codecov
2669
chmod +x codecov
2770
fi
2871

29-
# Upload to codecov
30-
./codecov upload-process \
31-
-t "${CODECOV_TOKEN}" \
32-
-f coverage.xml \
33-
--git-service github \
72+
# Determine slug (handle fork PRs)
73+
DEFAULT_SLUG="vllm-project/vllm"
74+
UPLOAD_SLUG="$DEFAULT_SLUG"
75+
if [ -n "${BUILDKITE_PULL_REQUEST:-}" ] && [ "${BUILDKITE_PULL_REQUEST}" != "false" ] && [ -n "${BUILDKITE_PULL_REQUEST_REPO:-}" ]; then
76+
# Parse owner/repo from git URL ([email protected]:owner/repo.git or https://github.com/owner/repo.git)
77+
UPLOAD_SLUG=$(echo "${BUILDKITE_PULL_REQUEST_REPO}" | sed -E 's#(git@|https?://)([^/:]+)[:/]([^/]+/[^/.]+)(\.git)?$#\3#')
78+
# Fallback to default on parse failure
79+
if ! echo "$UPLOAD_SLUG" | grep -q '/'; then
80+
UPLOAD_SLUG="$DEFAULT_SLUG"
81+
fi
82+
fi
83+
84+
echo "Uploading coverage for slug: $UPLOAD_SLUG, sha: ${BUILDKITE_COMMIT:-unknown}, branch: ${BUILDKITE_BRANCH:-unknown}, pr: ${BUILDKITE_PULL_REQUEST:-none}"
85+
86+
# Only require token for upstream slug; forks typically don't need one
87+
if [ "$UPLOAD_SLUG" = "$DEFAULT_SLUG" ] && [ -z "${CODECOV_TOKEN:-}" ]; then
88+
echo "CODECOV_TOKEN not set for upstream slug, skipping upload"
89+
exit 0
90+
fi
91+
92+
# Build Codecov args
93+
# Use coverage-upload directory to ensure codecov only finds our single combined file
94+
CODECOV_ARGS=(upload-process -f coverage.xml --git-service github \
3495
--build "${BUILDKITE_BUILD_NUMBER:-unknown}" \
3596
--branch "${BUILDKITE_BRANCH:-unknown}" \
3697
--sha "${BUILDKITE_COMMIT:-unknown}" \
37-
--slug vllm-project/vllm \
98+
--slug "$UPLOAD_SLUG" \
3899
--flag "$FLAG" \
39100
--name "$STEP_LABEL" \
40-
--dir /vllm-workspace || true
101+
--dir /vllm-workspace \
102+
--disable-search)
103+
104+
# Include PR number if available to help Codecov associate fork PRs
105+
if [ -n "${BUILDKITE_PULL_REQUEST:-}" ] && [ "${BUILDKITE_PULL_REQUEST}" != "false" ]; then
106+
CODECOV_ARGS=("${CODECOV_ARGS[@]}" --pr "${BUILDKITE_PULL_REQUEST}")
107+
fi
108+
109+
# Upload to codecov
110+
./codecov "${CODECOV_ARGS[@]}" || true
41111

42112
exit 0

0 commit comments

Comments
 (0)