|
| 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 | +} |
0 commit comments