Repository navigation
193 lines (179 loc) · 6.36 KB
/
Copy pathrun-tests.yml
File metadata and controls
193 lines (179 loc) · 6.36 KB
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
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
name: Run tests on pull request
on:
pull_request:
branches:
- main
jobs:
prepare:
name: Prepare changes
runs-on: ubuntu-latest
permissions:
contents: read
pull-requests: read
outputs:
client: ${{ steps.changes.outputs.client }}
server: ${{ steps.changes.outputs.server }}
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
submodules: recursive
- name: Filter changes
uses: dorny/paths-filter@v2
id: changes
with:
filters: |
client:
- 'client/**'
server:
- 'server/**'
server-tests:
name: Run server tests
runs-on: ubuntu-latest
needs: prepare
if: ${{ needs.prepare.outputs.server == 'true' }}
defaults:
run:
working-directory: ./server
steps:
- uses: actions/checkout@v4
with:
submodules: recursive
- uses: actions/setup-node@v4
with:
node-version: '20'
cache: 'yarn'
cache-dependency-path: server/yarn.lock
- run: yarn
- run: yarn test
- run: yarn test:e2e
client-tests:
name: Run client tests
runs-on: ubuntu-latest
needs: prepare
if: ${{ needs.prepare.outputs.client == 'true' }}
defaults:
run:
working-directory: ./client
steps:
- uses: actions/checkout@v4
with:
submodules: recursive
- uses: actions/setup-node@v4
with:
node-version: '20'
cache: 'yarn'
cache-dependency-path: client/yarn.lock
- run: yarn
- run: yarn test
env:
# entities.test.js renders the full admin app ~140 times in one
# process (every resource's List/Create/Edit page); the default
# heap limit is tight enough on CI runners that later tests in the
# same run degrade/fail from GC pressure even though they pass
# fine in isolation.
NODE_OPTIONS: --max-old-space-size=4096
e2e-tests:
name: Run browser E2E tests
runs-on: ubuntu-latest
needs: prepare
if: ${{ needs.prepare.outputs.client == 'true' || needs.prepare.outputs.server == 'true' }}
services:
mysql:
image: mysql:8.4
env:
MYSQL_ROOT_PASSWORD: root
MYSQL_DATABASE: mysql_database
ports:
- 3306:3306
options: >-
--health-cmd="mysqladmin ping -proot"
--health-interval=10s
--health-timeout=5s
--health-retries=10
env:
MYSQL_HOST: 127.0.0.1
MYSQL_PORT: 3306
MYSQL_USER: mysql_user
MYSQL_PASSWORD: mysql_password
MYSQL_DATABASE: mysql_database
JWT_SECRET: jwt_secret
steps:
- uses: actions/checkout@v4
with:
submodules: recursive
- uses: actions/setup-node@v4
with:
node-version: '20'
# data.sql (the run-without-docker checkpoint dump) both creates the
# schema/seed data and grants mysql_user its privileges, but assumes
# the account itself already exists — the docker-based setup creates
# it via the image's own MYSQL_USER/MYSQL_PASSWORD env vars, which the
# plain `mysql:` service image doesn't expose the same way.
- name: Set up database
run: |
mysql -h127.0.0.1 -uroot -proot -e "
CREATE USER IF NOT EXISTS 'mysql_user'@'%' IDENTIFIED BY 'mysql_password';
GRANT ALL PRIVILEGES ON mysql_database.* TO 'mysql_user'@'%';
FLUSH PRIVILEGES;
"
mysql -h127.0.0.1 -uroot -proot mysql_database < db/data.sql
- name: Install server deps, run pending migrations
working-directory: ./server
run: |
yarn
NODE_ENV=development yarn typeorm:run
# Backgrounded within this step, with the wait loop right after it in
# the same step: the workflow can't move on to the next step until
# this one is confirmed answering requests — a later step starting
# before this one is truly ready would just fail on connection-refused
# instead of waiting for it.
- name: Start server
working-directory: ./server
run: |
NODE_ENV=development PORT=3001 yarn start:dev > /tmp/server.log 2>&1 &
ready=false
for i in $(seq 1 60); do
# Any HTTP response (even a 400 from an empty body) means the
# server is up; curl's own exit code only tells us the TCP
# connection was refused or not. GitHub Actions runs this script
# under `bash -e`, and `code=$(curl ...)` is a plain assignment
# (not exempt the way `curl ... && break` is) — so on the very
# first, expected-to-fail attempt curl's connection-refused exit
# code aborted the whole step before the retry loop ran at all.
# `|| true` neutralizes that; emptiness is still checked below.
code=$(curl -s -o /dev/null -w "%{http_code}" -X POST http://localhost:3001/auth/register -H "Content-Type: application/json" -d '{}' || true)
if [ -n "$code" ] && [ "$code" != "000" ]; then ready=true; break; fi
sleep 1
done
if [ "$ready" != "true" ]; then
echo "Server did not become ready:"; cat /tmp/server.log; exit 1
fi
- name: Install client deps, start client
working-directory: ./client
run: |
yarn
yarn start > /tmp/client.log 2>&1 &
for i in $(seq 1 60); do
curl -sf -o /dev/null http://localhost:3000 && break
sleep 1
done
curl -sf -o /dev/null http://localhost:3000 || (echo "Client did not become ready:"; cat /tmp/client.log; exit 1)
- name: Install E2E deps
working-directory: ./e2e
run: |
yarn
# playwright.config.ts prefers a pre-installed Chromium at
# $PLAYWRIGHT_CHROMIUM_PATH (present in some dev sandboxes) but
# falls back to Playwright's own managed browser when that path
# doesn't exist — which is always the case on this runner.
npx playwright install --with-deps chromium
- name: Run E2E tests
working-directory: ./e2e
run: yarn test
- uses: actions/upload-artifact@v4
if: failure()
with:
name: playwright-report
path: e2e/test-results/
retention-days: 7