I am working on an automated pull request check via GitHub actions and I want to preserve some data from a command's stderr
output between jobs.
For this, I need to write the stderr
to an artifact file, but before that I need to also remove some control chars from it via sed
, otherwise I end up with something like:
\x1b[31mFound 344 errors!\x1b[39;49m
I then want the main command to return the same exit code in order to fail the check and prevent merging of the pull request.
I can probably take care of a subset of what needs doing, but am unable to take care of all 3 together together (sed > file write > stderr). If it makes it easier, I am okay with writing both stdout
and stderr
to the file as well.
Open to suggestions to do this differently.
tee
:somecommand 2&>1 | tee ./artifact.txt
. However, doing so loses the original exit status. – Abhishek Jain Nov 28 '20 at 18:56pipefail
shell option which essentially solves my problem. The final command being:set -o pipefail ; somecommand 2&>1 | tee ./artifact.txt
; set +o pipefail` – Abhishek Jain Nov 28 '20 at 18:58Fortunately I have been able to (mostly) solve it. Hopefully, the answer I posted will bring more context to you guys :)
– Abhishek Jain Nov 28 '20 at 19:40git
output thgough ased
, which indicates that you use a specific configuration for that characters to survive a pipe pass (like color "always" and not just "auto"). – thanasisp Nov 29 '20 at 00:12