-
Notifications
You must be signed in to change notification settings - Fork 2
374 lines (346 loc) · 14 KB
/
continuous-integration.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
name: CICD
on:
workflow_dispatch:
push:
branches:
- "master"
tags:
- "v*"
pull_request:
branches:
- "master"
release:
types: [released, prereleased]
env:
REGISTRY: ghcr.io/${{ github.repository_owner }}
jobs:
lint:
name: Lint
permissions:
checks: write
contents: write
runs-on: ubuntu-latest
concurrency:
group: ${{ github.workflow }}-lint-${{ matrix.project }}-${{ github.ref }}
cancel-in-progress: true
strategy:
fail-fast: false
matrix:
project:
- api
- web
include:
- project: api
dir: ./src/api
lang: cs
config:
auto_fix: false
continue_on_error: false
check_name: "Dotnet Format (${dir})"
dotnet_format: true
dotnet_format_dir: ./src/api
env: {}
- project: web
dir: ./src/web
lang: js
config:
auto_fix: false
continue_on_error: false
check_name: "${linter} (${dir})"
# ESLint
eslint: true
eslint_dir: ./src/web
eslint_extensions: js,ts,tsx
eslint_args: --ignore-path ../../.gitignore --config .eslintrc.cjs
# Prettier
prettier: true
prettier_dir: ./src/web
prettier_extensions: js,ts,tsx
prettier_args: --ignore-path ../../.gitignore --config prettier.config.cjs
env:
SKIP_ENV_VALIDATION: true
# outputs: # https://github.com/actions/runner/pull/2477
# ${{ matrix.project }}-changes: ${{ steps.filter.outputs.changes }}
steps:
- uses: actions/checkout@v4
- uses: dorny/paths-filter@v3
id: filter
with:
base: master
filters: |-
changes:
- '${{ matrix.dir }}/**'
web:
- './src/web/**'
- uses: actions/setup-node@v4
if: (steps.filter.outputs.web == 'true' || github.event_name == 'workflow_dispatch') && matrix.lang == 'js'
with:
node-version: 18
cache: yarn
- run: yarn install --frozen-lockfile
if: (steps.filter.outputs.changes == 'true' || github.event_name == 'workflow_dispatch') && matrix.lang == 'js'
working-directory: ${{ matrix.dir }}
- uses: actions/setup-dotnet@v4
if: (steps.filter.outputs.changes == 'true' || github.event_name == 'workflow_dispatch') && matrix.lang == 'cs'
with:
dotnet-version: 7.x
- uses: wearerequired/lint-action@v2
if: steps.filter.outputs.changes == 'true' || github.event_name == 'workflow_dispatch'
with: ${{ matrix.config }}
env: ${{ matrix.env }}
build:
name: Build and push
permissions:
contents: read
packages: write
runs-on: ubuntu-latest
concurrency:
group: ${{ github.workflow }}-build-${{ matrix.image }}-${{ github.ref }}
cancel-in-progress: true
needs:
- lint
outputs:
image_version: ${{ steps.meta.outputs.version }}
strategy:
matrix:
image:
- yoma-api
- yoma-web
include:
- image: yoma-api
context: ./src/api
file: ./src/api/Dockerfile
buildArgs: ""
- image: yoma-web
context: ./src/web
file: ./src/web/Dockerfile
buildArgs: |-
NEXT_PUBLIC_ENVIRONMENT=production
steps:
- uses: actions/checkout@v4
- uses: dorny/paths-filter@v3 # https://github.com/actions/runner/pull/2477
id: filter
with:
base: master
filters: |-
changes:
- '${{ matrix.context }}/**'
- uses: docker/setup-buildx-action@v3
if: steps.filter.outputs.changes == 'true' || github.event_name == 'workflow_dispatch'
- uses: docker/login-action@v3
if: steps.filter.outputs.changes == 'true' || github.event_name == 'workflow_dispatch'
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ github.token }}
- uses: docker/metadata-action@v5
id: meta
with:
images: ${{ env.REGISTRY }}/${{ matrix.image }}
tags: |
type=raw,value=latest,enable=${{ github.ref == 'refs/heads/master' }}
type=sha,prefix=pr-${{ github.event.pull_request.number }}-,priority=601,enable=${{ github.event_name == 'pull_request' }}
type=sha,prefix={{branch}}-,priority=601,enable=${{ github.event_name != 'pull_request' }}
type=ref,event=branch,priority=600
type=ref,event=pr
type=semver,pattern={{version}}
type=semver,pattern={{major}}.{{minor}}
- uses: docker/build-push-action@v5
if: steps.filter.outputs.changes == 'true' || github.event_name == 'workflow_dispatch'
with:
platforms: linux/amd64,linux/arm64/v8
context: ${{ matrix.context }}
file: ${{ matrix.file }}
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
cache-from: type=gha,scope=build-${{ matrix.image }}
cache-to: type=gha,mode=max,scope=build-${{ matrix.image }}
build-args: ${{ matrix.buildArgs }}
test-e2e:
name: Test (e2e)
permissions:
id-token: write
contents: read
packages: read
needs: build
runs-on: ubuntu-latest
env:
PUBLIC_S3_ACCESS_KEY: ${{ secrets.PUBLIC_S3_ACCESS_KEY }}
PUBLIC_S3_SECRET_KEY: ${{ secrets.PUBLIC_S3_SECRET_KEY }}
PRIVATE_S3_ACCESS_KEY: ${{ secrets.PRIVATE_S3_ACCESS_KEY }}
PRIVATE_S3_SECRET_KEY: ${{ secrets.PRIVATE_S3_SECRET_KEY }}
concurrency:
group: ${{ github.workflow }}-e2e-${{ github.ref }}
cancel-in-progress: true
steps:
- uses: actions/checkout@v4
- uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ github.token }}
- name: Create env file
run: |
echo "AWSS3__Buckets__Public__AccessKey=${{ secrets.PUBLIC_S3_ACCESS_KEY }}" >> src/api/env.secrets
echo "AWSS3__Buckets__Public__SecretKey=${{ secrets.PUBLIC_S3_SECRET_KEY }}" >> src/api/env.secrets
echo "AWSS3__Buckets__Public__BucketName=yoma-v3-public-storage" >> src/api/env.secrets
echo "AWSS3__Buckets__Private__AccessKey=${{ secrets.PRIVATE_S3_ACCESS_KEY }}" >> src/api/env.secrets
echo "AWSS3__Buckets__Private__SecretKey=${{ secrets.PRIVATE_S3_SECRET_KEY }}" >> src/api/env.secrets
echo "AWSS3__Buckets__Private__BucketName=yoma-v3-private-storage" >> src/api/env.secrets
echo "AriesCloudAPI__BaseUri=${{ secrets.ARIESCLOUDAPI_BASEURI }}" >> src/api/env.secrets
echo "AriesCloudAPI__GroupId=${{ secrets.ARIESCLOUDAPI_GROUPID }}" >> src/api/env.secrets
echo "AriesCloudAPI__ProtocolVersion=v2" >> src/api/env.secrets
echo "AriesCloudAPI__GovernanceAdmin__ClientId=${{ secrets.ARIESCLOUDAPI_GOVERNANCEADMIN_CLIENTID }}" >> src/api/env.secrets
echo "AriesCloudAPI__GovernanceAdmin__ClientSecret=${{ secrets.ARIESCLOUDAPI_GOVERNANCEADMIN_CLIENTSECRET }}" >> src/api/env.secrets
echo "AriesCloudAPI__Customer__ClientId=${{ secrets.ARIESCLOUDAPI_CUSTOMER_CLIENTID }}" >> src/api/env.secrets
echo "AriesCloudAPI__Customer__ClientSecret=${{ secrets.ARIESCLOUDAPI_CUSTOMER_CLIENTSECRET }}" >> src/api/env.secrets
echo "Zlto__Username=${{ secrets.ZLTO_USERNAME }}" >> src/api/env.secrets
echo "Zlto__Password=${{ secrets.ZLTO_PASSWORD }}" >> src/api/env.secrets
echo "AppSettings__SSIIssuerNameYomaOrganization=${{ secrets.APPSETTINGS_SSIISSUERNAMEYOMAORGANIZATION }}" >> src/api/env.secrets
echo "AppSettings__SSISchemaFullNameYoID=${{ secrets.APPSETTINGS_SSISCHEMAFULLNAMEYOID }}" >> src/api/env.secrets
- uses: dorny/paths-filter@v3 # https://github.com/actions/runner/pull/2477
id: filter
with:
base: master
filters: |-
api:
- './src/api/**'
web:
- './src/web/**'
- name: Pre-pull images
run: |-
docker compose -f ./src/api/docker-compose.yml pull
docker compose -f ./src/web/docker-compose.yml pull
env:
API_TAG: ${{ steps.filter.outputs.api == 'true' && needs.build.outputs.image_version || 'latest' }}
YOUTH_TAG: ${{ steps.filter.outputs.web == 'true' && needs.build.outputs.image_version || 'latest' }}
continue-on-error: true
- name: Start services
run: |-
docker compose -f ./src/api/docker-compose.yml up -d
docker compose -f ./src/web/docker-compose.yml up -d
env:
API_TAG: ${{ steps.filter.outputs.api == 'true' && needs.build.outputs.image_version || 'latest' }}
YOUTH_TAG: ${{ steps.filter.outputs.web == 'true' && needs.build.outputs.image_version || 'latest' }}
- uses: actions/setup-node@v4
with:
node-version: 18
cache: yarn
- uses: cypress-io/github-action@v6
- name: Upload Cypress Screenshots
uses: actions/upload-artifact@v4
if: always()
with:
name: cypress-screenshots
path: cypress/screenshots
if-no-files-found: ignore
- name: Upload Cypress Recording
uses: actions/upload-artifact@v4
if: always()
with:
name: cypress-videos
path: cypress/videos
if-no-files-found: ignore
- name: Keycloak Config logs
if: always()
run: docker logs keycloak-config
- name: Keycloak logs
if: always()
run: docker logs keycloak
- name: Yoma API logs
if: always()
run: docker logs yoma-api
- name: Yoma Web logs
if: always()
run: docker logs yoma-web
- run: docker compose down -v
deploy:
name: Deploy
permissions:
id-token: write
contents: read
packages: read
needs: [test-e2e, build]
runs-on: ubuntu-latest
env:
TAILSCALE_VERSION: 1.58.2
HELMFILE_VERSION: v0.161.0
HELM_VERSION: v3.14.0
TAG: ${{ needs.build.outputs.image_version }}
concurrency:
group: ${{ github.workflow }}-deploy-${{ matrix.project }}-${{ github.ref }}
cancel-in-progress: false
environment:
name: ${{
(github.event_name == 'release' && github.event.action == 'released') && 'prod' ||
(github.event_name == 'release' && github.event.action == 'prereleased') && 'stage' ||
'dev'
}}
url: ${{ vars.PUBLIC_URL }}
if: github.triggering_actor != 'dependabot[bot]'
steps:
- uses: actions/checkout@v4
- uses: dorny/paths-filter@v3 # https://github.com/actions/runner/pull/2477
id: filter
with:
base: master
filters: |-
api:
- './src/api/**'
web:
- './src/web/**'
- uses: unfor19/install-aws-cli-action@v1
if: steps.filter.outputs.api == 'true' || steps.filter.outputs.web == 'true' || github.event_name == 'workflow_dispatch'
- name: SOPS Binary Installer
if: steps.filter.outputs.api == 'true' || steps.filter.outputs.web == 'true' || github.event_name == 'workflow_dispatch'
uses: mdgreenwald/[email protected]
- uses: aws-actions/configure-aws-credentials@v4
if: steps.filter.outputs.api == 'true' || steps.filter.outputs.web == 'true' || github.event_name == 'workflow_dispatch'
with:
aws-region: ${{ secrets.AWS_REGION }}
role-to-assume: ${{ secrets.AWS_ROLE_ARN }}
role-session-name: github-cicd
- run: aws eks update-kubeconfig --name ${{ secrets.CLUSTER }}
if: steps.filter.outputs.api == 'true' || steps.filter.outputs.web == 'true' || github.event_name == 'workflow_dispatch'
- uses: tailscale/github-action@main
if: steps.filter.outputs.api == 'true' || steps.filter.outputs.web == 'true' || github.event_name == 'workflow_dispatch'
with:
authkey: ${{ secrets.TAILSCALE_AUTHKEY }}
version: ${{ env.TAILSCALE_VERSION }}
- name: Set GIT_REF Environment Variable
run: |
if [ "${{ github.event_name }}" == "pull_request" ]; then
echo "GIT_REF=${{ github.head_ref }}" >> $GITHUB_ENV
else
echo "GIT_REF=$(echo ${{ github.ref }} | sed 's/refs\/heads\///')" >> $GITHUB_ENV
fi
# Diff on PR draft. Apply on
- name: Helmfile Apply/Diff API
if: steps.filter.outputs.api == 'true' || github.event_name == 'workflow_dispatch'
uses: helmfile/[email protected]
with:
helmfile-args: |
${{ (github.event_name == 'pull_request' && github.event.pull_request.draft) && 'diff' || 'apply' }} \
--environment ${{ vars.ENVIRONMENT }} \
--selector app=yoma-api \
--state-values-set gitref=${{env.GIT_REF}}
helmfile-version: ${{ env.HELMFILE_VERSION }}
helm-version: ${{ env.HELM_VERSION }}
helm-plugins: |
https://github.com/databus23/helm-diff,
https://github.com/jkroepke/helm-secrets
- name: Helmfile Apply/Diff Web
if: steps.filter.outputs.web == 'true' || github.event_name == 'workflow_dispatch'
uses: helmfile/[email protected]
with:
helmfile-args: |
${{ (github.event_name == 'pull_request' && github.event.pull_request.draft) && 'diff' || 'apply' }} \
--environment ${{ vars.ENVIRONMENT }} \
--selector app=yoma-web \
--state-values-set gitref=${{ env.GIT_REF }}
helmfile-version: ${{ env.HELMFILE_VERSION }}
helm-version: ${{ env.HELM_VERSION }}
helm-plugins: |
https://github.com/databus23/helm-diff,
https://github.com/jkroepke/helm-secrets