diff --git a/misc/make-deps.sh b/misc/make-deps.sh index 03cc7c3e..9d8ff40d 100755 --- a/misc/make-deps.sh +++ b/misc/make-deps.sh @@ -4,10 +4,7 @@ XPWD=`pwd` ROOT="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && cd .. && pwd )" # dir! cd "${ROOT}" >/dev/null -travis=0 -if env | grep -q '^TRAVIS=true$'; then - travis=1 -fi +. ${ROOT}/test/util.sh sudo_command=$(command -v sudo) @@ -81,7 +78,7 @@ if [ ! -z "$PACMAN" ]; then $sudo_command $PACMAN -S --noconfirm --asdeps --needed libvirt augeas rubygems libpcap fi -if [ $travis -eq 0 ]; then +if ! in_ci; then if [ ! -z "$YUM" ]; then if [ -z "$GO" ]; then $sudo_command $YUM install -y golang golang-googlecode-tools-stringer || $sudo_command $YUM install -y golang-bin # centos-7 epel @@ -132,8 +129,10 @@ go get golang.org/x/lint/golint # for `golint`-ing go get golang.org/x/tools/cmd/goimports # for fmt go get github.com/tmthrgd/go-bindata/go-bindata # for compiling in non golang files go get github.com/dvyukov/go-fuzz/go-fuzz # for fuzzing the mcl lang bits -if env | grep -q -e '^TRAVIS=true$' -e '^JENKINS_URL=' -e '^BUILD_TAG=jenkins'; then - go get -u gopkg.in/alecthomas/gometalinter.v1 && mv "$(dirname $(command -v gometalinter.v1))/gometalinter.v1" "$(dirname $(command -v gometalinter.v1))/gometalinter" && gometalinter --install # bonus +if in_ci; then + go get -u gopkg.in/alecthomas/gometalinter.v1 && \ + mv "$(dirname $(command -v gometalinter.v1))/gometalinter.v1" "$(dirname $(command -v gometalinter.v1))/gometalinter" && \ + gometalinter --install # bonus fi command -v mdl &>/dev/null || gem install mdl --no-document || true # for linting markdown files command -v fpm &>/dev/null || gem install fpm --no-document || true # for cross distro packaging diff --git a/test.sh b/test.sh index 69c86166..4e91fc29 100755 --- a/test.sh +++ b/test.sh @@ -76,8 +76,7 @@ fi # run-test ./test/test-crossbuild.sh # do these longer tests only when running on ci -if env | grep -q -e '^TRAVIS=true$' -e '^JENKINS_URL=' -e '^BUILD_TAG=jenkins'; then - +if in_ci; then if label-block "shell"; then run-testsuite ./test/test-shell.sh fi diff --git a/test/shell/net.sh b/test/shell/net.sh index d95ec2cc..22d515bd 100755 --- a/test/shell/net.sh +++ b/test/shell/net.sh @@ -2,7 +2,7 @@ . "$(dirname "$0")/../util.sh" -if env | grep -q -e '^TRAVIS=true$'; then +if in_ci travis; then # this often fails in travis with: `address already in use` echo "Travis gives wonky results here, skipping test!" exit diff --git a/test/shell/t3.sh b/test/shell/t3.sh index b7734f11..f4f73bec 100755 --- a/test/shell/t3.sh +++ b/test/shell/t3.sh @@ -2,7 +2,7 @@ . "$(dirname "$0")/../util.sh" -if env | grep -q -e '^TRAVIS=true$'; then +if in_ci travis jenkins; then # inotify doesn't seem to work properly on travis echo "Travis and Jenkins give wonky results here, skipping test!" exit diff --git a/test/shell/yaml-change1.sh b/test/shell/yaml-change1.sh index 93299e46..9c206985 100755 --- a/test/shell/yaml-change1.sh +++ b/test/shell/yaml-change1.sh @@ -4,7 +4,7 @@ exit 0 # TODO: this test needs to be update to use deploys instead -#if env | grep -q -e '^TRAVIS=true$'; then +#if in_ci; then # # inotify doesn't seem to work properly on travis # echo "Travis and Jenkins give wonky results here, skipping test!" # exit diff --git a/test/test-gotest.sh b/test/test-gotest.sh index dfbab47c..b9eccae7 100755 --- a/test/test-gotest.sh +++ b/test/test-gotest.sh @@ -8,7 +8,7 @@ cd "${ROOT}" . test/util.sh # travis is slow for some reason -if env | grep -q -e '^TRAVIS=true$'; then +if in_ci travis; then export GO_TEST_TIMEOUT_SCALE=3 fi diff --git a/test/test-yamlfmt.sh b/test/test-yamlfmt.sh index 83923412..d285fb4e 100755 --- a/test/test-yamlfmt.sh +++ b/test/test-yamlfmt.sh @@ -13,7 +13,7 @@ ROOT=$(dirname "${BASH_SOURCE}")/.. cd "${ROOT}" . test/util.sh -#if env | grep -q -e '^TRAVIS=true$' -e '^JENKINS_URL=' -e '^BUILD_TAG=jenkins'; then +#if in_ci travis jenkins; then # echo "Travis and Jenkins give wonky results here, skipping test!" # exit 0 #fi diff --git a/test/util.sh b/test/util.sh index e4613172..3e026a5f 100755 --- a/test/util.sh +++ b/test/util.sh @@ -20,26 +20,43 @@ fi TIMEOUT="$timeout --kill-after=360s --signal=QUIT 300s" -fail_test() -{ +in_ci() { + if [ $# -eq 0 ]; then + test -n "$CI" -o -n "$TRAVIS" -o -n "$JENKINS_URL" + return $? + fi + + for var in "$@"; do + case "$var" in + travis) + test "$TRAVIS" = "true" && return 0;; + jenkins) + test -n "$JENKINS_URL" && return 0;; + *) + continue;; + esac + done + return 1 +} + +fail_test() { echo -e "FAIL: $@" exit 1 } -function run-test() -{ +function run-test() { "$@" || failures=$( [ -n "$failures" ] && echo "$failures\\n$@" || echo "$@" ) } # travis expander helpers from: # https://github.com/travis-ci/travis-rubies/blob/build/build.sh fold_start() { - if env | grep -q -e '^TRAVIS=true$'; then - echo -e "travis_fold:start:$1\033[33;1m$2\033[0m" + if in_ci travis; then + echo -e "travis_fold:start:$1\033[33;1m${@:2}\033[0m" fi } fold_end() { - if env | grep -q -e '^TRAVIS=true$'; then + if in_ci travis; then echo -e "\ntravis_fold:end:$1\r" fi }