-
Notifications
You must be signed in to change notification settings - Fork 0
282 lines (255 loc) · 8.32 KB
/
ci.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
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
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
name: CI
on:
workflow_dispatch:
pull_request:
push:
branches:
- main
concurrency:
group: ${{ github.workflow }}-${{ github.ref || github.run_id }}
cancel-in-progress: true
env:
NODE_OPTIONS: "--max-old-space-size=6144"
NODE_ENV: test
NODE_MODULES_PATHS: |
node_modules
packages/*/node_modules
!packages/mobile/node_modules
jobs:
node_modules_cache:
name: Cache node modules
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: 20.x
cache: yarn
- uses: actions/cache/restore@v3
with:
key: ${{ runner.os }}-yarn-${{ hashFiles('yarn.lock') }}
path: ${{ env.NODE_MODULES_PATHS }}
- run: yarn
- uses: actions/cache/save@v3
with:
key: ${{ runner.os }}-yarn-${{ hashFiles('yarn.lock') }}
path: ${{ env.NODE_MODULES_PATHS }}
test:
needs: node_modules_cache
strategy:
fail-fast: false
matrix:
include:
- { package: "@tamanu/facility-server", shard: 1/4, postgres: 14 }
- { package: "@tamanu/facility-server", shard: 2/4, postgres: 14 }
- { package: "@tamanu/facility-server", shard: 3/4, postgres: 14 }
- { package: "@tamanu/facility-server", shard: 4/4, postgres: 14 }
- { package: "@tamanu/central-server", shard: 1/4, postgres: 14 }
- { package: "@tamanu/central-server", shard: 2/4, postgres: 14 }
- { package: "@tamanu/central-server", shard: 3/4, postgres: 14 }
- { package: "@tamanu/central-server", shard: 4/4, postgres: 14 }
- { package: "@tamanu/meta-server" }
- { package: "@tamanu/shared", postgres: 12 }
- { package: "@tamanu/shared", postgres: 14 }
- { package: "@tamanu/shared", postgres: 16 }
- { package: "@tamanu/web-frontend" }
name: Test ${{ matrix.package }} ${{ matrix.shard }} (pg=${{ matrix.postgres || 'no' }})
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: 20.x
cache: yarn
- uses: actions/cache/restore@v3
with:
key: ${{ runner.os }}-yarn-${{ hashFiles('yarn.lock') }}
path: ${{ env.NODE_MODULES_PATHS }}
- run: yarn
- run: yarn build-shared
- run: yarn workspace ${{ matrix.package }} run build
- name: Install and start postgres if needed
if: matrix.postgres
run: |
source .github/scripts/install-postgres-ubuntu.sh ${{ matrix.postgres }}
.github/scripts/setup-postgres-for-one-package.sh ${{ matrix.package }}
- name: Run tests
env:
package: ${{ matrix.package }}
shard: ${{ matrix.shard }}
run: |
[[ -z "$shard" ]] || shard="--shard $shard"
yarn workspace "$package" run test $shard
build-all:
needs: node_modules_cache
name: Build all packages
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: 20.x
cache: yarn
- uses: actions/cache/restore@v3
with:
key: ${{ runner.os }}-yarn-${{ hashFiles('yarn.lock') }}
path: ${{ env.NODE_MODULES_PATHS }}
- run: yarn
- run: yarn build
lint:
needs: node_modules_cache
name: Lint packages
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: 20.x
cache: yarn
- uses: actions/cache/restore@v3
with:
key: ${{ runner.os }}-yarn-${{ hashFiles('yarn.lock') }}
path: ${{ env.NODE_MODULES_PATHS }}
- run: yarn
- name: Lint errors
run: yarn lint-all --quiet
- name: Lint warnings
run: yarn lint-all
storybook:
needs: node_modules_cache
# Workaround for define plugin conflict warning
env:
NODE_ENV: development
continue-on-error: true
name: Test storybook
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: 20.x
cache: yarn
- uses: actions/cache/restore@v3
with:
key: ${{ runner.os }}-yarn-${{ hashFiles('yarn.lock') }}
path: ${{ env.NODE_MODULES_PATHS }}
- run: yarn
- run: yarn build-shared
- run: yarn workspace @tamanu/web-frontend run test-storybook
migrations:
needs: node_modules_cache
strategy:
fail-fast: false
matrix:
server:
- central-server
- facility-server
postgres:
- '12'
- '14'
- '15'
- '16'
name: Test migrations server=${{ matrix.server }} pg=${{ matrix.postgres }}
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: 20.x
cache: yarn
- uses: actions/cache/restore@v3
with:
key: ${{ runner.os }}-yarn-${{ hashFiles('yarn.lock') }}
path: ${{ env.NODE_MODULES_PATHS }}
- run: yarn
- run: yarn build-shared
- name: Install and start postgres ${{ matrix.postgres }}
run: |
source .github/scripts/install-postgres-ubuntu.sh ${{ matrix.postgres }}
.github/scripts/setup-postgres-for-one-package.sh migrations
- run: scripts/apply_and_revert_server_migrations.sh ${{ matrix.server }}
test-mobile:
name: Test mobile
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: 20.x
cache: yarn
- uses: actions/cache/restore@v3
with:
key: ${{ runner.os }}-yarnmobile-${{ hashFiles('mobile/yarn.lock') }}
path: mobile/node_modules
- run: yarn
working-directory: packages/mobile
- uses: actions/cache/save@v3
with:
key: ${{ runner.os }}-yarnmobile-${{ hashFiles('mobile/yarn.lock') }}
path: mobile/node_modules
- run: yarn test
working-directory: packages/mobile
test-facility-offline:
needs: node_modules_cache
name: Test the facility server with the central server being down
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: 20.x
cache: yarn
- uses: actions/cache/restore@v3
with:
key: ${{ runner.os }}-yarn-${{ hashFiles('yarn.lock') }}
path: ${{ env.NODE_MODULES_PATHS }}
- run: yarn
- name: Install and start postgres
run: |
source .github/scripts/install-postgres-ubuntu.sh 16
.github/scripts/test-facility-offline.sh setup-postgres
- name: Build central and facility servers
run: .github/scripts/test-facility-offline.sh build
- name: Start a central server
run: .github/scripts/test-facility-offline.sh central-start
- name: Start a facility server
run: .github/scripts/test-facility-offline.sh facility-start
- name: Stop the servers and print logs
run: .github/scripts/test-facility-offline.sh stop-and-print
- name: Start a facility server again without a central one
run: .github/scripts/test-facility-offline.sh facility-start-again
test-yarn-lock:
strategy:
fail-fast: false
matrix:
workdir:
- .
- packages/mobile
name: Check ${{ matrix.workdir }}/yarn.lock is up to date
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: 20.x
cache: yarn
- run: yarn
working-directory: ${{ matrix.workdir }}
- run: git diff --exit-code
# Dummy job to have a stable name for PR requirements
tests-pass:
if: always() # always run even if dependencies fail
name: Tests pass
needs:
- test
- build-all
- lint
- migrations
- test-mobile
- test-facility-offline
- test-yarn-lock
runs-on: ubuntu-latest
steps:
- uses: re-actors/alls-green@release/v1
with:
jobs: ${{ toJSON(needs) }}