...

Text file src/edge-infra.dev/hack/build/ci/coverage-rpt.sh

Documentation: edge-infra.dev/hack/build/ci

     1#!/usr/bin/env bash
     2set -eu
     3
     4REPO="${REPO:-"edge-infra"}"
     5COMMIT="$(git rev-parse HEAD)"
     6COVERAGE_BUCKET="${COVERAGE_BUCKET:-"ret-edge-pltf-infra-coverage-reports"}"
     7PUSH_COVERAGE="${PUSH_COVERAGE:-"false"}"
     8
     9bazel query 'kind(go_test, //...) except test/e2e/...' > test-targets.txt
    10coverage_exit=0
    11bazel coverage --@io_bazel_rules_go//go/config:cover_format=go_cover \
    12  --nocache_test_results \
    13  --test_tag_filters=-integration,-end-to-end \
    14  --target_pattern_file=test-targets.txt || coverage_exit=$?
    15
    16if [[ $coverage_exit != 0 ]]; then
    17    echo "WARNING: 'bazel coverage' exited with code: $coverage_exit"
    18    echo "Some tests may have failed, uploading coverage report anyway"
    19fi
    20
    21find -L bazel-testlogs -name 'coverage.dat' | tr '\n' ' ' | sed 's/\ $//' > coverage-files.txt
    22
    23# Removed double quotes which is causing file too long error
    24# shellcheck disable=SC2046
    25gopherage aggregate $(cat coverage-files.txt) > aggregated.out
    26gopherage filter aggregated.out \
    27  --exclude-path 'edge-infra.dev/third_party/.*' \
    28  --exclude-path 'edge-infra.dev/.*/zz_generated.*.go' \
    29  -o filtered.out
    30
    31go tool cover -func=filtered.out
    32total=$(go tool cover -func=filtered.out | grep total | grep -Eo '[0-9]+\.[0-9]+')
    33echo "TOTAL COVERAGE: $total"
    34
    35if (( $(echo "$total <= 60" | bc -l) )) ; then
    36    COLOR=red
    37elif (( $(echo "$total > 80" | bc -l) )); then
    38    COLOR=green
    39else
    40    COLOR=yellow
    41fi
    42
    43go tool cover -html=filtered.out -o coverage.html
    44
    45if [ "$PUSH_COVERAGE" = 'true' ]; then
    46    echo "generating badge to coverage.svg..."
    47    curl "https://img.shields.io/badge/Coverage-$total%25-$COLOR" > coverage.svg
    48    echo "done"
    49
    50    gsutil cp ./coverage.html "gs://ret-edge-pltf-infra-coverage-reports/$REPO/coverage.html"
    51    gsutil cp ./coverage.svg  "gs://ret-edge-pltf-infra-coverage-reports/$REPO/coverage.svg"
    52    gsutil cp ./filtered.out  "gs://ret-edge-pltf-infra-coverage-reports/$REPO/$COMMIT/filtered.out"
    53    gsutil acl ch -u AllUsers:R "gs://ret-edge-pltf-infra-coverage-reports/$REPO/coverage.svg"
    54fi

View as plain text