-
Notifications
You must be signed in to change notification settings - Fork 46
405 lines (357 loc) · 12.5 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
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
405
name: CI
on:
push:
branches:
- master
tags-ignore:
- "**"
pull_request:
branches:
- "**"
jobs:
common_checks:
name: Common checks
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: 20.8.0
cache: 'npm'
cache-dependency-path: '**/package-lock.json'
- name: Install dependencies
run: npm ci
- name: Check formatting
run: npm run format:check
build_ilc:
name: Build ILC
runs-on: ubuntu-latest
strategy:
matrix:
branch:
- name: src
ref: ${{ github.ref }}
- name: dest
ref: ${{ github.base_ref }}
exclude:
- branch:
ref: ""
steps:
- uses: actions/checkout@v4
with:
ref: ${{ matrix.branch.ref }}
- id: sha7
run: |
echo "SHA=$(git rev-parse --short HEAD)" >> $GITHUB_ENV
echo "BRANCH=$(git rev-parse --abbrev-ref HEAD)" >> $GITHUB_ENV
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
- name: Set up Docker Buildx
id: buildx
uses: docker/setup-buildx-action@v3
- name: Docker ILC auth
run: echo "${{ secrets.DOCKER_HUB_BROTHERS_TOKEN }}" | docker login --username brothers --password-stdin
- name: Build the Docker image
uses: docker/build-push-action@v3
with:
context: ./ilc
platforms: linux/amd64,linux/arm64
push: true
cache-from: |
type=registry,ref=namecheap/ilc_tmp:buildcache
cache-to: |
type=registry,ref=namecheap/ilc_tmp:buildcache,mode=max
tags: |
namecheap/ilc_tmp:${{ env.SHA }}
- name: Run server-side tests
run: docker run namecheap/ilc_tmp:$SHA npm run test:ci
- name: Run server-side tests coverage
run: docker run --volume $(pwd)/artifacts/ilc/coverage/server:/.coverage namecheap/ilc_tmp:$SHA bash -c "npm run test:coverage && mv .nyc_output/* /.coverage"
- uses: actions/upload-artifact@v4
with:
name: ${{ matrix.branch.name }}-server-side-tests-artifacts
path: artifacts/ilc/coverage/server
- name: Build the Docker image to test client-side
run: |
cd ./ilc/
DOCKER_BUILDKIT=1 docker build . --file ./Test.Dockerfile --tag ilc:tmp-test-client --build-arg BASE_IMAGE=namecheap/ilc_tmp:$SHA
- name: Run client-side tests
run: |
echo fs.inotify.max_user_watches=524288 | sudo tee -a /etc/sysctl.conf
sudo sysctl -p
docker run --volume $(pwd)/artifacts/ilc/coverage/client:/.coverage ilc:tmp-test-client bash -c "npm run test:client -- --browsers ChromeHeadlessWithoutSecurity && mv .karma_output/* /.coverage"
- uses: actions/upload-artifact@v4
with:
name: ${{ matrix.branch.name }}-client-side-tests-artifacts
path: artifacts/ilc/coverage/client
build_registry:
name: Build Registry
runs-on: ubuntu-latest
strategy:
matrix:
branch:
- name: src
ref: ${{ github.ref }}
- name: dest
ref: ${{ github.base_ref }}
exclude:
- branch:
ref: ""
steps:
- uses: actions/checkout@v4
with:
ref: ${{ matrix.branch.ref }}
- id: sha7
run: echo "SHA=$(git rev-parse --short HEAD)" >> $GITHUB_ENV
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
- name: Set up Docker Buildx
id: buildx
uses: docker/setup-buildx-action@v3
with:
buildkitd-flags: --debug
- name: Docker registry auth
run: echo "${{ secrets.DOCKER_HUB_BROTHERS_TOKEN }}" | docker login --username brothers --password-stdin
- name: Build the Docker image
uses: docker/build-push-action@v3
with:
context: ./registry
platforms: linux/amd64,linux/arm64
push: true
cache-from: |
type=registry,ref=namecheap/ilc_tmp:buildcache_registry_${{ matrix.branch.name }}
cache-to: |
type=registry,ref=namecheap/ilc_tmp:buildcache_registry_${{ matrix.branch.name }},mode=max
tags: |
namecheap/ilc_tmp:reg_${{ env.SHA }}
registry_tests:
name: Test Registry
needs: [build_registry]
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
branch:
- name: src
ref: ${{ github.ref }}
- name: dest
ref: ${{ github.base_ref }}
database:
- client: sqlite3
- client: mysql
host: mysql
port: 3306
- client: pg
host: postgres
port: 5432
exclude:
- branch:
ref: ""
env:
DB_CLIENT: ${{ matrix.database.client }}
DB_NAME: ilc_${{ matrix.branch.name }}
services:
mysql:
image: mysql:5.7
env:
MYSQL_ROOT_PASSWORD: pwd
ports:
- 3306:3306
volumes:
- ${{ github.workspace }}:/usr/src/ilc
options: --name=mysql --health-cmd="mysqladmin ping" --health-interval=10s --health-timeout=5s --health-retries=3
postgres:
image: postgres:15.4-alpine
env:
POSTGRES_USER: root
POSTGRES_PASSWORD: pwd
volumes:
- ${{ github.workspace }}:/usr/src/ilc
ports:
- 5432:5432
options: --name=postgres --health-cmd pg_isready --health-interval 10s --health-timeout 5s --health-retries 5
steps:
- uses: actions/checkout@v4
with:
ref: ${{ matrix.branch.ref }}
- id: sha7
run: echo "SHA=$(git rev-parse --short HEAD)" >> $GITHUB_ENV
- name: Docker registry auth
run: echo "${{ secrets.DOCKER_HUB_BROTHERS_TOKEN }}" | docker login --username brothers --password-stdin
- name: Run tests
run: >-
bash ./registry/scripts/reset.sh;
docker run
--volume $(pwd)/artifacts/registry/coverage:/.coverage
--network ${{ job.container.network }}
-e DB_CLIENT=${{ matrix.database.client }}
-e DB_HOST=${{ matrix.database.host }}
-e DB_PORT=${{ matrix.database.port }}
-e DB_USER=root
-e DB_PASSWORD=pwd
-e DB_NAME=$DB_NAME
namecheap/ilc_tmp:reg_$SHA
sh -c "npm run test:ci && mv .nyc_output/* /.coverage"
- uses: actions/upload-artifact@v4
with:
name: ${{ matrix.branch.name }}-${{ matrix.database.client }}-registry-tests-artifacts
path: ./artifacts/registry/coverage
e2e_tests:
name: Run E2E tests
runs-on: ubuntu-22.04
strategy:
fail-fast: false
matrix:
database:
- client: mysql
host: mysql
port: 3306
- client: pg
host: postgres
port: 5432
services:
mysql:
image: mysql:5.7
env:
MYSQL_ROOT_PASSWORD: pwd
MYSQL_DATABASE: ilc
ports:
- 3306:3306
options: --name=mysql --health-cmd="mysqladmin ping" --health-interval=10s --health-timeout=5s --health-retries=3
postgres:
image: postgres:15.4-alpine
env:
POSTGRES_USER: root
POSTGRES_PASSWORD: pwd
POSTGRES_DB: ilc
ports:
- 5432:5432
options: --name=postgres --health-cmd pg_isready --health-interval 10s --health-timeout 5s --health-retries 5
steps:
- uses: actions/checkout@v4
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: 20.8.0
cache: 'npm'
cache-dependency-path: '**/package-lock.json'
- name: Install dependencies
run: npm install
- name: Build ILC & Registry
run: npm run build
- name: Run E2E tests
working-directory: e2e
run: npm run start:verbose
env:
DB_CLIENT: ${{ matrix.database.client }}
DB_HOST: localhost
DB_PORT: ${{ matrix.database.port }}
DB_USER: root
DB_PASSWORD: pwd
DB_NAME: ilc
- uses: actions/upload-artifact@v4
if: failure()
with:
name: e2e-tests-artifacts
path: e2e/.codecept_output
coverage_report:
name: PR Coverage Report
runs-on: ubuntu-latest
needs: [build_ilc, registry_tests]
if: github.base_ref
steps:
- uses: actions/checkout@v4
- uses: actions/download-artifact@v4
- name: Create coverage report for ilc/server
id: ilc-server-coverage-report
uses: namecheap/Coverage-Diff@master
with:
fullCoverageDiff: true
autorun: false
postComment: false
oldCodeCoveragePath: ./dest-server-side-tests-artifacts/coverage/coverage-summary.json
newCodeCoveragePath: ./src-server-side-tests-artifacts/coverage/coverage-summary.json
total_delta: 2
- name: Create coverage report for ilc/client
id: ilc-client-coverage-report
if: success() || failure()
uses: namecheap/Coverage-Diff@master
with:
fullCoverageDiff: true
autorun: false
postComment: false
oldCodeCoveragePath: ./dest-client-side-tests-artifacts/coverage/chrome/coverage-summary.json
newCodeCoveragePath: ./src-client-side-tests-artifacts/coverage/chrome/coverage-summary.json
total_delta: 2
- name: Merge coverage report for registry
run: |
bash .github/workflows/merge-registry-coverage.sh dest
bash .github/workflows/merge-registry-coverage.sh src
- name: Create coverage report for registry
id: registry-coverage-report
if: success() || failure()
uses: namecheap/Coverage-Diff@master
with:
fullCoverageDiff: true
autorun: false
postComment: false
oldCodeCoveragePath: ./dest-merged-registry-tests-artifacts/coverage/coverage-summary.json
newCodeCoveragePath: ./src-merged-registry-tests-artifacts/coverage/coverage-summary.json
total_delta: 6
- name: Compose comment
if: success() || failure()
run: |
echo "# Coverage Report" > report.md
echo "## Ilc/server" >> report.md
echo "${{ steps.ilc-server-coverage-report.outputs.report }}" >> report.md
echo "## Ilc/client" >> report.md
echo "${{ steps.ilc-client-coverage-report.outputs.report }}" >> report.md
echo "## Registry" >> report.md
echo "${{ steps.registry-coverage-report.outputs.report }}" >> report.md
- name: Add Coverage PR Comment
if: success() || failure()
uses: marocchino/sticky-pull-request-comment@v2
with:
recreate: true
header: coverage-diff-report
path: report.md
push_images:
needs: [build_ilc, registry_tests, e2e_tests]
name: Push images to registry
runs-on: ubuntu-latest
steps:
- name: Docker registry auth
run: echo "${{ secrets.DOCKER_HUB_BROTHERS_TOKEN }}" | docker login --username brothers --password-stdin
- name: Calculate tags
id: tags
run: |
BRANCH=$(echo ${GITHUB_REF} | cut -d '/' -f 3-99)
LATEST=$([ "$BRANCH" == "master" ] && echo "latest,${GITHUB_SHA:0:7}," || echo "")
DOCKER_TAGS="$LATEST${BRANCH//\//_}"
echo "Tags that will be used: $DOCKER_TAGS"
echo ::set-output name=docker_tags::$DOCKER_TAGS
- name: Install regctl
run: |
curl -L https://github.com/regclient/regclient/releases/download/v0.3.10/regctl-linux-amd64 > ./regctl
chmod 755 ./regctl
- name: Push images
run: |
TAGS="${{ steps.tags.outputs.docker_tags }}"
for i in ${TAGS//,/ }
do
./regctl image copy namecheap/ilc_tmp:reg_${GITHUB_SHA:0:7} namecheap/ilc_registry:$i
./regctl image copy namecheap/ilc_tmp:${GITHUB_SHA:0:7} namecheap/ilc:$i
done
build_docs:
needs: [push_images]
name: Build documentation
runs-on: ubuntu-latest
if: github.ref == 'refs/heads/master'
steps:
- uses: actions/checkout@v4
- name: Build the Docker image
run: |
docker build -t ilc-mkdocs - < ./.mkdocs/Dockerfile
- name: Generate docs and publish to GitHub Pages
run: docker run --rm -v ${PWD}:/docs ilc-mkdocs gh-deploy --force