forked from metarhia/Example
-
Notifications
You must be signed in to change notification settings - Fork 0
142 lines (117 loc) · 4.55 KB
/
test-macos.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
name: Testing CI
on:
- pull_request
- push
jobs:
build:
runs-on: ${{ matrix.os }}
strategy:
matrix:
node:
- 18
- 20
os:
# - ubuntu-latest
# - windows-latest
- macos-latest
steps:
- uses: actions/checkout@v3
- name: Setup docker (missing on MacOS)
if: runner.os == 'macos'
run: |
# brew install docker
# brew install docker-compose
# mkdir -p ~/.docker/cli-plugins
# ln -sfn /usr/local/opt/docker-compose/bin/docker-compose ~/.docker/cli-plugins/docker-compose
# colima start
# # For testcontainers to find the Colima socket
# # https://github.com/abiosoft/colima/blob/main/docs/FAQ.md#cannot-connect-to-the-docker-daemon-at-unixvarrundockersock-is-the-docker-daemon-running
# sudo ln -sf $HOME/.colima/default/docker.sock /var/run/docker.
- name: Install PostgreSQL and Redis (on MacOS)
if: runner.os == 'macos'
run: |
# brew install postgresql
brew install redis
sudo su postgres initdb --locale=C -E UTF-8 /opt/homebrew/var/postgresql@14
brew services start postgresql
brew services start redis
- name: Check services status (on MacOS)
if: runner.os == 'macos'
run: |
# until brew services list | grep -E 'postgresql[[:space:]]+started' && brew services list | grep -E 'redis[[:space:]]+started'; do sleep 5; done
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: |
cd database
bash setup.sh
- name: Setup pg (on Windows)
if: runner.os == 'windows'
run: |
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"
pg_ctl start
Start-Sleep -Seconds 15
cd database
bash setup.sh
- name: Setup redis (on Windows)
if: runner.os == 'windows'
run: |
$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
$REDIS_PATH=$outputFolder
Write-Host "REDIS_PATH=$REDIS_PATH"
cd $REDIS_PATH
dir
sc.exe create Redis binpath=C:\redis\RedisService.exe start= auto
net start Redis
- name: Start docker containers
if: runner.os == 'ubuntu'
run: |
docker-compose -f test-docker-compose.yml up -d pg-example redis-example
# sleep 15 # wait for database to be ready
# docker ps
- name: Wait for PostgreSQL to become healthy
if: runner.os == 'ubuntu'
run: |
while [[ "$(docker inspect --format='{{.State.Health.Status}}' pg-example)" != "healthy" ]]; do
echo "Waiting for PostgreSQL container to become healthy..."
sleep 5
done
timeout-minutes: 5
- name: Wait for Redis to become healthy
if: runner.os == 'ubuntu'
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
with:
node-version: ${{ matrix.node }}
- uses: actions/cache@v3
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
if: runner.os == 'ubuntu'
run: docker-compose down