Last active
September 13, 2021 22:10
-
-
Save prisis/e050c4da44c6ee7fa1519912eac19563 to your computer and use it in GitHub Desktop.
tfold is a helper to create folded reports on travis
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
# How to use: | |
# | |
# And add it to your bash file | |
# source ./tfold.sh | |
# | |
# tfold "fold name" "command to execute" | |
nanoseconds() { | |
local cmd="date" | |
local format="+%s%N" | |
local os=$(uname) | |
if hash gdate > /dev/null 2>&1; then | |
cmd="gdate" | |
elif [[ "$os" = Darwin ]]; then | |
format="+%s000000000" | |
fi | |
$cmd -u $format | |
} | |
# Arguments: | |
# $1 fold name | |
# $2 command to execute | |
tfold () { | |
local title=$1 | |
local fold=$(echo "$title" | sed -r 's/[^-_A-Za-z\d]+/./g') | |
shift | |
local id=$(printf %08x $(( RANDOM * RANDOM ))) | |
local start=$(nanoseconds) | |
echo -e "travis_fold:start:$fold" | |
echo -e "travis_time:start:$id" | |
echo -e "\\e[1;34m$title\\e[0m" | |
bash -xc "$*" 2>&1 | |
local ok=$? | |
local end=$(nanoseconds) | |
echo -e "\\ntravis_time:end:$id:start=$start,finish=$end,duration=$(($end-$start))" | |
(exit $ok) && | |
echo -e "\\e[32mOK\\e[0m $title\\n\\ntravis_fold:end:$fold" || | |
echo -e "\\e[41mKO\\e[0m $title\\n" | |
(exit $ok) | |
} | |
export -f nanoseconds; | |
export -f tfold; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Download it with:
wget https://gistcdn.githack.com/prisis/e050c4da44c6ee7fa1519912eac19563/raw/7a72a7df7718af30e703c1ef0379cdf7ff24ce10/tfold.sh