From d02955732f32b6c96cbfa670d40b31546c089b54 Mon Sep 17 00:00:00 2001 From: Antonin Bas Date: Fri, 28 Jun 2024 10:21:59 -0700 Subject: [PATCH] Fix codecov upload for Jenkins CI scripts (#6493) It seems that codecov upload has been broken for a while for ci/jenkins/test-vmc.sh and ci/jenkins/test-mc.sh. The file pattern must be quoted when calling the codecov binary, or the glob will be expanded by the shell instead of by codecov (which is bad because we want the glob to be expanded in the context of the search directory). We also set "disable_search" to "true" when using the codecov-action in Github workflows. This action uses the codecov CLI and there is no need to keep search enabled when providing an explicit and comprehensive list of files to include in the report. Signed-off-by: Antonin Bas --- .github/workflows/go.yml | 3 +++ .github/workflows/kind.yml | 6 ++++++ ci/jenkins/test-mc.sh | 2 +- ci/jenkins/test-vmc.sh | 23 +++++++++++------------ 4 files changed, 21 insertions(+), 13 deletions(-) diff --git a/.github/workflows/go.yml b/.github/workflows/go.yml index 7d39c51ff4f..43bfb5d9819 100644 --- a/.github/workflows/go.yml +++ b/.github/workflows/go.yml @@ -51,6 +51,7 @@ jobs: with: token: ${{ secrets.CODECOV_TOKEN }} file: .coverage/coverage-unit.txt + disable_search: true flags: unit-tests name: codecov-unit-test fail_ci_if_error: ${{ github.event_name == 'push' }} @@ -76,6 +77,7 @@ jobs: with: token: ${{ secrets.CODECOV_TOKEN }} file: .coverage/coverage-unit.txt + disable_search: true flags: unit-tests name: codecov-unit-test fail_ci_if_error: ${{ github.event_name == 'push' }} @@ -107,6 +109,7 @@ jobs: with: token: ${{ secrets.CODECOV_TOKEN }} files: .coverage/coverage-integration.txt,multicluster/.coverage/coverage-integration.txt + disable_search: true flags: integration-tests name: codecov-integration-test fail_ci_if_error: ${{ github.event_name == 'push' }} diff --git a/.github/workflows/kind.yml b/.github/workflows/kind.yml index e37b936e2cd..a8b1748313f 100644 --- a/.github/workflows/kind.yml +++ b/.github/workflows/kind.yml @@ -117,6 +117,7 @@ jobs: with: token: ${{ secrets.CODECOV_TOKEN }} file: '*.cov.out*' + disable_search: true flags: kind-e2e-tests name: codecov-test-e2e-encap directory: test-e2e-encap-coverage @@ -185,6 +186,7 @@ jobs: with: token: ${{ secrets.CODECOV_TOKEN }} file: '*.cov.out*' + disable_search: true flags: kind-e2e-tests name: codecov-test-e2e-encap-non-default directory: test-e2e-encap-non-default-coverage @@ -255,6 +257,7 @@ jobs: with: token: ${{ secrets.CODECOV_TOKEN }} file: '*.cov.out*' + disable_search: true flags: kind-e2e-tests name: codecov-test-e2e-encap-all-features-enabled directory: test-e2e-encap-all-features-enabled-coverage @@ -317,6 +320,7 @@ jobs: with: token: ${{ secrets.CODECOV_TOKEN }} file: '*.cov.out*' + disable_search: true flags: kind-e2e-tests name: codecov-test-e2e-noencap directory: test-e2e-noencap-coverage @@ -379,6 +383,7 @@ jobs: with: token: ${{ secrets.CODECOV_TOKEN }} file: '*.cov.out*' + disable_search: true flags: kind-e2e-tests name: codecov-test-e2e-hybrid directory: test-e2e-hybrid-coverage @@ -453,6 +458,7 @@ jobs: with: token: ${{ secrets.CODECOV_TOKEN }} file: '*.cov.out*' + disable_search: true flags: kind-e2e-tests name: codecov-test-e2e-fa directory: test-e2e-fa-coverage diff --git a/ci/jenkins/test-mc.sh b/ci/jenkins/test-mc.sh index e02f13c3df6..15f3594013c 100755 --- a/ci/jenkins/test-mc.sh +++ b/ci/jenkins/test-mc.sh @@ -258,7 +258,7 @@ function run_codecov { (set -e shasum -a 256 -c codecov.SHA256SUM chmod +x codecov - ./codecov -c -t ${CODECOV_TOKEN} -F ${flag} -f ${file} -s ${dir} -C ${GIT_COMMIT} -r antrea-io/antrea + ./codecov -c -t "${CODECOV_TOKEN}" -F "${flag}" -f "${file}" -s "${dir}" -C "${GIT_COMMIT}" -r "antrea-io/antrea" rm -f trustedkeys.gpg codecov )} diff --git a/ci/jenkins/test-vmc.sh b/ci/jenkins/test-vmc.sh index 30c0e27b1d8..1ce62dfe891 100755 --- a/ci/jenkins/test-vmc.sh +++ b/ci/jenkins/test-vmc.sh @@ -308,8 +308,6 @@ function run_codecov { (set -e flag=$1 file=$2 dir=$3 - remote=$4 - ip=$5 rm -f trustedkeys.gpg codecov # This is supposed to be a one-time step, but there should be no harm in @@ -327,12 +325,7 @@ function run_codecov { (set -e chmod +x codecov - if [[ $remote == true ]]; then - ${SCP_WITH_UTILS_KEY} codecov jenkins@${ip}:~ - ${SSH_WITH_UTILS_KEY} -n jenkins@${ip} "cd antrea; ~/codecov -c -t ${CODECOV_TOKEN} -F ${flag} -f ${file} -C ${GIT_COMMIT} -r antrea-io/antrea" - else - ./codecov -c -t ${CODECOV_TOKEN} -F ${flag} -f ${file} -s ${dir} -C ${GIT_COMMIT} -r antrea-io/antrea - fi + ./codecov -c -t "${CODECOV_TOKEN}" -F "${flag}" -f "${file}" -s "${dir}" -C "${GIT_COMMIT}" -r "antrea-io/antrea" rm -f trustedkeys.gpg codecov )} @@ -547,8 +540,14 @@ function run_e2e { tar -zcf ${GIT_CHECKOUT_DIR}/antrea-test-logs.tar.gz ${GIT_CHECKOUT_DIR}/antrea-test-logs if [[ "$COVERAGE" == true ]]; then + pushd ${GIT_CHECKOUT_DIR}/e2e-coverage + for dir in */; do + go tool covdata textfmt -i="${dir}" -o "${dir%?}.cov.out" + rm -rf "${dir}"; + done + popd tar -zcf ${GIT_CHECKOUT_DIR}/e2e-coverage.tar.gz ${GIT_CHECKOUT_DIR}/e2e-coverage - run_codecov "e2e-tests" "*.cov.out*" "${GIT_CHECKOUT_DIR}/e2e-coverage" false "" + run_codecov "e2e-tests" "*.cov.out*" "${GIT_CHECKOUT_DIR}/e2e-coverage" fi } @@ -618,13 +617,13 @@ function run_conformance { if [[ "$COVERAGE" == true ]]; then rm -rf ${GIT_CHECKOUT_DIR}/conformance-coverage mkdir -p ${GIT_CHECKOUT_DIR}/conformance-coverage - collect_coverage + collect_coverage_for_conformance tar -zcf ${GIT_CHECKOUT_DIR}/$TESTCASE-coverage.tar.gz ${GIT_CHECKOUT_DIR}/conformance-coverage - run_codecov "e2e-tests" "*antrea*" "${GIT_CHECKOUT_DIR}/conformance-coverage" false "" + run_codecov "e2e-tests" "*antrea*" "${GIT_CHECKOUT_DIR}/conformance-coverage" fi } -function collect_coverage() { +function collect_coverage_for_conformance() { antrea_controller_pod_name="$(kubectl get pods --selector=app=antrea,component=antrea-controller -n kube-system --no-headers=true | awk '{ print $1 }')" controller_pid="$(kubectl exec -i $antrea_controller_pod_name -n kube-system -- pgrep antrea)" kubectl exec -i $antrea_controller_pod_name -n kube-system -- kill -SIGINT $controller_pid