forked from trailheadapps/lwc-recipes
-
Notifications
You must be signed in to change notification settings - Fork 0
170 lines (144 loc) · 6.26 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
# 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: trailheadapps-Ubuntu
steps:
# Checkout the source code
- name: 'Checkout source code'
uses: actions/checkout@v3
# 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@v3
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
# 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@v3
with:
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@v3
# Run PMD scan
- name: 'Run PMD scan'
uses: pmd/pmd-github-action@v1
id: pmd
with:
sourcePath: 'force-app'
rulesets: 'ruleset.xml'
# Check for PMD violations
- name: 'Check for PMD violations'
if: steps.pmd.outputs.violations != 0
run: exit 1
# Install Salesforce CLI
- name: 'Install Salesforce CLI'
run: |
wget https://developer.salesforce.com/media/salesforce-cli/sfdx/channels/stable/sfdx-linux-x64.tar.xz
mkdir ~/sfdx
tar xJf sfdx-linux-x64.tar.xz -C ~/sfdx --strip-components 1
echo "$HOME/sfdx/bin" >> $GITHUB_PATH
~/sfdx/bin/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 force:org:create -f config/project-scratch-def.json -a scratch-org -s -d 1 release=Preview
# Deploy source to scratch org
- name: 'Push source to scratch org'
run: sfdx force:source:push
# 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 -c -r human -d ./tests/apex -w 20
# 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@v3
with:
flags: Apex
# Housekeeping
- name: 'Delete scratch org'
if: always()
run: sfdx force:org:delete -p -u scratch-org
trigger-packaging:
runs-on: trailheadapps-Ubuntu
needs: scratch-org-test
steps:
# Checkout the source code
- name: 'Checkout source code'
uses: actions/checkout@v3
# Check for package changes using git diff
- name: 'Check for package changes'
id: checkForChanges
run: |
git fetch origin $GITHUB_BASE_REF --depth=1
changedPaths=$( git diff-tree --name-only origin/$GITHUB_BASE_REF $GITHUB_SHA )
set +e
hasChanges='false'
if [ $(echo "$changedPaths" | grep -c '^force-app') == 1 ]; then
hasChanges='true'
fi
echo "::set-output name=hasChanges::$hasChanges"
# Trigger packaging pre-release PR workflow
- name: 'Trigger packaging pre-release PR workflow if needed'
uses: peter-evans/repository-dispatch@v2
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 }}" }'