intercept.sh 720 B

12345678910111213141516171819202122
  1. #!/usr/bin/env bash
  2. set -e
  3. if [[ (-n $CI || -n $FORCE_INTERCEPT) && -z $NO_INTERCEPT ]]; then
  4. : "${INTERCEPT_OUTPUT:="./intercepted-console-$(date '+%Yy%mm%dd%Hh%Mm%Ss%Nns').log"}"
  5. echo "$0: Intercepting stderr into $INTERCEPT_OUTPUT, along side tee-d stdout."
  6. # we don't care about being racy here as was before; so disable shellcheck
  7. # shellcheck disable=SC2094
  8. if "$@" 2>> "$INTERCEPT_OUTPUT" 1>> >(tee -a "$INTERCEPT_OUTPUT"); then
  9. exit_code=0
  10. else
  11. exit_code=$?
  12. echo "$0: command failed; please see $INTERCEPT_OUTPUT in artifacts"
  13. fi
  14. exit "$exit_code"
  15. else
  16. # revert to noop so that this wrapper isn't so inconvenient to be used deep
  17. # outside CI=1 land (i.e. on laptops)
  18. "$@"
  19. fi