Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
#!/bin/bash
set -eu
output="/tmp/$$.log"
idx=0
touch "$output"
NTH_LINE="${NTH_LINE:-100}"
ERROR_LINES="${ERROR_LINES:-200}"
function cleanup () {
rm -f "$output"
}
trap cleanup EXIT
echo 'travis_fold:start:output-stream'
echo "+ $@ # showing every ${NTH_LINE}th line"
"$@" 2>&1 | tee "$output" | while read line; do
idx=$((idx+1))
if [ $(($idx % $NTH_LINE)) -eq 0 ]; then
echo "... # $line"
fi
done
status="${PIPESTATUS[0]}"
echo 'travis_fold:end:output-stream'
echo ""
if [ "$status" -eq 0 ]; then
echo "# Success"
else
echo "# Exited with status $status. Showing the last $ERROR_LINES lines of output:"
tail -n "$ERROR_LINES" "$output"
exit "$status"
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.