diff --git a/scripts/openshiftci-presubmit-unittests.sh b/scripts/openshiftci-presubmit-unittests.sh index 9b858df9d48..283436b692e 100755 --- a/scripts/openshiftci-presubmit-unittests.sh +++ b/scripts/openshiftci-presubmit-unittests.sh @@ -27,3 +27,31 @@ cd ../.. # Run unit make test + +# Upload coverage to codecov.io - failures here should not fail the build +( + set +e + CODECOV_TOKEN_FILE="/var/run/codecov-token/CODECOV_TOKEN" + if [[ ! -f "${CODECOV_TOKEN_FILE}" ]]; then + echo "Codecov token not found at ${CODECOV_TOKEN_FILE}, skipping upload" + exit 0 + fi + CODECOV_TOKEN="$(cat "${CODECOV_TOKEN_FILE}")" + COMMIT="$(git rev-parse HEAD)" + BRANCH="$(git rev-parse --abbrev-ref HEAD)" + QUERY="token=${CODECOV_TOKEN}&commit=${COMMIT}&branch=${BRANCH}&flags=unit-tests" + + # Step 1: request an upload slot; response is two lines: report URL, S3 URL. + RESPONSE=$(curl -sX POST -H 'Accept: text/plain' "https://codecov.io/upload/v4?${QUERY}") + S3_URL=$(echo "${RESPONSE}" | sed -n 2p) + if [[ -z "${S3_URL}" ]]; then + echo "Codecov did not return an upload URL, aborting" + exit 1 + fi + + # Step 2: PUT the coverage file to GCS (Codecov uses GCS, not AWS S3; + # x-amz-storage-class is not supported and causes a 400). + curl -fiX PUT --data-binary @cover.out \ + -H 'Content-Type: text/plain' \ + "${S3_URL}" +) || echo "Coverage upload to codecov.io failed, continuing"