Skip to content

Instantly share code, notes, and snippets.

@timbertson
Last active June 23, 2018 10:27
Show Gist options
  • Save timbertson/b619802d795c270f80886cee8efd4191 to your computer and use it in GitHub Desktop.
Save timbertson/b619802d795c270f80886cee8efd4191 to your computer and use it in GitHub Desktop.
#!/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