Skip to content

Commit

Permalink
build: added coverage uploading to codecov.io, ignore generated files…
Browse files Browse the repository at this point in the history
…, 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
d4l3k committed Jul 21, 2016
1 parent d43713b commit 54c2287
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 48 deletions.
6 changes: 3 additions & 3 deletions Makefile
Expand Up @@ -235,9 +235,9 @@ $(GLOCK):
@unset GIT_WORK_TREE; $(GLOCK) sync github.com/cockroachdb/cockroach
touch $@

.PHONY: coveralls
coveralls:
@build/coveralls.sh
.PHONY: upload-coverage
upload-coverage:
@build/upload-coverage.sh

include .bootstrap

Expand Down
45 changes: 0 additions & 45 deletions build/coveralls.sh

This file was deleted.

65 changes: 65 additions & 0 deletions build/upload-coverage.sh
@@ -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"

0 comments on commit 54c2287

Please sign in to comment.