Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
build: added coverage uploading to codecov.io, ignore generated files…
…, and optimize This added codecov.io as a coverage endpoint. Ignores files that match `(acceptance|cmd|ui/embedded|storage/simulation|sql/pgbench|.*\.(pb|pb\.gw)\.go)` since we don't care about files that are generated or those which are only for tests. Only generate coverage profiles for packages that are actually dependencies of the package we are testing.
- Loading branch information
Showing
3 changed files
with
68 additions
and
48 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 was deleted.
Oops, something went wrong.
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,65 @@ | ||
#!/bin/bash | ||
|
||
if [ -z "$COVERALLS_TOKEN" ]; then | ||
echo "FAIL: Missing or empty COVERALLS_TOKEN." | ||
exit 1 | ||
fi | ||
if [ -z "$CODECOV_TOKEN" ]; then | ||
echo "FAIL: Missing or empty CODECOV_TOKEN." | ||
exit 1 | ||
fi | ||
|
||
if [ -n "${TMPDIR-}" ]; then | ||
outdir="${TMPDIR}" | ||
else | ||
outdir="/tmp" | ||
fi | ||
|
||
main_package="github.com/cockroachdb/cockroach" | ||
# This regex removes files from the uploaded coverage. | ||
ignore_files="$main_package/(acceptance|cmd|ui/embedded|storage/simulation|sql/pgbench|.*\.(pb|pb\.gw)\.go)" | ||
|
||
coverage_dir="${outdir}/coverage" | ||
coverage_profile="${coverage_dir}/coverage.out" | ||
coverage_mode=count | ||
|
||
rm -rf "$coverage_dir" | ||
mkdir -p "$coverage_dir" | ||
|
||
# Run "make coverage" on each package. | ||
for pkg in $(go list ./...); do | ||
# Verify package has test files. | ||
if [ -z "$(go list -f '{{join .TestGoFiles ""}}{{join .XTestGoFiles ""}}' $pkg)" ]; then | ||
echo "$pkg: Skipping due to no test files." | ||
continue | ||
fi | ||
|
||
# Only generate coverage for cockroach dependencies. This fetches all test | ||
# deps and main deps, filters them, and converts them into a comma separated | ||
# list. | ||
coverpkg=$(go list -f '{{join .Deps "\n"}} | ||
{{join .TestImports "\n"}} | ||
{{join .XTestImports "\n"}}' $pkg | \ | ||
sort | uniq | grep "$main_package" | sed -e ':a' -e 'N' -e '$!ba' -e 's/\n/,/g') | ||
|
||
# Find all cockroach packages that are imported by this package or in it's | ||
# tests. | ||
f="${coverage_dir}/$(echo $pkg | tr / -).cover" | ||
touch $f | ||
time ${builder} make coverage \ | ||
PKG="$pkg" \ | ||
TESTFLAGS="-v -coverprofile=$f -covermode=$coverage_mode -coverpkg=$coverpkg" | \ | ||
tee "${outdir}/coverage.log" | ||
done | ||
|
||
# Merge coverage profiles and remove lines that match our ignore filter. | ||
gocovmerge "$coverage_dir"/*.cover | grep -vE "$ignore_files" > "$coverage_profile" | ||
|
||
# Upload profiles to coveralls.io. | ||
goveralls \ | ||
-coverprofile="$coverage_profile" \ | ||
-service=teamcity \ | ||
-repotoken=$COVERALLS_TOKEN | ||
|
||
# Upload profiles to codecov.io. | ||
bash <(curl -s https://codecov.io/bash) -f "$coverage_profile" |