generated from 8iq/nodejs-hackathon-boilerplate-starter-kit
-
Notifications
You must be signed in to change notification settings - Fork 30
404 lines (389 loc) · 13.6 KB
/
nodejs.condo.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
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
name: Condo CI
on:
push:
branches:
- main
# NOTE: change pull_request_target to pull_request if you want to change the CI in your branch
pull_request_target:
types:
- opened
- reopened
- synchronize
branches:
- main
workflow_dispatch:
concurrency:
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
cancel-in-progress: true
env:
DOCKER_IMAGE: condo/condo-image:${{ github.event.pull_request.head.sha || github.sha }}
DOCKER_IMAGE_FULL: ${{ secrets.DOCKER_REGISTRY }}/condo/condo-image:${{ github.event.pull_request.head.sha || github.sha }}
PG_IMAGE_FULL: ${{ secrets.DOCKER_REGISTRY }}/doma/utils/postgres:13.2
REDIS_IMAGE_FULL: ${{ secrets.DOCKER_REGISTRY }}/doma/utils/redis:6.2
REF: ${{ github.event.pull_request.head.sha || github.ref }}
jobs:
authorize:
name: Authorize PR
runs-on: ubuntu-22.04
environment:
${{ github.event_name == 'pull_request_target' &&
github.event.pull_request.head.repo.full_name != github.repository &&
'external' || 'internal' }}
outputs:
ref: ${{ env.REF }}
steps:
- run: echo "PR is authorized to run CI jobs"
build-image:
name: Build Docker Image
needs: authorize
runs-on: test-pool-runners
outputs:
DOCKER_IMAGE: ${{ env.DOCKER_IMAGE }}
steps:
- name: Prepare runner
run: |
sudo apt update && sudo apt install -y git
- name: Set registry variables
run: |
echo "DOCKER_CACHE_FROM=type=registry,ref=${{ secrets.DOCKER_REGISTRY }}/condo/condo-image:$( echo "${{github.ref_name}}" | sed 's/[^a-zA-Z0-9]/-/g' ) >> $GITHUB_ENV"
echo "DOCKER_CACHE_TO=type=registry,ref=${{ secrets.DOCKER_REGISTRY }}/condo/condo-image:$( echo "${{github.ref_name}}" | sed 's/[^a-zA-Z0-9]/-/g' ),mode=min,image-manifest=true" >> $GITHUB_ENV
- name: Login to cloud registry
uses: docker/login-action@v3
with:
registry: ${{ secrets.DOCKER_REGISTRY }}
username: ${{ secrets.SBERCLOUD_CR_USERNAME }}
password: ${{ secrets.SBERCLOUD_CR_PASSWORD }}
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0
submodules: recursive
ssh-key: ${{ secrets.SSH_DOCK_SERVER_PRIVATE_KEY }}
ref: ${{ env.REF }}
- name: Prune repo to filter out yarn.lock and package.json
run: |
bash bin/prune.sh
- name: Setup context for Docker BuildX
id: buildx-context
run: |
docker context create builders
- name: Setup Docker BuildX
id: buildx
uses: docker/setup-buildx-action@v3
with:
endpoint: builders
driver-opts: |
env.BUILDKIT_STEP_LOG_MAX_SIZE=10485760
image=${{ secrets.DOCKER_REGISTRY }}/doma/utils/buildkit:buildx-stable-1
- name: Build repo image
uses: docker/build-push-action@v5
with:
context: .
file: Dockerfile
push: true
tags: ${{ env.DOCKER_IMAGE_FULL }}
build-args: |
REGISTRY=${{ secrets.DOCKER_REGISTRY }}/doma/utils
TURBO_TEAM=condo-ci
TURBO_REMOTE_ONLY=true
TURBO_TOKEN=${{ secrets.TURBO_TOKEN }}
TURBO_API=${{ secrets.TURBO_API }}
provenance: false
cache-from: ${{ env.DOCKER_CACHE_FROM }}
cache-to: ${{ env.DOCKER_CACHE_TO }}
- name: Collect docker logs on failure
if: failure()
uses: jwalton/gh-docker-logs@v1
with:
dest: './docker-logs'
- name: Upload log artifact
uses: actions/upload-artifact@v4
if: failure()
with:
name: logs
path: |
*.log
./docker-logs
retention-days: 2
# SRC: https://how.wtf/run-workflow-step-or-job-based-on-file-changes-github-actions.html
detect-changes:
name: Define job list based on changed files
needs: authorize
runs-on: ubuntu-22.04
outputs:
address-service: ${{ steps.detect-changes.outputs.address-service }}
dev-api: ${{ steps.detect-changes.outputs.dev-api }}
condorb: ${{ steps.detect-changes.outputs.condorb }}
webhooks: ${{ steps.detect-changes.outputs.webhooks }}
steps:
- name: Checkout code with submodules
uses: actions/checkout@v4
with:
fetch-depth: 0
submodules: recursive
ssh-key: ${{ secrets.SSH_DOCK_SERVER_PRIVATE_KEY }}
ref: ${{ env.REF }}
- name: Scan changed files
uses: dorny/paths-filter@v3
id: detect-changes
with:
filters: |
address-service:
- 'apps/address-service/**'
- 'packages/**'
condorb:
- 'apps/condorb'
- 'packages/**'
dev-api:
- 'apps/dev-api/**'
- 'apps/condo/domains/miniapp/**'
- 'apps/condo/domains/user/**'
- 'packages/**'
webhooks:
- 'packages/webhooks/**'
lint:
name: Lint source code
needs: authorize
runs-on: ubuntu-22.04
steps:
- name: Checkout code with submodules
uses: actions/checkout@v4
with:
fetch-depth: 0
submodules: recursive
ssh-key: ${{ secrets.SSH_DOCK_SERVER_PRIVATE_KEY }}
ref: ${{ env.REF }}
- name: Prepare Node environment
uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node-version }}
cache: 'yarn'
- name: Install root dependencies
run: |
yarn workspaces focus root
- name: Check JS code-style rules
run: |
yarn lint:code
- name: Check styling rules
run: |
yarn lint:styles
- name: Check translations rules
run: |
yarn lint:translations
- name: Check common file patterns
run: |
bash ./bin/lint-common-patterns.sh
# TODO(DOMA-7754): Figure out how to extract schema without starting KS-app (30sec for start per app is slow) and lint all apps
security:
name: Semgrep vulnerabilities check
needs: authorize
runs-on: ubuntu-22.04
container:
image: returntocorp/semgrep
# Skip any PR created by dependabot to avoid permission issues
if: (github.actor != 'dependabot[bot]')
steps:
# Fetch project source with GitHub Actions Checkout.
- name: Checkout code with submodules
uses: actions/checkout@v4
with:
fetch-depth: 0
submodules: recursive
ssh-key: ${{ secrets.SSH_DOCK_SERVER_PRIVATE_KEY }}
ref: ${{ env.REF }}
- run: ./bin/run-semgrep.sh -a
run-address-service-tests:
name: Address-Service Tests
runs-on: ubuntu-22.04
needs:
- authorize
- build-image
- detect-changes
if: ${{ needs.detect-changes.outputs.address-service == 'true' }}
steps:
- name: Login to cloud registry
uses: docker/login-action@v3
with:
registry: ${{ secrets.DOCKER_REGISTRY }}
username: ${{ secrets.SBERCLOUD_CR_USERNAME }}
password: ${{ secrets.SBERCLOUD_CR_PASSWORD }}
- name: Setup PG db
run: |
docker run -e POSTGRES_USER=$POSTGRES_USER -e POSTGRES_PASSWORD=$POSTGRES_PASSWORD -e POSTGRES_DB=$POSTGRES_DB -p="127.0.0.1:5432:5432" -d ${{ env.PG_IMAGE_FULL }}
env:
POSTGRES_USER: postgres
POSTGRES_PASSWORD: postgres
POSTGRES_DB: main
- name: Setup Redis db
run: |
docker run -p="127.0.0.1:6379:6379" -d ${{ env.REDIS_IMAGE_FULL }}
- name: Run condo container with daemon
run: |
docker run --network="host" --name condo-container -dit ${{ env.DOCKER_IMAGE_FULL }} sh
- name: Prepare apps
run: |
docker exec condo-container node bin/prepare.js -f address-service condo
- name: Check migrations state
run: |
docker exec condo-container yarn workspace @app/address-service makemigrations --check
- name: Run apps and tests
run: |
docker exec condo-container sh -c "(\
yarn workspace @app/address-service start & \
node bin/wait-apps-apis.js -f address-service) && \
yarn workspace @app/address-service test"
run-condo-tests:
name: Condo Tests
needs:
- authorize
- build-image
strategy:
matrix:
domain:
- organization
- user
- scope
- property
- acquiring
- billing
- miniapp
- banking
- ticket
- meter
- contact
- resident
- notification
- common
- others
uses: ./.github/workflows/_nodejs.condo.core.tests.yml
with:
domain_name: ${{ matrix.domain }}
runs-on: runners-dind-set-cpu5-ram10
image_name: ${{ needs.build-image.outputs.DOCKER_IMAGE }}
secrets: inherit
run-condo-e2e-tests:
name: Condo E2E Tests
needs: authorize
uses: ./.github/workflows/_nodejs.condo.cypress.yml
with:
ref: ${{ needs.authorize.outputs.ref }}
secrets: inherit
run-condorb-tests:
name: CondoRB Tests
runs-on: ubuntu-22.04
needs:
- authorize
- build-image
- detect-changes
if: ${{ needs.detect-changes.outputs.condorb == 'true' }}
steps:
- name: Login to cloud registry
uses: docker/login-action@v3
with:
registry: ${{ secrets.DOCKER_REGISTRY }}
username: ${{ secrets.SBERCLOUD_CR_USERNAME }}
password: ${{ secrets.SBERCLOUD_CR_PASSWORD }}
- name: Setup PG db
run: |
docker run -e POSTGRES_USER=$POSTGRES_USER -e POSTGRES_PASSWORD=$POSTGRES_PASSWORD -e POSTGRES_DB=$POSTGRES_DB -p="127.0.0.1:5432:5432" -d ${{ env.PG_IMAGE_FULL }}
env:
POSTGRES_USER: postgres
POSTGRES_PASSWORD: postgres
POSTGRES_DB: main
- name: Setup Redis db
run: |
docker run -p="127.0.0.1:6379:6379" -d ${{ env.REDIS_IMAGE_FULL }}
- name: Run condo container with daemon
run: |
docker run --network="host" --name condo-container -dit ${{ env.DOCKER_IMAGE_FULL }} sh
- name: Prepare apps
run: |
docker exec condo-container node bin/prepare.js -f condo condorb
- name: Check migrations state
run: |
docker exec condo-container yarn workspace @app/condorb makemigrations --check
- name: Run apps and tests
run: |
docker exec condo-container sh -c "(\
yarn workspace @app/condo start & \
yarn workspace @app/condorb start & \
node bin/wait-apps-apis.js -f condo condorb) && \
yarn workspace @app/condorb test"
run-dev-api-tests:
name: DEV-API Tests
runs-on: ubuntu-22.04
needs:
- authorize
- build-image
- detect-changes
if: ${{ needs.detect-changes.outputs.dev-api == 'true' }}
steps:
- name: Login to cloud registry
uses: docker/login-action@v3
with:
registry: ${{ secrets.DOCKER_REGISTRY }}
username: ${{ secrets.SBERCLOUD_CR_USERNAME }}
password: ${{ secrets.SBERCLOUD_CR_PASSWORD }}
- name: Setup PG db
run: |
docker run -e POSTGRES_USER=$POSTGRES_USER -e POSTGRES_PASSWORD=$POSTGRES_PASSWORD -e POSTGRES_DB=$POSTGRES_DB -p="127.0.0.1:5432:5432" -d ${{ env.PG_IMAGE_FULL }}
env:
POSTGRES_USER: postgres
POSTGRES_PASSWORD: postgres
POSTGRES_DB: main
- name: Setup Redis db
run: |
docker run -p="127.0.0.1:6379:6379" -d ${{ env.REDIS_IMAGE_FULL }}
- name: Run condo container with daemon
run: |
mkdir test_logs
chmod -R a+rw ./test_logs
docker run -v ./test_logs:/app/test_logs --network="host" --name condo-container -dit ${{ env.DOCKER_IMAGE_FULL }} sh
- name: Prepare apps
run: |
docker exec condo-container node bin/prepare.js -f condo dev-api
- name: Check migrations state
run: |
docker exec condo-container yarn workspace @app/dev-api makemigrations --check
- name: Run apps and tests
run: |
docker exec condo-container sh -c "yarn workspace @app/condo start" 2>&1 > ./test_logs/devapi.condo.dev.log &
docker exec condo-container sh -c "yarn workspace @app/dev-api start" 2>&1 > ./test_logs/devapi.dev-api.dev.log &
docker exec condo-container sh -c "node bin/wait-apps-apis.js -f condo dev-api"
docker exec condo-container sh -c "yarn workspace @app/dev-api test" 2>&1 > ./test_logs/devapi.tests.log
- name: Collect docker logs on failure
if: failure()
uses: jwalton/gh-docker-logs@v1
with:
dest: './docker-logs'
- name: Upload log artifact
uses: actions/upload-artifact@v4
if: failure()
with:
name: dev-api
path: |
./test_logs/*
*.log
./docker-logs
retention-days: 2
run-webhooks-tests:
name: Webhooks Tests
runs-on: ubuntu-22.04
needs:
- authorize
- detect-changes
if: ${{ needs.detect-changes.outputs.webhooks == 'true' }}
steps:
- name: Checkout code with submodules
uses: actions/checkout@v4
with:
fetch-depth: 0
submodules: recursive
ssh-key: ${{ secrets.SSH_DOCK_SERVER_PRIVATE_KEY }}
ref: ${{ env.REF }}
- name: Install packages
run: |
npm i -g turbo
yarn install --immutable
- name: Test webhooks utils
run: yarn workspace @open-condo/webhooks jest