Skip to content

Commit

Permalink
Merge pull request #4 from antmicro/override-travis-wait
Browse files Browse the repository at this point in the history
Add KEEP_ALIVE functionality
  • Loading branch information
kowalewskijan authored Jul 7, 2020
2 parents 561f03f + c28fd26 commit 54d5e98
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 3 deletions.
62 changes: 60 additions & 2 deletions common.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,66 @@ export -f travis_nanoseconds
export -f travis_fold
export -f travis_time_start
export -f travis_time_finish
export -f travis_wait
export -f travis_jigger

TRAVIS_MAX_TIME=50

# Override default travis_wait to pipe the output
travis_wait() {
local timeout="${1}"

if [[ "${timeout}" =~ ^[0-9]+$ ]]; then
shift
else
timeout=20
fi

local cmd=("${@}")
local log_file="travis_wait_${$}.log"

"${cmd[@]}" &
local cmd_pid="${!}"

travis_jigger "${!}" "${timeout}" "${cmd[@]}" &
local jigger_pid="${!}"
local result

{
wait "${cmd_pid}" 2>/dev/null
result="${?}"
ps -p"${jigger_pid}" &>/dev/null && kill "${jigger_pid}"
}

if [[ "${result}" -eq 0 ]]; then
printf "\\n${ANSI_GREEN}The command %s exited with ${result}.${ANSI_RESET}\\n" "${cmd[*]}"
else
printf "\\n${ANSI_RED}The command %s exited with ${result}.${ANSI_RESET}\\n" "${cmd[*]}"
fi

echo -e "\\n${ANSI_GREEN}Log:${ANSI_RESET}\\n"

return "${result}"
}

# Override default travis_jigger to print invisible character to keep build alive
travis_jigger() {
local cmd_pid="${1}"
shift
local timeout="${1}"
shift
local count=0

echo -e "\\n"

while [[ "${count}" -lt "${timeout}" ]]; do
count="$((count + 1))"
# print invisible character
echo -ne "\xE2\x80\x8B"
sleep 60
done

echo -e "\\n${ANSI_RED}Timeout (${timeout} minutes) reached. Terminating \"${*}\"${ANSI_RESET}\\n"
kill -9 "${cmd_pid}"
}

if [ $TRAVIS_OS_NAME = 'osx' ]; then
DATE_SWITCH="-r "
Expand Down
6 changes: 5 additions & 1 deletion script.sh
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,11 @@ $SPACER

start_section "conda.build" "${GREEN}Building..${NC}"
if [ $TRAVIS_OS_NAME != 'windows' ]; then
$CONDA_PATH/bin/python $TRAVIS_BUILD_DIR/.travis/.travis-output.py /tmp/output.log conda build $CONDA_BUILD_ARGS
if [ $KEEP_ALIVE = 'true' ]; then
travis_wait $TRAVIS_MAX_TIME $CONDA_PATH/bin/python $TRAVIS_BUILD_DIR/.travis-output.py /tmp/output.log conda build $CONDA_BUILD_ARGS
else
$CONDA_PATH/bin/python $TRAVIS_BUILD_DIR/.travis-output.py /tmp/output.log conda build $CONDA_BUILD_ARGS
fi
else
# Work-around: prevent console output being mangled
winpty.exe -Xallow-non-tty -Xplain conda build $CONDA_BUILD_ARGS 2>&1 | tee /tmp/output.log
Expand Down

0 comments on commit 54d5e98

Please sign in to comment.