Skip to content

Update testing infrastructure #158

Update testing infrastructure

Update testing infrastructure #158

Workflow file for this run

name: Testing CI
on: pull_request
jobs:
build:
runs-on: ${{ matrix.os }}
strategy:
matrix:
node:
- 18
- 20
os:
- ubuntu-latest
- windows-latest
- macos-latest
steps:
- uses: actions/checkout@v4
- name: Setup (on MacOS)
if: runner.os == 'macOS'
run: |
# install and up
brew install redis
brew services start postgresql
brew services start redis
# wait for ready
until pg_isready -h localhost -p 5432 && redis-cli ping; do sleep 5; done
# setup db
createuser -s postgres
cd database
bash setup.sh
- 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"
# start and wait
pg_ctl start
$timeout = 120
$elapsedTime = 0
Write-Host "Waiting for PostgreSQL to start"
while ($elapsedTime -lt $timeout) {
$pgIsReadyResult = & $PG_BIN\pg_isready.exe -h localhost -p 5432 -t 1
if ($pgIsReadyResult -eq "localhost:5432 - accepting connections") {
Write-Host "PostgreSQL is ready"
break
}
Start-Sleep -Seconds 5
$elapsedTime += 5
}
# setup db
cd database
bash setup.sh
# 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"
if (-not (Test-Path $outputFolder)) {
New-Item -ItemType Directory -Path $outputFolder | Out-Null
}
Invoke-WebRequest -Uri $URL -OutFile "redis.tar.gz"
tar -xf "redis.tar.gz" -C $outputFolder
$innerFolder = Get-ChildItem -Path $outputFolder | Select-Object -First 1
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
# wait for redis
Write-Host "Waiting for Redis to start"
while ($elapsedTime -lt $timeout) {
$redisPingResult = & C:\redis\redis-cli.exe ping
echo $redisPingResult
if ($redisPingResult -eq "PONG") {
Write-Host "Redis is ready"
break
}
Start-Sleep -Seconds 5
$elapsedTime += 5
}
if ($elapsedTime -ge $timeout) {
Write-Host "Timeout waiting for services to start."
exit 1
}
Write-Host "Services are ready"
- name: Setup (on Linux)
if: runner.os == 'Linux'
run: |
docker-compose -f test-docker-compose.yml up -d pg-example redis-example
while [[ "$(docker inspect --format='{{.State.Health.Status}}' pg-example)" != "healthy" ]]; do
echo "Waiting for PostgreSQL container to become healthy..."
sleep 5
done
while [[ "$(docker inspect --format='{{.State.Health.Status}}' redis-example)" != "healthy" ]]; do
echo "Waiting for Redis container to become healthy..."
sleep 5
done
- name: Use Node.js ${{ matrix.node }}
uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node }}
- uses: actions/cache@v4
with:
path: ~/.npm
key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }}
restore-keys: |
${{ runner.os }}-node-
- run: npm ci
- run: npm run dotest
env:
MODE: test
- name: Stop containers for Linux
if: runner.os == 'Linux'
run: docker-compose down