From ebffaadba7d0ef9b79c7068b7507919e098fc7b0 Mon Sep 17 00:00:00 2001 From: Adam Reese Date: Wed, 6 Jul 2016 20:03:10 -0700 Subject: [PATCH] feat(ci): setup test coverage reports with coveralls.io --- scripts/ci.sh | 25 +++++++++++++++++-------- scripts/coverage.sh | 43 ++++++++++++++++++++++++++++--------------- 2 files changed, 45 insertions(+), 23 deletions(-) diff --git a/scripts/ci.sh b/scripts/ci.sh index 7ed63df4a..04aee0b51 100755 --- a/scripts/ci.sh +++ b/scripts/ci.sh @@ -22,13 +22,22 @@ IFS=$'\n\t' HELM_ROOT="${BASH_SOURCE[0]%/*}/.." cd "$HELM_ROOT" -case "${CIRCLE_NODE_INDEX-0}" in - 0) - echo "Running 'make test-unit'" +run_unit_test() { + if [[ "${CIRCLE_BRANCH-}" == "master" ]]; then + echo "Running unit tests with coverage'" + ./scripts/coverage.sh --coveralls + else + echo "Running unit tests'" make test-unit - ;; - 1) - echo "Running 'make test-style'" - make test-style - ;; + fi +} + +run_style_check() { + echo "Running 'make test-style'" + make test-style +} + +case "${CIRCLE_NODE_INDEX-0}" in + 0) run_unit_test ;; + 1) run_style_check ;; esac diff --git a/scripts/coverage.sh b/scripts/coverage.sh index ccb2d52fc..30553c1b9 100755 --- a/scripts/coverage.sh +++ b/scripts/coverage.sh @@ -16,22 +16,35 @@ set -euo pipefail -COVERDIR=${COVERDIR:-.coverage} -COVERMODE=${COVERMODE:-atomic} -PACKAGES=($(go list $(glide novendor))) +covermode=${COVERMODE:-atomic} +coverdir=$(mktemp -d /tmp/coverage.XXXXXXXXXX) +profile="${coverdir}/cover.out" -if [[ ! -d "$COVERDIR" ]]; then - mkdir -p "$COVERDIR" -fi +hash goveralls 2>/dev/null || go get github.com/mattn/goveralls -echo "mode: ${COVERMODE}" > "${COVERDIR}/coverage.out" +generate_cover_data() { + for d in $(godir) ; do + local output="${coverdir}/${d//\//-}.cover" + go test -coverprofile="${output}" -covermode="$covermode" "$d" + done -for d in "${PACKAGES[@]}"; do - go test -coverprofile=profile.out -covermode="$COVERMODE" "$d" - if [ -f profile.out ]; then - sed "/mode: $COVERMODE/d" profile.out >> "${COVERDIR}/coverage.out" - rm profile.out - fi -done + echo "mode: $covermode" >"$profile" + grep -h -v "^mode:" "$coverdir"/*.cover >>"$profile" +} + +push_to_coveralls() { + goveralls -coverprofile="${profile}" -service=circle-ci +} + +generate_cover_data +go tool cover -func "${profile}" + +case "$1" in + --html) + go tool cover -html "${profile}" + ;; + --coveralls) + push_to_coveralls + ;; +esac -go tool cover -html "${COVERDIR}/coverage.out" -o "${COVERDIR}/coverage.html"