From 011321810296066d4415a50a5a655de1dc626953 Mon Sep 17 00:00:00 2001 From: make-github-pseudonymous-again <5165674+make-github-pseudonymous-again@users.noreply.github.com> Date: Sat, 20 Apr 2024 18:39:53 +0200 Subject: [PATCH] :recycle: refactor: Refactor `.State` loop as composite action. --- .github/actions/is-running/action.yml | 35 +++++++++++++++++++++++++++ .github/workflows/ci:build:image.yml | 10 +++++--- 2 files changed, 41 insertions(+), 4 deletions(-) create mode 100644 .github/actions/is-running/action.yml diff --git a/.github/actions/is-running/action.yml b/.github/actions/is-running/action.yml new file mode 100644 index 000000000..b603c1a18 --- /dev/null +++ b/.github/actions/is-running/action.yml @@ -0,0 +1,35 @@ +name: is-running +description: > + Checks if a given container is running. + +inputs: + + container: + required: true + + timeout: + required: true + default: 30 + + polling-interval: + required: true + default: 1 + +runs: + + using: composite + + steps: + + - name: Wait for container to be healthy + + env: + NAME_OR_ID: ${{ inputs.container }} + TIMEOUT: ${{ inputs.timeout }} + POLLING_INTERVAL: ${{ inputs.polling-interval }} + + shell: bash + + run: | + timeout "${TIMEOUT}" bash -c \ + 'until docker inspect --format "{{json .State }}" "${NAME_OR_ID}" | jq -e ".Status == \"running\"" ; do sleep "${POLLING_INTERVAL}"; done' diff --git a/.github/workflows/ci:build:image.yml b/.github/workflows/ci:build:image.yml index a72d50904..76162129f 100644 --- a/.github/workflows/ci:build:image.yml +++ b/.github/workflows/ci:build:image.yml @@ -87,6 +87,7 @@ jobs: scripts/assert-replica-set.js .github/actions/is-healthy/action.yml .github/actions/is-reachable/action.yml + .github/actions/is-running/action.yml sparse-checkout-cone-mode: false - name: Get server image URL @@ -160,10 +161,11 @@ jobs: "address=$(docker container inspect --format '{{ range.NetworkSettings.Networks }}{{ .IPAddress }}{{ end }}' server)" \ >> "$GITHUB_OUTPUT" - - name: Wait for server container to be running - run: | - timeout 60 bash -c \ - 'until docker inspect --format "{{json .State }}" server | jq -e ".Status == \"running\"" ; do sleep 1; done' + - name: Wait for container to be running + uses: ./.github/actions/is-running + with: + container: server + timeout: 60 - name: Wait for server container port to be available uses: ./.github/actions/is-reachable