fix(ci): handle `tee` trying to write to a closed pipe (#7580)

Use `trap '' PIPE` as a command in the pipeline might exit early and we want the script to continue executing, as using `grep --max-count=1` might exit after finding the first match, causing a broken pipe error with `tee`.

This is being combined with  `set -o pipefail` to have strict error handling and we want the script to fail if any command in the pipeline fails.
This commit is contained in:
Gustavo Valverde 2023-09-20 19:58:18 +01:00 committed by GitHub
parent dbdb4be429
commit 2b0b2a4292
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 5 additions and 0 deletions

View File

@ -592,6 +592,9 @@ jobs:
--ssh-flag="-o ConnectTimeout=5" \
--command=' \
set -e;
set -o pipefail;
trap '' PIPE;
sudo docker logs \
--tail all \
--follow \
@ -599,11 +602,13 @@ jobs:
tee --output-error=exit /dev/stderr | \
grep --max-count=1 --extended-regexp --color=always \
"test result: .*ok.* [1-9][0-9]* passed.*finished in"; \
EXIT_STATUS=$( \
sudo docker wait ${{ inputs.test_id }} || \
sudo docker inspect --format "{{.State.ExitCode}}" ${{ inputs.test_id }} || \
echo "missing container, or missing exit status for container" \
); \
echo "sudo docker exit status: $EXIT_STATUS"; \
exit "$EXIT_STATUS" \
'