-
Notifications
You must be signed in to change notification settings - Fork 98
303 lines (258 loc) · 14 KB
/
Copy pathci.yml
File metadata and controls
303 lines (258 loc) · 14 KB
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
# Unique name for this workflow
name: CI
# Definition when the workflow should run
on:
workflow_dispatch:
push:
branches:
- main
paths-ignore:
- 'sfdx-project.json'
- 'README.md'
# Jobs to be executed
jobs:
format-lint-lwc-tests:
runs-on: trailheadapps-Ubuntu
steps:
# Checkout the source code
- name: 'Checkout source code'
uses: actions/checkout@v4
# Check for hardcoded username in XP cloud config
- name: 'Check for hardcoded username in XP cloud config'
run: |
fileToCheck="cc-site/main/default/sites/Coral_Cloud.site-meta.xml"
if grep -q siteAdmin $fileToCheck; then
echo "siteAdmin tag detected in $fileToCheck. Remove the tag to fix this.";
exit 1;
fi
if grep -q siteGuestRecordDefaultOwner $fileToCheck; then
echo "siteGuestRecordDefaultOwner tag detected in $fileToCheck. Remove the tag to fix this.";
exit 1;
fi
# 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: HUSKY=0 npm ci
# Prettier formatting
- name: 'Code formatting verification with Prettier'
run: npm run prettier:verify
# Install Salesforce CLI
- name: 'Install Salesforce CLI'
run: |
npm install @salesforce/cli --location=global
nodeInstallPath=$(npm config get prefix)
echo "$nodeInstallPath/bin" >> $GITHUB_PATH
cd "$nodeInstallPath/bin"
./sf --version
# Install Salesforce CLI Code Analyzer plugin
- name: 'Install Salesforce CLI Code Analyzer plugin'
run: sf plugins install code-analyzer
# Run Code Analyzer
- name: 'Run Code Analyzer'
id: run-code-analyzer
uses: forcedotcom/run-code-analyzer@v2
with:
run-arguments: --workspace "cc-*/**" --view detail --output-file "sca-results.csv" --config-file "code-analyzer.yml"
results-artifact-name: code-analyzer-results
github-token: ${{ github.token }}
# Check for Code Analyzer critical or high severity violations
- name: 'Check for Code Analyzer critical or high severity violations'
if: |
steps.run-code-analyzer.outputs.exit-code > 0 ||
steps.run-code-analyzer.outputs.num-sev1-violations > 0 ||
steps.run-code-analyzer.outputs.num-sev2-violations > 0
run: |
echo One of more Code Analyzer critical or high severity violations found
exit 1
# 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:
token: ${{ secrets.CODECOV_TOKEN }}
flags: LWC
scratch-org-test:
runs-on: trailheadapps-Ubuntu
needs: format-lint-lwc-tests
if: github.actor != 'dependabot[bot]'
steps:
# Checkout the source code
- name: 'Checkout source code'
uses: actions/checkout@v4
# Install Salesforce CLI
- name: 'Install Salesforce CLI'
run: |
npm install @salesforce/cli --location=global
nodeInstallPath=$(npm config get prefix)
echo "$nodeInstallPath/bin" >> $GITHUB_PATH
sf --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: sf org login sfdx-url -f ./DEVHUB_SFDX_URL.txt -a devhub -d
# Create scratch org
- name: 'Create scratch org'
run: sf org create scratch -f config/project-scratch-def.json -a scratch-org -d -y 1 -w 10
# Push base source to scratch org
- name: 'Push base source to scratch org'
run: sf project deploy start -d cc-base-app
# Assign Prompt Template Manager permission set
- name: 'Assign Prompt Template Manager permission set'
run: sf org assign permset -n EinsteinGPTPromptTemplateManager
# Push employee source to scratch org
- name: 'Push employee source to scratch org'
run: sf project deploy start -d cc-employee-app
# Assign Coral Cloud permission sets
- name: 'Assign Coral Cloud permission sets to default user'
run: |
sf org assign permset -n Coral_Cloud_Admin
sf org assign permset -n Coral_Cloud_Employee_Agent_Access
# Import sample data
- name: 'Import sample data'
run: sf data tree import -p ./data/data-plan.json
# Run Apex tests in scratch org
- name: 'Run Apex tests'
run: sf apex test run -c -r human -d ./tests/apex -w 20
# Upload code coverage data
- name: 'Upload code coverage for Apex to Codecov.io'
uses: codecov/codecov-action@v4
with:
token: ${{ secrets.CODECOV_TOKEN }}
flags: Apex
# Prepare environment variables for service deployment
- name: 'Prepare environment variables for service deployment'
run: |
echo "Exporting username and org domain for use in scripts:"
# Username
SF_CC_PLACEHOLDER_USERNAME=$(sf org display --json | grep -o '"username": "[^"]*' | cut -d'"' -f4)
if [ -z "${SF_CC_PLACEHOLDER_USERNAME}" ]; then
echo "Installation failed: could not retrieve username."
exit 1
fi
echo "- Username: $SF_CC_PLACEHOLDER_USERNAME"
echo "SF_CC_PLACEHOLDER_USERNAME=$SF_CC_PLACEHOLDER_USERNAME" >> $GITHUB_ENV
# Domain
SF_CC_PLACEHOLDER_DOMAIN=$(sf org display --json | grep -o '"instanceUrl": "https[^"]*' | cut -d'"' -f4 | sed -E 's|https?://([^\.]+).*|\1|')
if [ -z "${SF_CC_PLACEHOLDER_DOMAIN}" ]; then
echo "Installation failed: could not retrieve domain."
exit 1
fi
echo "- Domain: $SF_CC_PLACEHOLDER_DOMAIN"
echo "SF_CC_PLACEHOLDER_DOMAIN=$SF_CC_PLACEHOLDER_DOMAIN" >> $GITHUB_ENV
# Set dummy values for flow deployment
echo "Setting dummy values for flow deployment"
echo "SF_CC_PLACEHOLDER_FLOW_AGENT_ID=DummyForInitialDeploy" >> $GITHUB_ENV
echo "SF_CC_PLACEHOLDER_FLOW_CHANNEL_ID=DummyForInitialDeploy" >> $GITHUB_ENV
echo "SF_CC_PLACEHOLDER_FLOW_QUEUE_ID=DummyForInitialDeploy" >> $GITHUB_ENV
# Push Experience Cloud site source
- name: 'Push Experience Cloud site source'
run: sf project deploy start -d cc-site
# Push Service Agent Setup source
- name: 'Push Service Agent Setup source'
run: sf project deploy start -d cc-service-app/main/setup/classes/SetupServiceAgentUser.cls -d cc-service-app/main/default/permissionSets/Coral_Cloud_Service_Agent.permissionset-meta.xml
# Setup Service Agent user
- name: 'Setup Service Agent user'
run: sf apex run -f apex-scripts/setup-agent-user.apex
# Push service app source
- name: 'Push service app source'
run: sf project deploy start -d cc-service-app
# Read flow values (Agent ID, Channel ID, Queue ID) from org
- name: 'Read flow values (Agent ID, Channel ID, Queue ID) from org'
run: |
echo "Reading flow values from org..."
# Agent ID
SF_CC_PLACEHOLDER_FLOW_AGENT_ID=$(sf data query --query "SELECT Id from BotDefinition WHERE DeveloperName='Coral_Cloud_Agent'" --json | grep -o '"Id": "[^"]*' | cut -d'"' -f4)
if [ -z "${SF_CC_PLACEHOLDER_FLOW_AGENT_ID}" ] || [ "${SF_CC_PLACEHOLDER_FLOW_AGENT_ID}" = "DummyForInitialDeploy" ]; then
echo "Installation failed: could not retrieve agent ID."
exit 1
fi
echo "- Agent ID: $SF_CC_PLACEHOLDER_FLOW_AGENT_ID"
echo "SF_CC_PLACEHOLDER_FLOW_AGENT_ID=$SF_CC_PLACEHOLDER_FLOW_AGENT_ID" >> $GITHUB_ENV
# Channel ID
SF_CC_PLACEHOLDER_FLOW_CHANNEL_ID=$(sf data query --query "SELECT Id from ServiceChannel WHERE DeveloperName='sfdc_livemessage'" --json | grep -o '"Id": "[^"]*' | cut -d'"' -f4)
if [ -z "${SF_CC_PLACEHOLDER_FLOW_CHANNEL_ID}" ] || [ "${SF_CC_PLACEHOLDER_FLOW_CHANNEL_ID}" = "DummyForInitialDeploy" ]; then
echo "Installation failed: could not retrieve channel ID."
exit 1
fi
echo "- Channel ID: $SF_CC_PLACEHOLDER_FLOW_CHANNEL_ID"
echo "SF_CC_PLACEHOLDER_FLOW_CHANNEL_ID=$SF_CC_PLACEHOLDER_FLOW_CHANNEL_ID" >> $GITHUB_ENV
# Queue ID
SF_CC_PLACEHOLDER_FLOW_QUEUE_ID=$(sf data query --query "SELECT Id FROM Group WHERE Type = 'Queue' AND Name = 'Messaging Queue'" --json | grep -o '"Id": "[^"]*' | cut -d'"' -f4)
if [ -z "${SF_CC_PLACEHOLDER_FLOW_QUEUE_ID}" ] || [ "${SF_CC_PLACEHOLDER_FLOW_QUEUE_ID}" = "DummyForInitialDeploy" ]; then
echo "Installation failed: could not retrieve queue ID."
exit 1
fi
echo "- Queue ID: $SF_CC_PLACEHOLDER_FLOW_QUEUE_ID"
echo "SF_CC_PLACEHOLDER_FLOW_QUEUE_ID=$SF_CC_PLACEHOLDER_FLOW_QUEUE_ID" >> $GITHUB_ENV
# Redeploy flow metadata with org-specific values
- name: 'Redeploy flow metadata with org-specific values'
run: sf project deploy start -d cc-service-app/main/default/flows/Route_to_Agent.flow-meta.xml cc-service-app/main/default/flows/Route_to_Queue.flow-meta.xml
# Publish Experience Cloud site
- name: 'Publish Experience Cloud site'
run: sf community publish --name 'coral cloud'
# Deploy guest profile for Experience Cloud site
- name: 'Deploy guest profile for Experience Cloud site'
run: sf project deploy start --metadata-dir=guest-profile-metadata -w 10
# Activate messaging channel
- name: 'Activate messaging channel'
run: sf apex run -f apex-scripts/activate-messaging-channel.apex
# Housekeeping
- name: 'Delete scratch org'
if: always()
run: sf org delete scratch -p -o scratch-org
trigger-packaging:
runs-on: trailheadapps-Ubuntu
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
hasBasePackageChanges='false'
hasSitePackageChanges='false'
if [ $(echo "$changedPaths" | grep -c '^cc-base-app') == 1 ]; then
hasBasePackageChanges='true'
fi
if [ $(echo "$changedPaths" | grep -c '^cc-site') == 1 ]; then
hasSitePackageChanges='true'
fi
echo "hasBasePackageChanges=$hasBasePackageChanges" >> $GITHUB_OUTPUT
echo "hasSitePackageChanges=$hasSitePackageChanges" >> $GITHUB_OUTPUT
# Trigger packaging workflow if needed
- name: 'Trigger packaging workflow if needed'
uses: peter-evans/repository-dispatch@v3
if: steps.checkForChanges.outputs.hasBasePackageChanges == 'true' || steps.checkForChanges.outputs.hasSitePackageChanges == 'true'
with:
token: ${{ secrets.BOT_ACCESS_TOKEN }}
event-type: start-packaging
client-payload: '{ "ref": "${{ github.ref }}", "sha": "${{ github.sha }}", "isBasePackageRelease": "${{ steps.checkForChanges.outputs.hasBasePackageChanges }}", "isSitePackageRelease": "${{ steps.checkForChanges.outputs.hasSitePackageChanges }}" }'