-
Notifications
You must be signed in to change notification settings - Fork 144
340 lines (296 loc) · 13.1 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
# WARNING! Conditionals are set as variables to minimize repetitive checks.
# However, this results in the variables being the *string* values "true" or "false".
# As a result, you must always explicitly check for those strings. For example,
# ${{ env.DEVELOP }} will ALWAYS evaluate as true; to achieve the expected result
# you must check ${{ env.DEVELOP == 'true' }}. There's probably a better way to DRY,
# but this is what we have for now.
name: SalesforceCommerceCloud/pwa-kit/test
on:
# PRs from forks trigger `pull_request`, but do NOT have access to secrets.
# More info:
# https://docs.github.com/en/actions/using-workflows/events-that-trigger-workflows#workflows-in-forked-repositories-1
# https://securitylab.github.com/research/github-actions-preventing-pwn-requests/
# https://docs.github.com/en/actions/managing-workflow-runs/approving-workflow-runs-from-public-forks
pull_request: # Default: opened, reopened, synchronize (head branch updated)
merge_group: # Trigger GA workflow when a pull request is added to a merge queue.
push:
branches:
- develop
# TODO: Should we run on all pushes to release branches, or should we run on GitHub releases?
- 'release-*'
schedule:
# Run every day at 12am (PST) - cron uses UTC times
- cron: '0 8 * * *'
env:
IS_NOT_FORK: ${{ github.event_name == 'push' || github.event.pull_request.head.repo.full_name == github.repository }}
DEVELOP: ${{ (github.event_name == 'push' || github.event.pull_request.head.repo.full_name == github.repository) && (github.head_ref || github.ref_name) == 'develop' }}
RELEASE: ${{ (github.event_name == 'push' || github.event.pull_request.head.repo.full_name == github.repository) && startsWith(github.head_ref || github.ref_name, 'release-') }}
jobs:
pwa-kit:
strategy:
fail-fast: false
matrix:
node: [16, 18, 20]
npm: [8, 9, 10]
exclude: # node 16 is not compatible with npm 10
- node: 16
npm: 10
runs-on: ubuntu-latest
env:
# The "default" npm is the one that ships with a given version of node.
# For more: https://nodejs.org/en/download/releases/
# (We also use this env var for making sure a step runs once for the current node version)
# Note: For node 18, the default was npm 9 until v18.19.0, when it became npm 10
IS_DEFAULT_NPM: ${{ (matrix.node == 16 && matrix.npm == 8) || (matrix.node == 18 && matrix.npm == 10) || (matrix.node == 20 && matrix.npm == 10) }}
# The current recommended version for Managed Runtime:
# https://developer.salesforce.com/docs/commerce/pwa-kit-managed-runtime/guide/upgrade-node-version.html
IS_MRT_NODE: ${{ matrix.node == 20 && matrix.npm == 10 }}
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Setup Node
uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node }}
cache: npm
- name: Update NPM version
if: env.IS_DEFAULT_NPM == 'false'
run: |-
npm install -g npm@${{ matrix.npm }}
- name: Setup Ubuntu Machine
uses: "./.github/actions/setup_ubuntu"
- name: Run unit tests
uses: "./.github/actions/unit_tests"
- name: Run bundlesize test
uses: "./.github/actions/bundle_size_test"
- name: Smoke test scripts
if: env.IS_DEFAULT_NPM == 'true'
uses: "./.github/actions/smoke_tests"
- name: Create MRT credentials file
if: env.IS_NOT_FORK == 'true' && env.IS_MRT_NODE == 'true' && ( env.DEVELOP == 'true' || env.RELEASE == 'true' )
uses: "./.github/actions/create_mrt"
with:
mobify_user: ${{ secrets.MOBIFY_CLIENT_USER }}
mobify_api_key: ${{ secrets.MOBIFY_CLIENT_API_KEY }}
- name: Push Bundle to MRT (Development)
if: env.IS_NOT_FORK == 'true' && env.IS_MRT_NODE == 'true' && env.DEVELOP == 'true'
uses: "./.github/actions/push_to_mrt"
with:
CWD: "./packages/template-retail-react-app"
TARGET: staging
- name: Push Bundle to MRT (Production)
if: env.IS_NOT_FORK == 'true' && env.IS_MRT_NODE == 'true' && env.RELEASE == 'true'
uses: "./.github/actions/push_to_mrt"
with:
CWD: "./packages/template-retail-react-app"
TARGET: production
- name: Push Bundle to MRT (Commerce SDK React)
if: env.IS_NOT_FORK == 'true' && env.IS_MRT_NODE == 'true' && env.DEVELOP == 'true'
uses: "./.github/actions/push_to_mrt"
with:
CWD: "./packages/test-commerce-sdk-react"
TARGET: commerce-sdk-react
- name: Check Repository Clean
if: env.IS_NOT_FORK == 'true' && env.IS_DEFAULT_NPM == 'true'
uses: "./.github/actions/check_clean"
- name: Publish to NPM
if: env.IS_NOT_FORK == 'true' && env.IS_MRT_NODE == 'true' && env.RELEASE == 'true'
uses: "./.github/actions/publish_to_npm"
with:
NODE_AUTH_TOKEN: ${{ secrets.NODE_AUTH_TOKEN }}
- name: Send GitHub Action data to Slack workflow (PWA Kit)
id: slack
if: env.IS_NOT_FORK == 'true' && env.IS_DEFAULT_NPM == 'true' && env.DEVELOP == 'true' && failure()
uses: slackapi/[email protected]
with:
payload: |
{
"test": "A 'testNode${{ matrix.node }}' task has failed."
}
env:
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }}
pwa-kit-windows:
strategy:
fail-fast: false
matrix:
node: [16, 18, 20]
npm: [8, 9, 10]
exclude: # node 16 is not compatible with npm 10
- node: 16
npm: 10
env:
# The "default" npm is the one that ships with a given version of node.
# For more: https://nodejs.org/en/download/releases/
# (We also use this env var for making sure a step runs once for the current node version)
# Note: For node 18, the default was npm 9 until v18.19.0, when it became npm 10
IS_DEFAULT_NPM: ${{ (matrix.node == 16 && matrix.npm == 8) || (matrix.node == 18 && matrix.npm == 10) || (matrix.node == 20 && matrix.npm == 10) }}
# The current recommended version for Managed Runtime:
# https://developer.salesforce.com/docs/commerce/pwa-kit-managed-runtime/guide/upgrade-node-version.html
IS_MRT_NODE: ${{ matrix.node == 20 && matrix.npm == 10 }}
runs-on: windows-latest
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Setup Node
uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node }}
cache: npm
- name: Update NPM version
if: env.IS_DEFAULT_NPM == 'false'
run: |-
npm install -g npm@${{ matrix.npm }}
- name: Setup Windows Machine
uses: "./.github/actions/setup_windows"
- name: Run tests
uses: "./.github/actions/unit_tests"
# TODO: The generated workflow is identical to the generated-windows workflow,
# with a few extra steps. Can the workflows be merged? (Add `os` to the matrix?)
generated:
strategy:
fail-fast: false
matrix:
template: [retail-react-app-test-project, retail-react-app-demo, express-minimal-test-project, typescript-minimal-test-project]
runs-on: ubuntu-latest
env:
IS_TEMPLATE_FROM_RETAIL_REACT_APP: ${{ matrix.template == 'retail-react-app-test-project' || matrix.template == 'retail-react-app-demo' }}
PROJECT_DIR: generated-${{ matrix.template }}
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Setup Node
uses: actions/setup-node@v3
with:
node-version: 20
- name: Setup Ubuntu Machine
uses: "./.github/actions/setup_ubuntu"
- name: Generate ${{ matrix.template }} project
run: |-
node packages/pwa-kit-create-app/scripts/create-mobify-app-dev.js --outputDir ${{ env.PROJECT_DIR }}
env:
GENERATOR_PRESET: ${{ matrix.template }}
timeout-minutes: 8
- name: Lint the generated project
if: env.IS_TEMPLATE_FROM_RETAIL_REACT_APP == 'true'
uses: "./.github/actions/linting"
with:
cwd: ${{ env.PROJECT_DIR }}
- name: Run unit tests
if: env.IS_TEMPLATE_FROM_RETAIL_REACT_APP == 'true'
uses: "./.github/actions/unit_tests"
with:
cwd: ${{ env.PROJECT_DIR }}
- name: Run smoke tests
if: env.IS_TEMPLATE_FROM_RETAIL_REACT_APP == 'true'
uses: "./.github/actions/smoke_tests"
with:
dir: ${{ env.PROJECT_DIR }}
- name: Count Generated Project Dependencies
id: count_deps
if: env.IS_TEMPLATE_FROM_RETAIL_REACT_APP == 'true'
uses: "./.github/actions/count_deps"
- name: Store Verdaccio logfile artifact
uses: actions/upload-artifact@v3
with:
path: packages/pwa-kit-create-app/local-npm-repo/verdaccio.log
# TODO: Ticket W-12425059. Revisit Snyk CLI integration to monitor manifest files on generated projects.
# TODO: Update the SNYK_TOKEN stored in GitHub with a token generated from the proper Snyk org.
# - name: Audit Generated Project
# if: env.IS_NOT_FORK == 'true' && env.IS_TEMPLATE_FROM_RETAIL_REACT_APP == 'true' && env.DEVELOP == 'true'
# uses: "./.github/actions/snyk"
# with:
# snyk_token: ${{ secrets.SNYK_TOKEN }}
- name: Send metrics to Datadog
if: env.IS_NOT_FORK == 'true' && env.IS_TEMPLATE_FROM_RETAIL_REACT_APP == 'true'
uses: "./.github/actions/datadog"
with:
datadog_api_key: ${{ secrets.DATADOG_API_KEY }}
# TODO: The way this is set is a little bit magic - can it be cleaned up?
TOTAL_PACKAGES: $TOTAL_PACKAGES
- name: Create MRT credentials file
if: env.IS_NOT_FORK == 'true' && env.IS_TEMPLATE_FROM_RETAIL_REACT_APP == 'true' && env.DEVELOP == 'true'
uses: "./.github/actions/create_mrt"
with:
mobify_user: ${{ secrets.MOBIFY_CLIENT_USER }}
mobify_api_key: ${{ secrets.MOBIFY_CLIENT_API_KEY }}
- name: Push Bundle to MRT
if: env.IS_NOT_FORK == 'true' && env.DEVELOP == 'true' && matrix.template == 'retail-react-app-test-project'
uses: "./.github/actions/push_to_mrt"
with:
CWD: ${{ env.PROJECT_DIR }}
TARGET: generated-pwa
- name: Send GitHub Action data to Slack workflow (Generated)
id: slack
if: env.IS_NOT_FORK == 'true' && env.IS_TEMPLATE_FROM_RETAIL_REACT_APP == 'true' && env.DEVELOP == 'true' && failure()
uses: slackapi/[email protected]
with:
payload: |
{
"message": "A 'generated ${{ matrix.template }}' task has failed."
}
env:
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }}
generated-windows:
strategy:
fail-fast: false
matrix:
template: [retail-react-app-test-project, retail-react-app-demo, express-minimal-test-project, typescript-minimal-test-project]
runs-on: windows-latest
env:
IS_TEMPLATE_FROM_RETAIL_REACT_APP: ${{ matrix.template == 'retail-react-app-test-project' || matrix.template == 'retail-react-app-demo' }}
PROJECT_DIR: generated-${{ matrix.template }}
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Setup Node
uses: actions/setup-node@v3
with:
node-version: 20
- name: Setup Windows Machine
uses: "./.github/actions/setup_windows"
- name: Generate ${{ matrix.template }} project
run: |-
node packages/pwa-kit-create-app/scripts/create-mobify-app-dev.js --outputDir ${{ env.PROJECT_DIR }}
env:
GENERATOR_PRESET: ${{ matrix.template }}
timeout-minutes: 7
- name: Lint the generated project
if: env.IS_TEMPLATE_FROM_RETAIL_REACT_APP == 'true'
uses: "./.github/actions/linting"
with:
cwd: ${{ env.PROJECT_DIR }}
- name: Run unit tests
if: env.IS_TEMPLATE_FROM_RETAIL_REACT_APP == 'true'
uses: "./.github/actions/unit_tests"
with:
cwd: ${{ env.PROJECT_DIR }}
- name: Run smoke tests
if: env.IS_TEMPLATE_FROM_RETAIL_REACT_APP == 'true'
uses: "./.github/actions/smoke_tests"
with:
dir: ${{ env.PROJECT_DIR }}
- name: Count Generated Project Dependencies
if: env.IS_TEMPLATE_FROM_RETAIL_REACT_APP == 'true'
uses: "./.github/actions/count_deps"
- name: Store Verdaccio logfile artifact
uses: actions/upload-artifact@v3
with:
path: packages/pwa-kit-create-app/local-npm-repo/verdaccio.log
lighthouse:
strategy:
fail-fast: false
matrix:
node: [18] # Should match node version supported by MRT.
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Setup Node
uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node }}
cache: npm
- name: Setup Ubuntu Machine
uses: "./.github/actions/setup_ubuntu"
- name: Run Lighthouse CI on the PWA
uses: "./.github/actions/lighthouse_ci"