-
Notifications
You must be signed in to change notification settings - Fork 89
367 lines (336 loc) · 11.7 KB
/
node-build.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
name: Node Build
on:
workflow_dispatch:
pull_request:
branches:
- '**'
push:
branches:
- main
- release/v*
jobs:
prerequisite:
runs-on: ubuntu-latest
timeout-minutes: 1
steps:
- uses: actions/checkout@v4
- uses: ./.github/workflows/rafiki/env-setup
- run: pnpm checks
backend:
runs-on: ubuntu-latest
needs: prerequisite
timeout-minutes: 25
steps:
- uses: actions/checkout@v4
- uses: ./.github/workflows/rafiki/env-setup
- run: pnpm --filter backend build:deps
- run: NODE_OPTIONS=--max-old-space-size=4096 pnpm --filter backend test:ci
- name: AsyncAPI extension
run: |
echo "{\"extends\":[\"spectral:oas\",\"spectral:asyncapi\"]}" >> .spectral.json
- name: Validate Open API specs
run: |
npx @stoplight/spectral-cli lint ./packages/backend/src/openapi/specs/*.yaml
frontend:
runs-on: ubuntu-latest
needs: prerequisite
timeout-minutes: 5
steps:
- uses: actions/checkout@v4
- uses: ./.github/workflows/rafiki/env-setup
- run: pnpm --filter frontend typecheck
- run: pnpm --filter frontend build
auth:
runs-on: ubuntu-latest
needs: prerequisite
timeout-minutes: 5
steps:
- uses: actions/checkout@v4
- uses: ./.github/workflows/rafiki/env-setup
- run: pnpm --filter auth build:deps
- run: pnpm --filter auth test
- name: AsyncAPI extension
run: |
echo "{\"extends\":[\"spectral:oas\",\"spectral:asyncapi\"]}" >> .spectral.json
- name: Validate Open API specs
run: |
npx @stoplight/spectral-cli lint ./packages/auth/src/openapi/specs/*.yaml
token-introspection:
runs-on: ubuntu-latest
needs: prerequisite
timeout-minutes: 5
steps:
- uses: actions/checkout@v4
- uses: ./.github/workflows/rafiki/env-setup
- run: pnpm --filter token-introspection test
- name: AsyncAPI extension
run: |
echo "{\"extends\":[\"spectral:oas\",\"spectral:asyncapi\"]}" >> .spectral.json
- name: Validate Open API specs
run: |
npx @stoplight/spectral-cli lint ./packages/token-introspection/src/openapi/specs/*.yaml
mock-account-servicing-entity:
runs-on: ubuntu-latest
needs: prerequisite
timeout-minutes: 5
steps:
- uses: actions/checkout@v4
- uses: ./.github/workflows/rafiki/env-setup
- run: pnpm --filter mock-account-servicing-entity build
- run: pnpm --filter mock-account-servicing-entity typecheck
graphql:
runs-on: ubuntu-latest
needs: prerequisite
strategy:
matrix:
package: [auth, backend]
steps:
- uses: actions/checkout@v4
- uses: ./.github/workflows/rafiki/env-setup
- name: generate ${{ matrix.package }} graphql
run: pnpm --filter ${{ matrix.package }} generate
- name: verify changed files
uses: tj-actions/verify-changed-files@v19
id: verify-changed-files
with:
files: |
**/generated/graphql.*
- name: fail if GraphQL was generated
if: steps.verify-changed-files.outputs.files_changed == 'true'
run: exit 1
codeql-analyze:
runs-on: ubuntu-latest
needs: prerequisite
timeout-minutes: 5
permissions:
actions: read
contents: read
security-events: write
strategy:
fail-fast: false
matrix:
language: [ 'javascript' ]
config:
- './.github/codeql/source.yml'
- './.github/codeql/tests.yml'
steps:
- uses: actions/checkout@v4
- uses: ./.github/workflows/rafiki/env-setup
- name: Initialize CodeQL
uses: github/codeql-action/init@v3
with:
languages: ${{ matrix.language }}
config-file: ${{ matrix.config }}
- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@v3
integration-test:
runs-on: ubuntu-22.04
needs: prerequisite
timeout-minutes: 5
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Setup environment
uses: ./.github/workflows/rafiki/env-setup
- name: Setup hosts
run: |
echo "127.0.0.1 cloud-nine-wallet-test-backend" | sudo tee -a /etc/hosts
echo "127.0.0.1 cloud-nine-wallet-test-auth" | sudo tee -a /etc/hosts
echo "127.0.0.1 happy-life-bank-test-backend" | sudo tee -a /etc/hosts
echo "127.0.0.1 happy-life-bank-test-auth" | sudo tee -a /etc/hosts
- name: Build dependencies
run: pnpm --filter integration build:deps
- name: Run tests
run: pnpm --filter integration run-tests
node-build:
runs-on: ubuntu-latest
timeout-minutes: 5
needs: [auth, backend, frontend, token-introspection, mock-account-servicing-entity, graphql, codeql-analyze, integration-test]
steps:
- uses: actions/checkout@v4
- uses: ./.github/workflows/rafiki/env-setup
- run: pnpm build
version-generator:
runs-on: ubuntu-latest
if: startsWith(github.ref_name, 'release/v')
outputs:
version: ${{ steps.version-generator.outputs.NEW_VERSION }}
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
fetch-tags: true
- name: Configure git
run: |
git config --global user.name "github-actions[bot]"
git config --global user.email "github-actions[bot]@users.noreply.github.com"
- id: version-generator
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
VERSION_PREFIX=$(echo "${{ github.ref_name }}" | sed 's|release/||')
read major minor patch pre_release <<< $(echo "$VERSION_PREFIX" | awk -F'[.v-]' '{print $2, $3, $4, $5}')
version_search="v$major.$minor.*"
if [ -n "$pre_release" ]; then
version_search="$version_search-$pre_release"
fi
echo "VERSION_SEARCH: $version_search"
VERSION_PREFIX=$(git tag -l $version_search --sort=-taggerdate | head -n 1)
if [ -n "$VERSION_PREFIX" ]; then
read major minor patch pre_release <<< $(echo "$VERSION_PREFIX" | awk -F'[.v-]' '{print $2, $3, $4, $5}')
patch=$((patch + 1))
fi
NEW_VERSION="v${major}.${minor}.${patch}"
if [ -n "$pre_release" ]; then
NEW_VERSION="$NEW_VERSION-${pre_release}"
fi
echo "NEW_VERSION=$NEW_VERSION" >> $GITHUB_OUTPUT
echo "New version will be: $NEW_VERSION"
git tag -a $NEW_VERSION -m "$NEW_VERSION"
git push origin $NEW_VERSION
docker-build-branch:
runs-on: ubuntu-latest
needs: prerequisite
if: ${{ !startsWith(github.ref_name, 'release/v') }}
timeout-minutes: 5
strategy:
matrix:
package: [auth, backend, frontend]
steps:
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Build linux/amd64
uses: docker/build-push-action@v5
with:
push: false
platforms: linux/amd64
file: packages/${{ matrix.package }}/Dockerfile
tags: ghcr.io/${{ github.repository_owner }}/rafiki-${{ matrix.package }}:${{ github.workflow_sha }}
docker-build:
runs-on: ubuntu-latest
needs: version-generator
timeout-minutes: 5
strategy:
matrix:
package: [auth, backend, frontend]
steps:
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Build linux/amd64
if: ${{ !startsWith(github.ref_name, 'release/v') }}
uses: docker/build-push-action@v5
with:
push: false
platforms: linux/amd64
file: packages/${{ matrix.package }}/Dockerfile
tags: ghcr.io/${{ github.repository_owner }}/rafiki-${{ matrix.package }}:${{ needs.version-generator.outputs.version }}
outputs: type=docker,dest=/tmp/${{ matrix.package }}.tar
- name: Build linux/amd64 & linux/arm64
uses: docker/build-push-action@v5
with:
push: false
platforms: linux/amd64,linux/arm64
file: packages/${{ matrix.package }}/Dockerfile
tags: ghcr.io/${{ github.repository_owner }}/rafiki-${{ matrix.package }}:${{ needs.version-generator.outputs.version }}
outputs: type=docker,dest=/tmp/${{ matrix.package }}.tar
- name: Save docker image to cache
uses: actions/cache@v4
with:
path: /tmp/${{ matrix.package }}.tar
key: ${{ github.sha }}
docker-grype:
name: Docker Grype Scan
needs: docker-build
runs-on: ubuntu-latest
timeout-minutes: 5
strategy:
matrix:
package: [auth, backend, frontend]
steps:
- name: Fetch docker image from cache
uses: actions/cache/restore@v4
with:
path: /tmp/${{ matrix.package }}.tar
key: ${{ github.sha }}
- name: Scan docker image
uses: anchore/scan-action@v3
with:
image: /tmp/${{ matrix.package }}.tar
fail-build: true
only-fixed: true
severity-cutoff: high
output-format: table
docker-trivy:
name: Docker Trivy Scan
needs: [docker-build]
runs-on: ubuntu-latest
timeout-minutes: 5
strategy:
matrix:
package: [auth, backend, frontend]
steps:
- name: Fetch docker image from cache
uses: actions/cache/restore@v4
with:
path: /tmp/${{ matrix.package }}.tar
key: ${{ github.sha }}
- name: Download Trivy
run: |
curl -sfL https://raw.githubusercontent.com/aquasecurity/trivy/main/contrib/install.sh | sh -s -- -b /tmp
- name: Scan docker image
run: |
/tmp/trivy image --ignore-unfixed --format table --vuln-type os,library --exit-code 1 --severity HIGH --input /tmp/${{ matrix.package }}.tar
push:
name: Push to registry
needs: [docker-grype, docker-trivy, version-generator, node-build]
runs-on: ubuntu-latest
strategy:
matrix:
package: [auth, backend, frontend]
steps:
- name: Fetch docker image from cache
uses: actions/cache/restore@v4
with:
path: /tmp/${{ matrix.package }}.tar
key: ${{ github.sha }}
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Login to GHCR
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Load image into Docker
run: |
docker load --input /tmp/${{ matrix.package }}.tar
- name: List docker images
run: docker images
- name: Push to registry
run: |
docker push ghcr.io/${{ github.repository_owner }}/rafiki-${{ matrix.package }}:${{ needs.version-generator.outputs.version }}
generate-release:
runs-on: ubuntu-latest
needs: [push, version-generator]
steps:
- name: Checkout Code
uses: actions/checkout@v4
- name: Generate CHANGELOG data
id: changelog
uses: requarks/changelog-action@v1
with:
token: ${{ github.token }}
tag: ${{ needs.version-generator.outputs.version }}
- name: Create Release
uses: ncipollo/release-action@v1.14.0
with:
allowUpdates: true
draft: false
makeLatest: true
prerelease: endsWith(needs.version-generator.outputs.version, '-alpha')
name: ${{ needs.version-generator.outputs.version }}
body: ${{ steps.changelog.outputs.changes }}
tag: ${{ needs.version-generator.outputs.version }}
token: ${{ github.token }}