github.com/cockroachdb/pebble@v0.0.0-20231214172447-ab4952c5f87b/scripts/pr-codecov-run-tests.sh (about) 1 #!/usr/bin/env bash 2 3 # This script runs unit tests with coverage enabled for a specific list of 4 # package paths and outputs the coverage to a json file. 5 # 6 # Package paths that are not valid in this tree are tolerated. 7 8 set -xeuo pipefail 9 10 output_json_file="$1" 11 packages="$2" 12 13 # Find the targets. We need to convert from, e.g. 14 # . objstorage objstorage/objstorageprovider 15 # to 16 # . ./objstorage ./objstorage/objstorageprovider 17 18 paths="" 19 sep="" 20 21 for p in ${packages}; do 22 # Check that the path exists and contains Go files. 23 if ls "${p}"/*.go >/dev/null 2>&1; then 24 if [[ $p != "." ]]; then 25 p="./$p" 26 fi 27 paths="${paths}${sep}${p}" 28 sep=" " 29 fi 30 done 31 32 if [ -z "${paths}" ]; then 33 echo "Skipping" 34 touch "${output_json_file}" 35 exit 0 36 fi 37 38 tmpfile=$(mktemp --suffix -coverprofile) 39 trap 'rm -f "${tmpfile}"' EXIT 40 41 make testcoverage COVER_PROFILE="${tmpfile}" PKG="$paths" 42 go run github.com/cockroachdb/code-cov-utils/gocover2json@v1.0.0 \ 43 --trim-prefix github.com/cockroachdb/pebble/ \ 44 "${tmpfile}" "${output_json_file}"