diff --git a/.travis.yml b/.travis.yml index bd4a89744..531c366f3 100644 --- a/.travis.yml +++ b/.travis.yml @@ -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 diff --git a/.travis/test-coverage.sh b/.travis/test-coverage.sh index 3e3fc5322..9c2c3e7b8 100644 --- a/.travis/test-coverage.sh +++ b/.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) @@ -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' )