Skip to content
This repository was archived by the owner on Apr 12, 2024. It is now read-only.

Commit 6d2d208

Browse files
committed
chore(travis): add folding to logging output
This folds the output of the logging (karma, sauce-connect etc). Sometimes, an individual log will still be output completely, but overall the logs are folded, which makes it easy to scroll to the bottom of the Travis log and see the last non-log output (e.g. test failures).
1 parent 7166660 commit 6d2d208

File tree

3 files changed

+94
-6
lines changed

3 files changed

+94
-6
lines changed

lib/saucelabs/start_tunnel.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ CONNECT_URL="https://saucelabs.com/downloads/sc-$SC_VERSION-linux.tar.gz"
1616
CONNECT_DIR="/tmp/sauce-connect-$RANDOM"
1717
CONNECT_DOWNLOAD="sc-$SC_VERSION-linux.tar.gz"
1818

19-
CONNECT_LOG="$LOGS_DIR/sauce-connect"
19+
CONNECT_LOG="$LOGS_DIR/sauce-connect.log"
2020
CONNECT_STDOUT="$LOGS_DIR/sauce-connect.stdout"
2121
CONNECT_STDERR="$LOGS_DIR/sauce-connect.stderr"
2222

scripts/travis/_travis_fold.sh

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
# Based on https://github.com/angular/angular/blob/410aa33005f2dc6f6500db71e7f019a744f909d9/scripts/ci/_travis-fold.sh
2+
# private variable to track folds within this script
3+
travisFoldStack=()
4+
5+
function travisFoldStart() {
6+
local foldName="${0#./} ${1}"
7+
# get current time as nanoseconds since the beginning of the epoch
8+
foldStartTime=$(date +%s%N)
9+
# convert all non alphanum chars except for "-" and "." to "--"
10+
local sanitizedFoldName=${foldName//[^[:alnum:]\-\.]/--}
11+
# strip trailing "-"
12+
sanitizedFoldName=${sanitizedFoldName%-}
13+
# push the foldName onto the stack
14+
travisFoldStack+=("${sanitizedFoldName}|${foldStartTime}")
15+
16+
echo ""
17+
if [[ ${TRAVIS:-} ]]; then
18+
echo "travis_fold:start:${sanitizedFoldName}"
19+
echo "travis_time:start:${sanitizedFoldName}"
20+
fi
21+
local enterArrow="===> ${foldName} ==>==>==>==>==>==>==>==>==>==>==>==>==>==>==>==>==>==>==>==>==>==>==>==>==>==>==>==>==>"
22+
# keep all messages consistently wide 80chars regardless of the foldName
23+
echo ${enterArrow:40:100}
24+
# turn on verbose mode so that we have better visibility into what's going on
25+
# http://tldp.org/LDP/Bash-Beginners-Guide/html/sect_02_03.html#table_02_01
26+
set -x
27+
}
28+
29+
function travisFoldEnd() {
30+
set +x
31+
local foldName="${0#./} ${1}"
32+
# convert all non alphanum chars except for "-" and "." to "--"
33+
local sanitizedFoldName=${foldName//[^[:alnum:]\-\.]/--}
34+
# strip trailing "-"
35+
sanitizedFoldName=${sanitizedFoldName%-}
36+
37+
# consult and update travisFoldStack
38+
local lastFoldIndex=$(expr ${#travisFoldStack[@]} - 1)
39+
local lastFoldString=${travisFoldStack[$lastFoldIndex]}
40+
# split the string by | and then turn that into an array
41+
local lastFoldArray=(${lastFoldString//\|/ })
42+
local lastSanitizedFoldName=${lastFoldArray[0]}
43+
44+
if [[ ${TRAVIS:-} ]]; then
45+
local lastFoldStartTime=${lastFoldArray[1]}
46+
local foldFinishTime=$(date +%s%N)
47+
local foldDuration=$(expr ${foldFinishTime} - ${lastFoldStartTime})
48+
fi
49+
50+
# pop
51+
travisFoldStack=(${travisFoldStack[@]:0:lastFoldIndex})
52+
53+
# check for misalignment
54+
if [[ ${lastSanitizedFoldName} != ${sanitizedFoldName} ]]; then
55+
echo "Travis fold mis-alignment detected! travisFoldEnd expected sanitized fold name '${lastSanitizedFoldName}', but received '${sanitizedFoldName}' (after sanitization)"
56+
exit 1
57+
fi
58+
59+
local returnArrow="<=== ${foldName} <==<==<==<==<==<==<==<==<==<==<==<==<==<==<==<==<==<==<==<==<==<==<==<==<==<==<==<==<==<==<==<=="
60+
# keep all messages consistently wide 80chars regardless of the foldName
61+
echo ${returnArrow:40:100}
62+
echo ""
63+
if [[ ${TRAVIS:-} ]]; then
64+
echo "travis_time:end:${sanitizedFoldName}:start=${lastFoldStartTime},finish=${foldFinishTime},duration=${foldDuration}"
65+
echo "travis_fold:end:${sanitizedFoldName}"
66+
fi
67+
}
68+
69+
function travisFoldReturnArrows() {
70+
# print out return arrows so that it's easy to see the end of the script in the log
71+
echo ""
72+
returnArrow="<=== ${0#./} <==<==<==<==<==<==<==<==<==<==<==<==<==<==<==<==<==<==<==<==<==<==<==<==<==<==<==<==<==<==<=="
73+
# keep all messages consistently wide 80chars regardless of the foldName
74+
echo ${returnArrow:40:100}
75+
echo "<==<==<==<==<==<==<==<==<==<==<==<==<==<==<==<==<==<==<==<==<==<==<==<==<==<==<==<==<==<==<==<==<==="
76+
echo ""
77+
}

scripts/travis/print_logs.sh

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,21 @@
22

33
LOG_FILES=$LOGS_DIR/*
44

5+
#!/usr/bin/env bash
6+
7+
set -u -e -o pipefail
8+
9+
# Setup environment
10+
readonly thisDir=$(cd $(dirname $0); pwd)
11+
source ${thisDir}/_travis_fold.sh
12+
13+
514
for FILE in $LOG_FILES; do
6-
echo -e "\n\n\n"
7-
echo "================================================================================"
8-
echo " $FILE"
9-
echo "================================================================================"
10-
cat $FILE
15+
travisFoldStart "print log file: ${FILE}"
16+
cat $FILE
17+
travisFoldEnd "print log file: ${FILE}"
1118
done
19+
20+
21+
# Print return arrows as a log separator
22+
travisFoldReturnArrows

0 commit comments

Comments
 (0)