scripts/coverage.sh: detect use of "-mod vendor"

This commit is contained in:
Yousong Zhou
2020-12-21 11:22:31 +08:00
parent ce05e5290c
commit e01492df4f

View File

@@ -30,8 +30,14 @@ function push_to_codecov() {
covermode=${COVERMODE:-atomic} covermode=${COVERMODE:-atomic}
coverdir=$(mktemp -d /tmp/coverage.XXXXXXXXXX) coverdir=$(mktemp -d /tmp/coverage.XXXXXXXXXX)
profile="${coverdir}/profile.out" profile="${coverdir}/profile.out"
cwd="$PWD"
if [ -s "$cwd/go.mod" -a -d "$cwd/vendor" ]; then
mod_args=(-mod vendor)
fi
if [ -z "$pkgs" ]; then if [ -z "$pkgs" ]; then
pkgs="$(go list -mod vendor -test ./... | grep '\.test$' | sed -e 's/\.test$//')" pkgs="$(go list "${mod_args[@]}" -test ./... | grep '\.test$' | sed -e 's/\.test$//')"
pkgs="$(echo "$pkgs" | grep -vE 'host-image|hostimage')" pkgs="$(echo "$pkgs" | grep -vE 'host-image|hostimage')"
fi fi
if type circleci &>/dev/null; then if type circleci &>/dev/null; then
@@ -44,7 +50,7 @@ echo "$pkgs" | xargs -n 8 --no-run-if-empty echo \
go test -v \ go test -v \
-coverprofile="$profile.tmp" \ -coverprofile="$profile.tmp" \
-covermode="$covermode" \ -covermode="$covermode" \
-mod vendor \ "${mod_args[@]}" \
-ldflags '-w' \ -ldflags '-w' \
$batch; \ $batch; \
tail -n +2 "$profile.tmp" >>"$profile"; \ tail -n +2 "$profile.tmp" >>"$profile"; \