github.com/wfusion/gofusion@v1.1.14/test/ci-linux.sh (about) 1 #!/usr/bin/env bash 2 3 set -ex 4 5 # project path 6 APP="gofusion" 7 WORKDIR=$(cd $(dirname "$0") || exit; pwd) 8 WORKDIR=${WORKDIR%"$APP"*}$APP 9 cd "${WORKDIR}" || exit 10 OUTPUT_DIR="${WORKDIR}"/assets 11 OUTPUT="${OUTPUT_DIR}"/unittest 12 mkdir -p "${OUTPUT}" 13 touch "${OUTPUT}"/coverage.out 14 15 # dep install 16 go install gotest.tools/gotestsum@latest 17 go install github.com/axw/gocov/gocov@latest 18 go install github.com/matm/gocov-html/cmd/gocov-html@latest 19 if ! type -p java; then 20 if [ -f /etc/centos-release ] || [ -f /etc/system-release ]; then 21 yum update -y 22 yum install -y wget python3 glibc-langpack-en 23 elif [ -f /etc/lsb-release ] || [ -f /etc/debian_version ]; then 24 apt update 25 apt install default-jdk -y 26 fi 27 fi 28 29 if ! type -p allure; then 30 ALLURE_VERSION=2.24.1 31 wget https://repo1.maven.org/maven2/io/qameta/allure/allure-commandline/${ALLURE_VERSION}/allure-commandline-${ALLURE_VERSION}.zip 32 unzip allure-commandline-${ALLURE_VERSION}.zip -d /opt/ 33 mv /opt/allure-${ALLURE_VERSION} /opt/allure 34 rm allure-commandline-${ALLURE_VERSION}.zip 35 echo "export PATH=$PATH:/opt/allure/bin" >> ~/.bashrc 36 source ~/.bashrc 37 if test -f ~/.zshrc; then 38 echo "export PATH=$PATH:/opt/allure/bin" >> ~/.zshrc 39 fi 40 fi 41 if ! type -p allure-combine; then 42 pip install allure-combine 43 fi 44 45 # env 46 export LANG=en_US.UTF-8 47 export LC_ALL=en_US.UTF-8 48 export JAVA_TOOL_OPTIONS='-Dfile.encoding="UTF-8" -Dsun.jnu.encoding="UTF-8"' 49 GOBIN=$(go env GOPATH)/bin 50 51 # run test 52 COVER_PKG=$(find -type d -printf '%P\n' | egrep -v '^$|^.git/*|^test/*|^assets/*|^.idea/*|^common/fus/*|^common/infra/drivers/orm/opengauss/*|^common/infra/drivers/orm/sqlite/*|^common/infra/asynq/*|^common/infra/metrics/*|^common/infra/watermill/*|^common/infra/rotatelog/*|^common/utils/gomonkey/*|^common/utils/sqlparser/*' | awk '{print "github.com/wfusion/gofusion/" $0}' | sed ':a;N;$!ba;s/\n/,/g') 53 "${GOBIN}"/gotestsum --junitfile "${OUTPUT}"/junit.xml -- -timeout 30m -parallel 1 ./test/... -coverpkg="${COVER_PKG}" -coverprofile="${OUTPUT}"/coverage.out -covermode count || true 54 55 # export test report 56 echo "export complete.xml" 57 /opt/allure/bin/allure generate "${OUTPUT}" -o "${OUTPUT}"/allure --clean 58 while [ ! -d "${OUTPUT}"/allure ]; do 59 sleep 1 60 done 61 allure-combine --remove-temp-files --ignore-utf8-errors "${OUTPUT}"/allure --dest "${OUTPUT}" 62 "${GOBIN}"/minify -r -o "${OUTPUT}"/unittest.html "${OUTPUT}"/complete.html || true 63 64 # export test coverage report 65 echo "export coverage.html" 66 "${GOBIN}"/gocov convert "${OUTPUT}"/coverage.out > "${OUTPUT}"/coverage.json 67 "${GOBIN}"/gocov-html < "${OUTPUT}"/coverage.json > "${OUTPUT}"/gocov.html 68 "${GOBIN}"/minify -r -o "${OUTPUT}"/coverage.html "${OUTPUT}"/gocov.html || true 69 70 echo "export coverage.svg" 71 "${GOBIN}"/go-cover-treemap -coverprofile "${OUTPUT}"/coverage.out -only-folders > "${OUTPUT}"/coverage.svg 72 73 # remove temps 74 rm "${OUTPUT}"/coverage.out "${OUTPUT}"/coverage.json "${OUTPUT}"/junit.xml "${OUTPUT}"/complete.html "${OUTPUT}"/gocov.html 75 rm -rf "${OUTPUT}"/allure