-
Notifications
You must be signed in to change notification settings - Fork 458
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
workflows: restrict coverage testing to changed packages
This commit improves the code-cover-gen workflow to only run tests for the changed packages; other packages won't show up in the review so coverage data is not useful. This should speed up the build significantly.
- Loading branch information
1 parent
1253033
commit 0b401ee
Showing
3 changed files
with
82 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
#!/usr/bin/env bash | ||
|
||
BASE_SHA="$1" | ||
HEAD_SHA="$2" | ||
|
||
if [ -z "$HEAD_SHA" ];then | ||
echo "Usage: $0 <base-sha> <head-sha>" | ||
exit 1 | ||
fi | ||
|
||
git diff --name-only "${BASE_SHA}..${HEAD_SHA}" -- "*.go" \ | ||
| xargs -rn1 dirname \ | ||
| sort -u \ | ||
| xargs echo |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
#!/usr/bin/env bash | ||
|
||
# This script runs unit tests with coverage enabled for a specific list of | ||
# package paths and outputs the coverage to a json file. | ||
# | ||
# Package paths that are not valid in this tree are tolerated. | ||
|
||
set -xeuo pipefail | ||
|
||
output_json_file="$1" | ||
packages="$2" | ||
|
||
# Find the targets. We need to convert from, e.g. | ||
# . objstorage objstorage/objstorageprovider | ||
# to | ||
# . ./objstorage ./objstorage/objstorageprovider | ||
|
||
paths="" | ||
sep="" | ||
|
||
for p in ${packages}; do | ||
# Check that the path exists and contains Go files. | ||
if ls "${p}"/*.go >/dev/null 2>&1; then | ||
if [[ $p != "." ]]; then | ||
p="./$p" | ||
fi | ||
paths="${paths}${sep}${p}" | ||
sep=" " | ||
fi | ||
done | ||
|
||
if [ -z "${paths}" ]; then | ||
echo "Skipping" | ||
touch "${output_json_file}" | ||
exit 0 | ||
fi | ||
|
||
tmpfile=$(mktemp --suffix -coverprofile) | ||
trap 'rm -f "${tmpfile}"' EXIT | ||
|
||
make testcoverage COVER_PROFILE="${tmpfile}" PKG="$paths" | ||
go run github.com/cockroachdb/code-cov-utils/[email protected] \ | ||
--trim-prefix github.com/cockroachdb/pebble/ \ | ||
"${tmpfile}" "${output_json_file}" |