From 85e615798f1c5fe14805476d176ca5d291678b1d Mon Sep 17 00:00:00 2001 From: Heorhii Date: Fri, 26 Jan 2024 08:19:28 +0100 Subject: [PATCH] Refactored --- .github/workflows/test.yml | 57 +++++++++++++++++++++----------------- 1 file changed, 31 insertions(+), 26 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 9b9dbd8f..fa4cafcb 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -19,43 +19,57 @@ jobs: steps: - uses: actions/checkout@v3 - - name: Install PostgreSQL and Redis (on MacOS) + - name: Setup (on MacOS) if: runner.os == 'macOS' run: | + # install and up brew install redis brew services start postgresql brew services start redis - - name: Check services status (on MacOS) - if: runner.os == 'macOS' - run: | + # wait for ready until pg_isready -h localhost -p 5432 && redis-cli ping; do sleep 5; done - - name: Set up PostgreSQL (on MacOS) - if: runner.os == 'macOS' - run: | + # setup db createuser -s postgres cd database bash setup.sh - - name: Setup pg (on Windows) + - name: Setup (on Windows) if: runner.os == 'Windows' run: | + # postgres echo "unix_socket_directories = ''" >> "$PGDATA/postgresql.conf" echo "port = 5432" >> "$PGDATA/postgresql.conf" $PG_BIN = "C:\Program Files\PostgreSQL\14\bin" $env:PATH = "$PG_BIN;$env:PATH" Write-Host "PATH=$env:PATH" + # start and wait pg_ctl start - Start-Sleep -Seconds 15 + # Start-Sleep -Seconds 15 + Start-Sleep -Seconds 5 + $timeout = 60 + $elapsedTime = 0 + while ($elapsedTime -lt $timeout) { + $pgIsReadyResult = & pg_isready -h localhost -p 5432 -U postgres -d postgres -t 1 + if ($pgIsReadyResult -eq 0) { + Write-Host "PostgreSQL is ready" + break + } + Start-Sleep -Seconds 5 + $elapsedTime += 5 + } + if ($elapsedTime -ge $timeout) { + Write-Host "Timeout waiting for PostgreSQL to start." + exit 1 + } + # setup db cd database bash setup.sh - - name: Setup redis (on Windows) - if: runner.os == 'Windows' - run: | + # redis $URL = "https://github.com/redis-windows/redis-windows/releases/download/7.0.14/Redis-7.0.14-Windows-x64-with-Service.tar.gz" $outputFolder = "C:\redis" @@ -69,32 +83,23 @@ jobs: Move-Item -Path "$outputFolder\$($innerFolder.Name)\*" -Destination $outputFolder -Force Remove-Item -Path "$outputFolder\$($innerFolder.Name)" -Force + # start redis cd $outputFolder sc.exe create Redis binpath=C:\redis\RedisService.exe start= auto net start Redis - - name: Start docker containers + - name: Setup (on Linux) if: runner.os == 'Linux' run: | docker-compose -f test-docker-compose.yml up -d pg-example redis-example - - - name: Wait for PostgreSQL to become healthy - if: runner.os == 'Linux' - run: | while [[ "$(docker inspect --format='{{.State.Health.Status}}' pg-example)" != "healthy" ]]; do - echo "Waiting for PostgreSQL container to become healthy..." - sleep 5 + echo "Waiting for PostgreSQL container to become healthy..." + sleep 5 done - timeout-minutes: 5 - - - name: Wait for Redis to become healthy - if: runner.os == 'Linux' - run: | while [[ "$(docker inspect --format='{{.State.Health.Status}}' redis-example)" != "healthy" ]]; do echo "Waiting for Redis container to become healthy..." sleep 5 done - timeout-minutes: 5 - name: Use Node.js ${{ matrix.node }} uses: actions/setup-node@v3 @@ -114,6 +119,6 @@ jobs: env: MODE: test - - name: Stop containers + - name: Stop containers for Linux if: runner.os == 'Linux' run: docker-compose down