From 95c64aef60e50b3325c93ad50d42df846706fd35 Mon Sep 17 00:00:00 2001 From: Felipe Fernandes Versiane Date: Thu, 13 Jun 2024 19:56:44 -0300 Subject: [PATCH] fix: trying to fix ci.yml error --- .github/workflows/ci.yaml | 5 ++++- sh/wait-for-it.sh | 32 ++++++++++++++++++++++++++++++++ 2 files changed, 36 insertions(+), 1 deletion(-) create mode 100644 sh/wait-for-it.sh diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 1be41f0..b707d69 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -57,7 +57,10 @@ jobs: - uses: actions/checkout@v3 - name: Set up Docker Compose - run: docker-compose -f docker-compose.ci.yml up -d --build + run: docker-compose -f docker-compose.ci.yml up -d --build --no-cache + + - name: Wait for API to be ready + run: ./sh/wait-for-it.sh localhost:${{ secrets.PORT }} --timeout=60 - name: Run project run: make ci diff --git a/sh/wait-for-it.sh b/sh/wait-for-it.sh new file mode 100644 index 0000000..93223ef --- /dev/null +++ b/sh/wait-for-it.sh @@ -0,0 +1,32 @@ +#!/usr/bin/env bash +# Use this script to wait for a service to become available + +TIMEOUT=15 +while getopts t: option +do + case "${option}" + in + t) TIMEOUT=${OPTARG};; + esac +done + +shift $((OPTIND -1)) +HOST=$1 +PORT=$2 + +if [ -z "$HOST" ] || [ -z "$PORT" ]; then + echo "Usage: $0 host port [-t timeout]" + exit 1 +fi + +for i in `seq $TIMEOUT` ; do + nc -z $HOST $PORT > /dev/null 2>&1 + result=$? + if [ $result -eq 0 ] ; then + exit 0 + fi + sleep 1 +done + +echo "Timeout: Unable to connect to $HOST:$PORT" +exit 1