From 2b0b2a42927f25578e01bc18873d080f005d807a Mon Sep 17 00:00:00 2001 From: Gustavo Valverde Date: Wed, 20 Sep 2023 19:58:18 +0100 Subject: [PATCH] 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. --- .github/workflows/deploy-gcp-tests.yml | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/.github/workflows/deploy-gcp-tests.yml b/.github/workflows/deploy-gcp-tests.yml index 076ca4b0..b51e6d08 100644 --- a/.github/workflows/deploy-gcp-tests.yml +++ b/.github/workflows/deploy-gcp-tests.yml @@ -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" \ '