Skip to content

Commit

Permalink
🚧 progress: Refactor netcat loop as a composite action.
Browse files Browse the repository at this point in the history
  • Loading branch information
make-github-pseudonymous-again committed Apr 20, 2024
1 parent 1adff2f commit 6a521f3
Show file tree
Hide file tree
Showing 5 changed files with 70 additions and 13 deletions.
52 changes: 52 additions & 0 deletions .github/actions/is-reachable/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
name: is-reachable
description: Checks if a given host is reachable

inputs:

host:
required: true
default: 'localhost'

port:
required: true

timeout:
required: true
default: 5

max-roundtrip:
required: true
default: 5

polling-interval:
required: true
default: 1

protocol:
required: true
default: 'tcp'

ip-version:
required: true
default: 'any'

runs:

using: composite

steps:

- name: Wait for host to be reachable

env:
TIMEOUT: ${{ inputs.timeout }}
MAX_ROUNDTRIP: ${{ inputs.max-roundtrip }}
HOST: ${{ inputs.host }}
PORT: ${{ inputs.port }}
POLLING_INTERVAL: ${{ inputs.polling-interval }}
PROTOCOL_FLAGS: ${{ inputs.protocol == 'udp' && '-u' || '' }}
IP_VERSION_FLAGS: ${{ inputs.ip-version == '4' && '-4' || (inputs.ip-version == '6' && '-6' || '') }}

run: |
timeout "$TIMEOUT" bash -c \
'until nc -z -v -w"${MAX_ROUNDTRIP}" ${IP_VERSION_FLAGS} ${PROTOCOL_FLAGS} "${HOST}" "${PORT}"; do sleep "${POLLING_INTERVAL}"; done'
7 changes: 4 additions & 3 deletions .github/workflows/ci:build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -185,9 +185,10 @@ jobs:
echo "pid=$!" >> "$GITHUB_OUTPUT"
- name: Wait for server port to be available
run: |
timeout 60 bash -c \
'until nc -z -v -w5 localhost 3000 ; do sleep 1; done'
uses: ./.github/actions/is-reachable
with:
timeout: 60
port: 3000

- name: Call healthcheck endpoint
run: |
Expand Down
7 changes: 4 additions & 3 deletions .github/workflows/ci:build:compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -97,9 +97,10 @@ jobs:
'until docker inspect --format "{{json .State.Health }}" "$(docker compose ps -q patient-db)" | jq -e ".Status == \"healthy\"" ; do sleep 1; done'
- name: Wait for web port to be available
run: |
timeout 60 bash -c \
'until nc -z -v -w5 localhost 3000 ; do sleep 1; done'
uses: ./.github/actions/is-reachable
with:
timeout: 60
port: 3000

- name: Wait for web container to be healthy
run: |
Expand Down
10 changes: 6 additions & 4 deletions .github/workflows/ci:build:image.yml
Original file line number Diff line number Diff line change
Expand Up @@ -162,10 +162,12 @@ jobs:
timeout 60 bash -c \
'until docker inspect --format "{{json .State }}" server | jq -e ".Status == \"running\"" ; do sleep 1; done'
- name: Wait for server container 3000 port to be available
run: |
timeout 60 bash -c \
'until nc -z -v -w5 ${{ steps.server-container-ip-address.outputs.address }} 3000 ; do sleep 1; done'
- name: Wait for server container port to be available
uses: ./.github/actions/is-reachable
with:
timeout: 60
host: ${{ steps.server-container-ip-address.outputs.address }}
port: 3000

- name: Show docker containers
if: always()
Expand Down
7 changes: 4 additions & 3 deletions .github/workflows/ci:test:deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,10 @@ jobs:
'until docker inspect --format "{{json .State.Health }}" "$(docker compose ps -q patient-db)" | jq -e ".Status == \"healthy\"" ; do sleep 1; done'
- name: Wait for web port to be available
run: |
timeout 60 bash -c \
'until nc -z -v -w5 localhost 3000 ; do sleep 1; done'
uses: ./.github/actions/is-reachable
with:
timeout: 60
port: 3000

- name: Wait for web container to be healthy
run: |
Expand Down

0 comments on commit 6a521f3

Please sign in to comment.