|
| 1 | +#!/bin/false |
| 2 | +# |
| 3 | +# This file is intended to be sourced, hence the invalid shebang and |
| 4 | +# not being marked as an executable file in git. |
| 5 | + |
| 6 | +# This is from |
| 7 | +# https://github.com/travis-ci/travis-build/blob/master/lib/travis/build/bash/travis_setup_env.bash |
| 8 | +travis_setup_env() { |
| 9 | + export ANSI_RED='\e[31;1m' |
| 10 | + export ANSI_GREEN='\e[32;1m' |
| 11 | + export ANSI_YELLOW='\e[33;1m' |
| 12 | + export ANSI_RESET='\e[0m' |
| 13 | + export ANSI_CLEAR='\e[0K' |
| 14 | +} |
| 15 | + |
| 16 | +# This is from |
| 17 | +# https://github.com/travis-ci/travis-build/blob/master/lib/travis/build/bash/travis_fold.bash |
| 18 | +travis_fold() { |
| 19 | + local action="${1}" |
| 20 | + local name="${2}" |
| 21 | + printf 'travis_fold:%s:%s\r'"${ANSI_CLEAR}" "${action}" "${name}" |
| 22 | +} |
| 23 | + |
| 24 | +# This is modified loop version of |
| 25 | +# https://github.com/travis-ci/travis-build/blob/master/lib/travis/build/bash/travis_retry.bash |
| 26 | +travis_retry() { |
| 27 | + local result=0 |
| 28 | + local count=1 |
| 29 | + local max=5 |
| 30 | + while [ "${count}" -le "${max}" ]; do |
| 31 | + [ "${result}" -ne 0 ] && { |
| 32 | + printf "${ANSI_RED}"'The command "%s" failed. Retrying, %s of %s.'"${ANSI_RESET}"'\n' "${*}" "${count}" "${max}" >&2 |
| 33 | + } |
| 34 | + "${@}" && { result=0 && break; } || result="${?}" |
| 35 | + ((count++)) |
| 36 | + sleep 1 |
| 37 | + done |
| 38 | + |
| 39 | + [ "${count}" -gt "${max}" ] && { |
| 40 | + printf "${ANSI_RED}"'The command "%s" failed %s times.'"${ANSI_RESET}"'\n' "${*}" "${max}" >&2 |
| 41 | + } |
| 42 | + |
| 43 | + return "${result}" |
| 44 | +} |
| 45 | + |
| 46 | +# This is from |
| 47 | +# https://github.com/travis-ci/travis-build/blob/master/lib/travis/build/bash/ |
| 48 | +travis_nanoseconds() { |
| 49 | + local cmd='date' |
| 50 | + local format='+%s%N' |
| 51 | + |
| 52 | + if command -v gdate >/dev/null 2>&1; then |
| 53 | + cmd='gdate' |
| 54 | + elif [ "$(uname)" = Darwin ]; then |
| 55 | + format='+%s000000000' |
| 56 | + fi |
| 57 | + |
| 58 | + "${cmd}" -u "${format}" |
| 59 | +} |
| 60 | + |
| 61 | +travis_time_start() { |
| 62 | + TRAVIS_TIMER_ID="$(printf '%08x' $((RANDOM * RANDOM)))" |
| 63 | + TRAVIS_TIMER_START_TIME="$(travis_nanoseconds)" |
| 64 | + export TRAVIS_TIMER_ID TRAVIS_TIMER_START_TIME |
| 65 | + printf 'travis_time:start:%s\r'"${ANSI_CLEAR}" "${TRAVIS_TIMER_ID}" |
| 66 | +} |
| 67 | + |
| 68 | +travis_time_finish() { |
| 69 | + travis_timer_end_time="$(travis_nanoseconds)" |
| 70 | + local duration="$((travis_timer_end_time - TRAVIS_TIMER_START_TIME))" |
| 71 | + printf '\ntravis_time:end:%s:start=%s,finish=%s,duration=%s\r'"${ANSI_CLEAR}" \ |
| 72 | + "${TRAVIS_TIMER_ID}" "${TRAVIS_TIMER_START_TIME}" \ |
| 73 | + "${travis_timer_end_time}" "${duration}" |
| 74 | +} |
| 75 | + |
| 76 | +travis_do_cmd() { |
| 77 | + echo "$ ${*}" |
| 78 | + "${@}" |
| 79 | + local result="$?" |
| 80 | + export TRAVIS_TEST_RESULT=$((${TRAVIS_TEST_RESULT:-0} | $((result != 0)))) |
| 81 | + |
| 82 | + if [ "${result}" -eq 0 ]; then |
| 83 | + printf '%b' "${ANSI_GREEN}" |
| 84 | + else |
| 85 | + printf '%b' "${ANSI_RED}" |
| 86 | + fi |
| 87 | + printf 'The command "%s" exited with %d.'"${ANSI_RESET}"'\n' "${*}" "${result}" |
| 88 | + return "$result" |
| 89 | +} |
| 90 | + |
| 91 | +travis_setup_env |
| 92 | + |
| 93 | +export -f travis_retry travis_fold travis_time_start travis_time_finish travis_nanoseconds |
0 commit comments