From 74a9ddaa64b2f7adfffe1af31bff7b270e7a615b Mon Sep 17 00:00:00 2001 From: teor Date: Thu, 30 Jun 2022 11:58:29 +1000 Subject: [PATCH] If `docker wait` fails, get the exit code using `docker inspect` --- .github/workflows/deploy-gcp-tests.yml | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/.github/workflows/deploy-gcp-tests.yml b/.github/workflows/deploy-gcp-tests.yml index 602630e0a6a..fedba1361af 100644 --- a/.github/workflows/deploy-gcp-tests.yml +++ b/.github/workflows/deploy-gcp-tests.yml @@ -662,20 +662,28 @@ jobs: # Wait for the container to finish, then exit with the test's exit status. # - # `docker wait` prints the container exit status as a string, but we need to exit `ssh` with that status. - # `docker wait` can also wait for multiple containers, but we only ever wait for a single container. + # If the container has already finished, `docker wait` should return its status. + # But sometimes this doesn't work, so we use `docker inspect` as a fallback. + # + # `docker wait` prints the container exit status as a string, but we need to exit the `ssh` command + # with that status. + # (`docker wait` can also wait for multiple containers, but we only ever wait for a single container.) - name: Result of ${{ inputs.test_id }} test run: | - EXIT_CODE=$(\ gcloud compute ssh \ ${{ inputs.test_id }}-${{ env.GITHUB_REF_SLUG_URL }}-${{ env.GITHUB_SHA_SHORT }} \ --zone ${{ env.ZONE }} \ --quiet \ --ssh-flag="-o ServerAliveInterval=5" \ - --command="docker wait ${{ inputs.test_id }}" \ - ) - echo "$EXIT_CODE" - exit "$EXIT_CODE" + --command=' \ + EXIT_STATUS=$( \ + docker wait ${{ inputs.test_id }} || \ + docker inspect --format "{{.State.ExitCode}}" ${{ inputs.test_id }} || \ + echo "missing container, or missing exit status for container" \ + ); \ + echo "docker exit status: $EXIT_STATUS"; \ + exit "$EXIT_STATUS" \ + ' # create a state image from the instance's state disk, if requested by the caller