-
Notifications
You must be signed in to change notification settings - Fork 10
337 lines (291 loc) · 12.1 KB
/
ci-pr-prerelease.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
# Unique name for this workflow
name: CI on Pre-release PR
# Definition when the workflow should run
on:
workflow_dispatch:
pull_request:
types: [opened, edited, synchronize, reopened]
branches:
- prerelease/spring[2-9][0-9]
- prerelease/summer[2-9][0-9]
- prerelease/winter[2-9][0-9]
# Jobs to be executed
jobs:
format-lint-lwc-tests:
runs-on: ubuntu-latest
steps:
# Checkout the source code
- name: "Checkout source code"
uses: actions/checkout@v4
# Install Volta to enforce proper node and package manager versions
- name: "Install Volta"
uses: volta-cli/action@v4
# Cache node_modules to speed up the process
- name: "Restore node_modules cache"
id: cache-npm
uses: actions/cache@v4
with:
path: node_modules
key: npm-${{ hashFiles('**/package-lock.json') }}
restore-keys: |
npm-${{ env.cache-name }}-
npm-
# Install npm dependencies for Prettier and Jest
- name: "Install npm dependencies"
if: steps.cache-npm.outputs.cache-hit != 'true'
run: npm ci
env:
GHCR_TOKEN: ${{ secrets.GHCR_ACCESS_TOKEN }}
# Prettier formatting
- name: "Code formatting verification with Prettier"
run: npm run prettier:verify
# Lint LWC / Aura
- name: "Lint Lightning Web Components / Aura Components"
run: npm run lint
# LWC unit tests
- name: "Unit test Lightning Web Components"
run: npm run test:unit:coverage
# Upload code coverage data
- name: "Upload code coverage for LWC to Codecov.io"
uses: codecov/codecov-action@v4
with:
flags: LWC
token: ${{ secrets.CODECOV_TOKEN }}
scratch-org-test:
runs-on: ubuntu-latest
needs: format-lint-lwc-tests
if: ${{ github.actor != 'dependabot[bot]' }}
steps:
# Checkout the source code
- name: "Checkout source code"
uses: actions/checkout@v4
# Install Volta to enforce proper node and package manager versions
- name: "Install Volta"
uses: volta-cli/action@v4
# Cache node_modules to speed up the process
- name: "Restore node_modules cache"
id: cache-npm
uses: actions/cache@v4
with:
path: node_modules
key: npm-${{ hashFiles('**/package-lock.json') }}
restore-keys: |
npm-${{ env.cache-name }}-
npm-
# Install npm dependencies for Prettier and Jest
- name: "Install npm dependencies"
if: steps.cache-npm.outputs.cache-hit != 'true'
run: npm ci
# Prep
- name: "Prepare repo"
run: npm run prep
# Run PMD scan
- name: "Run PMD scan for sfGpsDs"
uses: pmd/[email protected]
id: pmd-sf-gps-ds
with:
sourcePath: "sfGpsDs"
rulesets: "ruleset.xml"
# Check for PMD violations
- name: "Check for PMD violations"
if: steps.pmd-sf-gps-ds.outputs.violations != 0
run: exit 1
# Run PMD scan
- name: "Run PMD scan for sfGpsDsAuNsw"
uses: pmd/[email protected]
id: pmd-sf-gps-ds-au-nsw
with:
sourcePath: "sfGpsDsAuNsw"
rulesets: "ruleset.xml"
# Check for PMD violations
- name: "Check for PMD violations"
if: steps.pmd-sf-gps-ds-au-nsw.outputs.violations != 0
run: exit 1
# Run PMD scan
- name: "Run PMD scan for sfGpsDsAuNswS"
uses: pmd/[email protected]
id: pmd-sf-gps-ds-au-nsw-s
with:
sourcePath: "sfGpsDsAuNswS"
rulesets: "ruleset.xml"
# Check for PMD violations
- name: "Check for PMD violations"
if: steps.pmd-sf-gps-ds-au-nsw-s.outputs.violations != 0
run: exit 1
# Run PMD scan
- name: "Run PMD scan for sfGpsDsAuVic1"
uses: pmd/[email protected]
id: pmd-sf-gps-ds-au-vic1
with:
sourcePath: "sfGpsDsAuVic"
rulesets: "ruleset.xml"
# Check for PMD violations
- name: "Check for PMD violations"
if: steps.pmd-sf-gps-ds-au-vic1.outputs.violations != 0
run: exit 1
# Run PMD scan
- name: "Run PMD scan for sfGpsDsAuVic2"
uses: pmd/[email protected]
id: pmd-sf-gps-ds-au-vic2
with:
sourcePath: "sfGpsDsAuVic2"
rulesets: "ruleset.xml"
# Check for PMD violations
- name: "Check for PMD violations"
if: steps.pmd-sf-gps-ds-au-vic2.outputs.violations != 0
run: exit 1
# Run PMD scan
- name: "Run PMD scan for sfGpsDsFrGov"
uses: pmd/[email protected]
id: pmd-sf-gps-ds-fr-gov
with:
sourcePath: "sfGpsDsFrGov"
rulesets: "ruleset.xml"
# Check for PMD violations
- name: "Check for PMD violations"
if: steps.pmd-sf-gps-ds-fr-gov.outputs.violations != 0
run: exit 1
# Run PMD scan
- name: "Run PMD scan for sfGpsDsUkGov"
uses: pmd/[email protected]
id: pmd-sf-gps-ds-uk-gov
with:
sourcePath: "sfGpsDsUkGov"
rulesets: "ruleset.xml"
# Check for PMD violations
- name: "Check for PMD violations"
if: steps.pmd-sf-gps-ds-uk-gov.outputs.violations != 0
run: exit 1
# Install Salesforce CLI
- name: "Install Salesforce CLI latest"
run: |
npm install @salesforce/cli --location=global
nodeInstallPath=$(npm config get prefix)
echo "$nodeInstallPath/bin" >> $GITHUB_PATH
# Confirm version Salesforce CLI
- name: "Confirm Salesforce CLI version"
run: |
sfdx --version
# Store secret for dev hub
- name: "Populate auth file with DEVHUB_SFDX_URL secret"
shell: bash
run: |
echo ${{ secrets.DEVHUB_SFDX_URL}} > ./DEVHUB_SFDX_URL.txt
secretFileSize=$(wc -c "./DEVHUB_SFDX_URL.txt" | awk '{print $1}')
if [ $secretFileSize == 1 ]; then
echo "Missing DEVHUB_SFDX_URL secret. Is this workflow running on a fork?";
exit 1;
fi
# Authenticate dev hub
- name: "Authenticate Dev Hub"
run: sfdx auth:sfdxurl:store -f ./DEVHUB_SFDX_URL.txt -a devhub -d
# Create scratch org
- name: "Create scratch org"
run: sfdx org create scratch -f config/project-scratch-def.json --alias=scratch-org --set-default --duration-days=1
# Deploy omnistudio to scratch org
- name: "Deploy Omnistudio"
run: sfdx package install --package=${{ vars.OMNISTUDIO_PACKAGEID }} --target-org=scratch-org --wait=20 --no-prompt --security-type=AllUsers
# Generate css from scss
- name: "Automatically generate css"
run: npm run cssgen
# Generate omnistudio versions of source
- name: "Automatically generate Omnistudio source"
run: npm run osfilegen
# Deploy source to scratch org
- name: "Push source to scratch org"
run: |
sfdx project deploy start --source-dir sfGpsDs --target-org=scratch-org
sfdx project deploy start --source-dir sfGpsDsAuNsw --target-org=scratch-org
sfdx project deploy start --source-dir sfGpsDsAuNswS --target-org=scratch-org
sfdx project deploy start --source-dir sfGpsDsAuVic --target-org=scratch-org
sfdx project deploy start --source-dir sfGpsDsAuVic2 --target-org=scratch-org
sfdx project deploy start --source-dir sfGpsDsUkGov --target-org=scratch-org
sfdx project deploy start --source-dir sfGpsDsFrGov --target-org=scratch-org
# Assign permissionset
# - name: 'Assign permissionset to default user'
# run: sfdx force:user:permset:assign -n recipes
# Import sample data
# - name: 'Import sample data'
# run: sfdx force:data:tree:import -p ./data/data-plan.json
# Run Apex tests in scratch org
- name: "Run Apex tests"
run: sfdx force apex test run --code-coverage --result-format=human --output-dir=./tests/apex --wait=20 --test-level=RunLocalTests
# Delete temporary test file that Codecov is unable to parse
#- name: "Delete coverage file (temporary step)"
# run: rm ./tests/apex/test-result-707*-codecoverage.json
# Upload code coverage data
- name: "Upload code coverage for Apex to Codecov.io"
uses: codecov/codecov-action@v4
with:
flags: Apex
token: ${{ secrets.CODECOV_TOKEN }}
# Housekeeping
- name: "Delete scratch org"
if: always()
run: sfdx org delete scratch --no-prompt --target-org=scratch-org
trigger-packaging:
runs-on: ubuntu-latest
needs: scratch-org-test
steps:
# Checkout the source code
- name: "Checkout source code"
uses: actions/checkout@v4
# Check for package changes using git diff
- name: "Check for package changes"
id: checkForChanges
run: |
git fetch origin ${{ github.event.before }} --depth=1
changedPaths=$( git diff-tree --name-only ${{ github.event.before }} $GITHUB_SHA )
set +e
hasChanges='false'
hasChangesSfGpsDs='false'
hasChangesSfGpsDsAuNsw='false'
hasChangesSfGpsDsAuNswS='false'
hasChangesSfGpsDsAuVic1='false'
hasChangesSfGpsDsAuVic2='false'
hasChangesSfGpsDsFrGov='false'
hasChangesSfGpsDsUkGov='false'
if [ $(echo "$changedPaths" | grep -c '^sfGpsDs$') == 1 ]; then
hasChanges='true'
hasChangesSfGpsDs='true'
fi
if [ $(echo "$changedPaths" | grep -c '^sfGpsDsAuNsw$') == 1 ]; then
hasChanges='true'
hasChangesSfGpsDsAuNsw='true'
fi
if [ $(echo "$changedPaths" | grep -c '^sfGpsDsAuNswS$') == 1 ]; then
hasChanges='true'
hasChangesSfGpsDsAuNswS='true'
fi
if [ $(echo "$changedPaths" | grep -c '^sfGpsDsAuVic$') == 1 ]; then
hasChanges='true'
hasChangesSfGpsDsAuVic1='true'
fi
if [ $(echo "$changedPaths" | grep -c '^sfGpsDsAuVic2$') == 1 ]; then
hasChanges='true'
hasChangesSfGpsDsAuVic2='true'
fi
if [ $(echo "$changedPaths" | grep -c '^sfGpsDsFrGov$') == 1 ]; then
hasChanges='true'
hasChangesSfGpsDsFrGov='true'
fi
if [ $(echo "$changedPaths" | grep -c '^sfGpsDsUkGov$') == 1 ]; then
hasChanges='true'
hasChangesSfGpsDsUkGov='true'
fi
echo "hasChanges=$hasChanges" >> $GITHUB_OUTPUT
echo "hasChangesSfGpsDs=$hasChangesSfGpsDs" >> $GITHUB_OUTPUT
echo "hasChangesSfGpsDsAuNsw=$hasChangesSfGpsDsAuNsw" >> $GITHUB_OUTPUT
echo "hasChangesSfGpsDsAuNswS=$hasChangesSfGpsDsAuNswS" >> $GITHUB_OUTPUT
echo "hasChangesSfGpsDsAuVic1=$hasChangesSfGpsDsAuVic1" >> $GITHUB_OUTPUT
echo "hasChangesSfGpsDsAuVic2=$hasChangesSfGpsDsAuVic2" >> $GITHUB_OUTPUT
echo "hasChangesSfGpsDsFrGov=$hasChangesSfGpsDsFrGov" >> $GITHUB_OUTPUT
echo "hasChangesSfGpsDsUkGov=$hasChangesSfGpsDsUkGov" >> $GITHUB_OUTPUT
# Trigger packaging workflow if needed
- name: "Trigger packaging workflow if needed"
uses: peter-evans/repository-dispatch@v3
if: ${{ steps.checkForChanges.outputs.hasChanges == 'true' }}
with:
token: ${{ secrets.BOT_ACCESS_TOKEN }}
event-type: start-packaging-pr-prerelease
client-payload: '{ "ref": "${{ github.ref }}", "sha": "${{ github.sha }}", "sfGpsDs": "${{ steps.checkForChanges.outputs.hasChangesSfGpsDs }}", "sfGpsDsAuNsw": "${{ steps.checkForChanges.outputs.hasChangesSfGpsDsAuNsw }}", "sfGpsDsAuNswS": "${{ steps.checkForChanges.outputs.hasChangesSfGpsDsAuNswS }}", "sfGpsDsAuVic1": "${{ steps.checkForChanges.outputs.hasChangesSfGpsDsAuVic1 }}", "sfGpsDsAuVic2": "${{ steps.checkForChanges.outputs.hasChangesSfGpsDsAuVic2 }}", "sfGpsDsFrGov": "${{ steps.checkForChanges.outputs.hasChangesSfGpsDsFrGov }}", "sfGpsDsUkGov": "${{ steps.checkForChanges.outputs.hasChangesSfGpsDsUkGov }}" }'