Skip to content

Commit 2b779a2

Browse files
AdamSalehclaude
andauthored
Added unit-test codecov upload (#1092)
* Added unit-test codecov upload. Signed-off-by: Adam Saleh <adam@asaleh.net> * fix: pin codecov CLI version and verify checksum Pin the codecov CLI download to a specific version (v11.2.8) and verify the SHA256 checksum before executing, addressing the supply-chain risk of fetching an unpinned "latest" binary. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> Signed-off-by: Adam Saleh <adam@asaleh.net> --------- Signed-off-by: Adam Saleh <adam@asaleh.net> Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 62c153e commit 2b779a2

1 file changed

Lines changed: 28 additions & 0 deletions

File tree

scripts/openshiftci-presubmit-unittests.sh

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,3 +27,31 @@ cd ../..
2727

2828
# Run unit
2929
make test
30+
31+
# Upload coverage to codecov.io - failures here should not fail the build
32+
(
33+
set +e
34+
CODECOV_TOKEN_FILE="/var/run/codecov-token/CODECOV_TOKEN"
35+
if [[ ! -f "${CODECOV_TOKEN_FILE}" ]]; then
36+
echo "Codecov token not found at ${CODECOV_TOKEN_FILE}, skipping upload"
37+
exit 0
38+
fi
39+
CODECOV_TOKEN="$(cat "${CODECOV_TOKEN_FILE}")"
40+
COMMIT="$(git rev-parse HEAD)"
41+
BRANCH="$(git rev-parse --abbrev-ref HEAD)"
42+
QUERY="token=${CODECOV_TOKEN}&commit=${COMMIT}&branch=${BRANCH}&flags=unit-tests"
43+
44+
# Step 1: request an upload slot; response is two lines: report URL, S3 URL.
45+
RESPONSE=$(curl -sX POST -H 'Accept: text/plain' "https://codecov.io/upload/v4?${QUERY}")
46+
S3_URL=$(echo "${RESPONSE}" | sed -n 2p)
47+
if [[ -z "${S3_URL}" ]]; then
48+
echo "Codecov did not return an upload URL, aborting"
49+
exit 1
50+
fi
51+
52+
# Step 2: PUT the coverage file to GCS (Codecov uses GCS, not AWS S3;
53+
# x-amz-storage-class is not supported and causes a 400).
54+
curl -fiX PUT --data-binary @cover.out \
55+
-H 'Content-Type: text/plain' \
56+
"${S3_URL}"
57+
) || echo "Coverage upload to codecov.io failed, continuing"

0 commit comments

Comments
 (0)