github.com/jingcheng-WU/gonum@v0.9.1-0.20210323123734-f1a2a11a8f7b/.github/workflows/script.d/travis-test-coverage.sh (about) 1 #!/bin/bash 2 3 if [[ "${TRAVIS_SECURE_ENV_VARS}" != true ]]; then 4 echo "skipping coverage - no secure environment" 5 exit 0 6 fi 7 8 # FIXME(kortschak): When we have arm64 assembly kernels, 9 # reconsider this for the internal/asm packages. 10 if [[ $(go env GOARCH) != "amd64" ]]; then 11 echo "skipping coverage - GOARCH != amd64" 12 exit 0 13 fi 14 15 ORIGIN_MASTER="$(git ls-remote origin master | cut -f1)" 16 CURRENT="$(git rev-parse HEAD)" 17 if [[ ${ORIGIN_MASTER} != ${CURRENT} ]]; then 18 echo "skipping coverage - not merged into master" 19 echo origin/master is ${ORIGIN_MASTER} 20 echo current HEAD is ${CURRENT} 21 exit 0 22 fi 23 24 MODE=set 25 PROFILE_OUT="${PWD}/profile.out" 26 ACC_OUT="${PWD}/coverage.txt" 27 28 testCover() { 29 # set the return value to 0 (successful) 30 retval=0 31 # get the directory to check from the parameter. Default to '.' 32 d=${1:-.} 33 # skip if there are no Go files here 34 ls $d/*.go &> /dev/null || return $retval 35 # switch to the directory to check 36 pushd $d > /dev/null 37 # create the coverage profile 38 coverageresult=$(go test $TAGS -coverprofile="${PROFILE_OUT}" -covermode=${MODE}) 39 # output the result so we can check the shell output 40 echo ${coverageresult} 41 # append the results to acc.out if coverage didn't fail, else set the retval to 1 (failed) 42 ( [[ ${coverageresult} == *FAIL* ]] && retval=1 ) || ( [ -f "${PROFILE_OUT}" ] && grep -v "mode: ${MODE}" "${PROFILE_OUT}" >> "${ACC_OUT}" ) 43 # return to our working dir 44 popd > /dev/null 45 # return our return value 46 return $retval 47 } 48 49 # Init coverage.txt 50 echo "mode: ${MODE}" > $ACC_OUT 51 52 # Run test coverage on all directories containing go files except testlapack, testblas, testgraph and testrand. 53 find . -type d -not -path '*testlapack*' -and -not -path '*testblas*' -and -not -path '*testgraph*' -and -not -path '*testrand*' | while read d; do testCover $d || exit; done 54 55 # Upload the coverage profile to coveralls.io 56 [ -n "$COVERALLS_TOKEN" ] && ( goveralls -coverprofile=$ACC_OUT || echo -e '\n\e[31mCoveralls failed.\n' ) 57 58 # Upload to coverage profile to codedov.io 59 [ -n "$CODECOV_TOKEN" ] && ( bash <(curl -s https://codecov.io/bash) || echo -e '\n\e[31mCodecov failed.\n' )