test: Add in_ci utility test function

in_ci checks for environment variables set by a selection of CI systems
and returns true if the test appears to be running in CI. Additionally
it can test for specific CI systems, and returns true if the CI system
is listed.

Deduplicate existing environment checks for Travis and Jenkins.

Signed-off-by: Joe Groocock <me@frebib.net>
This commit is contained in:
Joe Groocock
2021-02-12 14:40:47 +00:00
parent 6a61774fb7
commit 5af1dcb8b1
8 changed files with 36 additions and 21 deletions

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -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
}