Skip to content

Commit

Permalink
Merge fb3c400 into f3eaeb8
Browse files Browse the repository at this point in the history
  • Loading branch information
kortschak committed Feb 20, 2019
2 parents f3eaeb8 + fb3c400 commit 5bcbb28
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 8 deletions.
3 changes: 2 additions & 1 deletion .travis.yml
Expand Up @@ -58,7 +58,8 @@ script:
- go build -v ./...
- go test $TAGS -v ./...
# Only run test coverage analysis if we are secure and even with origin master.
- if [[ "${TRAVIS_SECURE_ENV_VARS}" == true && "$(git ls-remote origin master | cut -f1)" == "$(git rev-parse HEAD)" ]]; then bash ./.travis/test-coverage.sh; fi
# - if [[ "${TRAVIS_SECURE_ENV_VARS}" == true && "$(git ls-remote origin master | cut -f1)" == "$(git rev-parse HEAD)" ]]; then bash ./.travis/test-coverage.sh; fi
- if [[ "${TRAVIS_SECURE_ENV_VARS}" == true ]]; then bash ./.travis/test-coverage.sh; fi
- ${TRAVIS_BUILD_DIR}/.travis/check-imports.sh
# This is run last since it alters the tree.
- ${TRAVIS_BUILD_DIR}/.travis/check-generate.sh
Expand Down
37 changes: 30 additions & 7 deletions .travis/test-coverage.sh
@@ -1,7 +1,27 @@
#!/bin/bash

PROFILE_OUT=$PWD/profile.out
ACC_OUT=$PWD/acc.out
MODE=set
PROFILE_OUT="${PWD}/profile.out"
ACC_OUT="${PWD}/coverage.txt"

# FIXME(kortschak): Remove this; temporarily only doing latest release.
latestRelease=$(
git ls-remote --tags https://github.com/golang/go.git 'go*' \
| egrep 'go[1-9]+\.[0-9]+\.[0-9]+$' \
| sed -e 's|^.*tags/||g' \
| sort -V \
| tail -n 1
)
echo Latest Go release: $latestRelease

currentVersion=$(go version | cut -d' ' -f3)
echo Current Go version: $currentVersion

if [[ "${currentVersion%.*}" != "${latestRelease%.*}" ]]; then
echo Skipping coverage analysis.
exit 0
fi
#######################################################################

testCover() {
# set the return value to 0 (successful)
Expand All @@ -13,22 +33,25 @@ testCover() {
# switch to the directory to check
pushd $d > /dev/null
# create the coverage profile
coverageresult=`go test $TAGS -coverprofile=$PROFILE_OUT`
coverageresult=$(go test $TAGS -coverprofile="${PROFILE_OUT}" -covermode=${MODE})
# output the result so we can check the shell output
echo ${coverageresult}
# append the results to acc.out if coverage didn't fail, else set the retval to 1 (failed)
( [[ ${coverageresult} == *FAIL* ]] && retval=1 ) || ( [ -f $PROFILE_OUT ] && grep -v "mode: set" $PROFILE_OUT >> $ACC_OUT )
( [[ ${coverageresult} == *FAIL* ]] && retval=1 ) || ( [ -f "${PROFILE_OUT}" ] && grep -v "mode: ${MODE}" "${PROFILE_OUT}" >> "${ACC_OUT}" )
# return to our working dir
popd > /dev/null
# return our return value
return $retval
}

# Init acc.out
echo "mode: set" > $ACC_OUT
# Init coverage.txt
echo "mode: ${MODE}" > $ACC_OUT

# Run test coverage on all directories containing go files except testlapack testblas and testgraph.
find . -type d -not -path '*testlapack*' -and -not -path '*testblas*' -and -not -path '*testgraph*' | while read d; do testCover $d || exit; done

# Upload the coverage profile to coveralls.io
[ -n "$COVERALLS_TOKEN" ] && ( goveralls -coverprofile=$ACC_OUT -service=travis-ci -repotoken $COVERALLS_TOKEN || echo -e '\n\e[31mCoveralls failed.\n' )
[ -n "$COVERALLS_TOKEN" ] && ( goveralls -coverprofile=$ACC_OUT || echo -e '\n\e[31mCoveralls failed.\n' )

# Upload to coverage profile to codedov.io
[ -n "$CODECOV_TOKEN" ] && ( bash <(curl -s https://codecov.io/bash) || echo -e '\n\e[31mCodecov failed.\n' )

0 comments on commit 5bcbb28

Please sign in to comment.