-
Notifications
You must be signed in to change notification settings - Fork 3.9k
341 lines (317 loc) · 12.5 KB
/
test.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
name: Testing Pipeline
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
on:
pull_request:
jobs:
dependency-review:
name: Dependency review
runs-on: ubuntu-latest
steps:
- name: 'Checkout Repository'
uses: actions/checkout@v3
- name: 'Dependency Review'
uses: actions/dependency-review-action@v3
spellcheck:
name: Spell check
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: streetsidesoftware/cspell-action@v2
get-affected:
name: Get Affected Packages
runs-on: ubuntu-latest
outputs:
test-unit: ${{ steps.get-projects-arrays.outputs.test-unit }}
test-e2e: ${{ steps.get-projects-arrays.outputs.test-e2e }}
test-e2e-ee: ${{ steps.get-projects-arrays.outputs.test-e2e-ee }}
test-cypress: ${{ steps.get-projects-arrays.outputs.test-cypress }}
test-providers: ${{ steps.get-projects-arrays.outputs.test-providers }}
test-packages: ${{ steps.get-projects-arrays.outputs.test-packages }}
test-libs: ${{ steps.get-projects-arrays.outputs.test-libs }}
permissions:
contents: read
packages: write
deployments: write
id-token: write
steps:
# Get current branch name
- name: Get branch name
id: branch-name
uses: tj-actions/[email protected]
# Get base branch name to compare with. Base branch on a PR, "main" branch on pushing.
- name: Get base branch name
id: get-base-branch-name
run: |
if [[ "${{github.event.pull_request.base.ref}}" != "" ]]; then
echo "::set-output name=branch::${{github.event.pull_request.base.ref}}"
else
echo "::set-output name=branch::main"
fi
- uses: actions/checkout@v3
with:
fetch-depth: 0
- uses: ./.github/actions/setup-project
with:
slim: 'true'
# Configure Nx to be able to detect changes between branches when we are in a PR
- name: Derive appropriate SHAs for base and head for `nx affected` commands
uses: nrwl/nx-set-shas@v2
with:
main-branch-name: ${{steps.get-base-branch-name.outputs.branch}}
- name: Get affected
id: get-projects-arrays
# When not in a PR and the current branch is main, pass --all flag. Otherwise pass the base branch
run: |
if [[ "${{github.event.pull_request.base.ref}}" == "" && "${{steps.branch-name.outputs.current_branch}}" == "main" ]]; then
echo "Running ALL"
echo "::set-output name=test-unit::$(pnpm run get-affected test:unit --all | tail -n +5)"
echo "::set-output name=test-e2e::$(pnpm run get-affected test:e2e --all | tail -n +5)"
echo "::set-output name=test-e2e-ee::$(pnpm run get-affected test:e2e:ee --all | tail -n +5)"
echo "::set-output name=test-cypress::$(pnpm run get-affected cypress:run --all | tail -n +5)"
echo "::set-output name=test-providers::$(pnpm run get-affected test --all providers | tail -n +5)"
echo "::set-output name=test-packages::$(pnpm run get-affected test --all packages | tail -n +5)"
echo "::set-output name=test-libs::$(pnpm run get-affected test --all libs | tail -n +5)"
else
echo "Running PR origin/${{steps.get-base-branch-name.outputs.branch}}"
echo "::set-output name=test-unit::$(pnpm run get-affected test origin/${{steps.get-base-branch-name.outputs.branch}} | tail -n +5)"
echo "::set-output name=test-e2e::$(pnpm run get-affected test:e2e origin/${{steps.get-base-branch-name.outputs.branch}} | tail -n +5)"
echo "::set-output name=test-e2e-ee::$(pnpm run get-affected test:e2e:ee origin/${{steps.get-base-branch-name.outputs.branch}} | tail -n +5)"
echo "::set-output name=test-cypress::$(pnpm run get-affected cypress:run origin/${{steps.get-base-branch-name.outputs.branch}} | tail -n +5)"
echo "::set-output name=test-providers::$(pnpm run get-affected test origin/${{steps.get-base-branch-name.outputs.branch}} providers | tail -n +5)"
echo "::set-output name=test-packages::$(pnpm run get-affected test origin/${{steps.get-base-branch-name.outputs.branch}} packages | tail -n +5)"
echo "::set-output name=test-libs::$(pnpm run get-affected test origin/${{steps.get-base-branch-name.outputs.branch}} libs | tail -n +5)"
fi
test_web:
name: Test Web Cypress
needs: [ get-affected ]
if: ${{ contains(fromJson(needs.get-affected.outputs.test-cypress), '@novu/web') }}
uses: ./.github/workflows/reusable-web-e2e.yml
secrets: inherit
test_widget:
name: Test Widget Cypress
needs: [ get-affected ]
uses: ./.github/workflows/reusable-widget-e2e.yml
if: ${{ contains(fromJson(needs.get-affected.outputs.test-cypress), '@novu/widget') || contains(fromJson(needs.get-affected.outputs.test-unit), '@novu/notification-center') }}
secrets: inherit
build_docker_api:
name: Build Docker API
runs-on: ubuntu-latest
timeout-minutes: 80
needs: [ get-affected ]
if: ${{ contains(fromJson(needs.get-affected.outputs.test-e2e), '@novu/api') }}
permissions:
contents: read
packages: write
deployments: write
id-token: write
strategy:
matrix:
name: [ 'novu/api', 'novu/api-ee' ]
steps:
- uses: actions/checkout@v3
- uses: ./.github/actions/setup-project
- uses: ./.github/actions/setup-redis-cluster
- uses: ./.github/actions/docker/build-api
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
fork: ${{ github.event.pull_request.head.repo.fork }}
docker_name: ${{ matrix.name }}
test_providers:
name: Unit Test Providers
runs-on: ubuntu-latest
needs: [get-affected]
if: ${{ fromJson(needs.get-affected.outputs.test-providers)[0] }}
timeout-minutes: 80
steps:
- run: echo '${{ needs.get-affected.outputs.test-providers }}'
- uses: actions/checkout@v3
- uses: ./.github/actions/setup-project
with:
slim: 'true'
- uses: mansagroup/nrwl-nx-action@v3
with:
targets: lint,build,test
parallel: 5
projects: ${{join(fromJson(needs.get-affected.outputs.test-providers), ',')}}
test_packages:
name: Unit Test Packages
runs-on: ubuntu-latest
needs: [get-affected]
if: ${{ fromJson(needs.get-affected.outputs.test-packages)[0] }}
timeout-minutes: 80
permissions:
contents: read
packages: write
deployments: write
id-token: write
steps:
- run: echo '${{ needs.get-affected.outputs.test-packages }}'
- uses: actions/checkout@v3
- uses: ./.github/actions/setup-project
with:
slim: 'true'
- uses: ./.github/actions/setup-redis-cluster
- uses: mansagroup/nrwl-nx-action@v3
env:
LOGGING_LEVEL: 'info'
with:
targets: lint,build,test
projects: ${{join(fromJson(needs.get-affected.outputs.test-packages), ',')}}
test_libs:
name: Unit Test Libs
runs-on: ubuntu-latest
needs: [get-affected]
if: ${{ fromJson(needs.get-affected.outputs.test-libs)[0] }}
timeout-minutes: 80
steps:
- run: echo '${{ needs.get-affected.outputs.test-libs }}'
- uses: actions/checkout@v3
- uses: ./.github/actions/setup-project
- uses: mansagroup/nrwl-nx-action@v3
with:
targets: lint,build,test
projects: ${{join(fromJson(needs.get-affected.outputs.test-libs), ',')}}
test_e2e:
name: Test E2E
runs-on: ubuntu-latest
needs: [get-affected]
if: ${{ fromJson(needs.get-affected.outputs.test-e2e)[0] }}
timeout-minutes: 80
strategy:
# One job for each different project and node version
matrix:
projectName: ${{ fromJson(needs.get-affected.outputs.test-e2e) }}
permissions:
contents: read
packages: write
deployments: write
id-token: write
steps:
- run: echo ${{ matrix.projectName }}
- uses: actions/checkout@v3
- uses: ./.github/actions/setup-project
- uses: ./.github/actions/setup-redis-cluster
- uses: mansagroup/nrwl-nx-action@v3
name: Lint and build
with:
targets: lint,build
projects: ${{matrix.projectName}}
- uses: ./.github/actions/start-localstack
- uses: ./.github/actions/run-worker
if: ${{matrix.projectName != '@novu/worker' }}
with:
launch_darkly_sdk_key: ${{ secrets.LAUNCH_DARKLY_SDK_KEY }}
- uses: mansagroup/nrwl-nx-action@v3
name: Running the E2E tests
env:
LAUNCH_DARKLY_SDK_KEY: ${{ secrets.LAUNCH_DARKLY_SDK_KEY }}
with:
targets: test:e2e
projects: ${{matrix.projectName}}
check_submodule_token:
name: Check if the secret exists or not.
runs-on: ubuntu-latest
outputs:
has_token: ${{ steps.secret-check.outputs.has_token }}
steps:
- name: Check if secret exists
id: secret-check
run: |
if [[ -n "${{ secrets.SUBMODULES_TOKEN }}" ]]; then
echo "::set-output name=has_token::true"
else
echo "::set-output name=has_token::false"
fi
test_e2e_ee:
name: Test E2E EE
runs-on: ubuntu-latest
needs: [get-affected, check_submodule_token]
if: ${{ fromJson(needs.get-affected.outputs.test-e2e-ee)[0] && needs.check_submodule_token.outputs.has_token == 'true' }}
timeout-minutes: 80
strategy:
# One job for each different project and node version
matrix:
projectName: ${{ fromJson(needs.get-affected.outputs.test-e2e-ee) }}
permissions:
contents: read
packages: write
deployments: write
id-token: write
steps:
- run: echo ${{ matrix.projectName }}
- uses: actions/checkout@v3
- uses: ./.github/actions/checkout-submodules
with:
submodule_token: ${{ secrets.SUBMODULES_TOKEN }}
submodule_branch: "next"
- uses: ./.github/actions/setup-project
- uses: ./.github/actions/setup-redis-cluster
- uses: mansagroup/nrwl-nx-action@v3
name: Lint and build
with:
targets: lint,build
projects: ${{matrix.projectName}}
- uses: ./.github/actions/start-localstack
- uses: ./.github/actions/run-worker
if: ${{matrix.projectName == '@novu/api' }}
with:
launch_darkly_sdk_key: ${{ secrets.LAUNCH_DARKLY_SDK_KEY }}
- uses: mansagroup/nrwl-nx-action@v3
name: Running the E2E tests
env:
LAUNCH_DARKLY_SDK_KEY: ${{ secrets.LAUNCH_DARKLY_SDK_KEY }}
GOOGLE_OAUTH_CLIENT_ID: ${{ secrets.GOOGLE_OAUTH_CLIENT_ID }}
GOOGLE_OAUTH_CLIENT_SECRET: ${{ secrets.GOOGLE_OAUTH_CLIENT_SECRET }}
CI_EE_TEST: true
with:
targets: test:e2e:ee
projects: ${{matrix.projectName}}
test_unit:
name: Unit Test
runs-on: ubuntu-latest
needs: [get-affected]
if: ${{ fromJson(needs.get-affected.outputs.test-unit)[0] }}
timeout-minutes: 80
strategy:
# One job for each different project and node version
matrix:
projectName: ${{ fromJson(needs.get-affected.outputs.test-unit) }}
permissions:
contents: read
packages: write
deployments: write
id-token: write
steps:
- run: echo ${{ matrix.projectName }}
- uses: actions/checkout@v3
- uses: ./.github/actions/setup-project
with:
# Don't run redis and etc... for other unit tests
slim: ${{ !contains(matrix.projectName, '@novu/api') && !contains(matrix.projectName, '@novu/worker') && !contains(matrix.projectName, '@novu/ws') && !contains(matrix.projectName, '@novu/inbound-mail')}}
- uses: ./.github/actions/setup-redis-cluster
- uses: mansagroup/nrwl-nx-action@v3
name: Lint and build and test
with:
targets: lint,build,test
projects: ${{matrix.projectName}}
validate_swagger:
name: Validate Swagger
runs-on: ubuntu-latest
needs: [get-affected]
if: ${{ fromJson(needs.get-affected.outputs.test-unit)[0] }}
timeout-minutes: 10
permissions:
contents: read
packages: write
deployments: write
id-token: write
steps:
- uses: actions/checkout@v3
- uses: ./.github/actions/setup-project
- uses: ./.github/actions/setup-redis-cluster
- uses: ./.github/actions/run-api
with:
launch_darkly_sdk_key: ${{ secrets.LAUNCH_DARKLY_SDK_KEY }}
- uses: ./.github/actions/validate-swagger