-
Notifications
You must be signed in to change notification settings - Fork 3
101 lines (87 loc) · 3.32 KB
/
pr.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
# Unique name for this workflow
name: CI on PR
# Definition when the workflow should run
on:
workflow_dispatch:
pull_request:
types: [edited, opened, synchronize, reopened, review_requested]
paths:
- "force-app/**"
- "sample-handler/**"
- ".github/workflows/pr.yml"
# Jobs to be executed
jobs:
# Formatting and linting only runs on human-submitted PRs
format-lint-lwc-tests:
runs-on: ubuntu-latest
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
# Prettier formatting
- name: "Code formatting verification with Prettier"
run: npm run prettier:verify
scratch-org-test:
runs-on: ubuntu-latest
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 --global
nodeInstallPath=$(npm config get prefix)
echo "$nodeInstallPath/bin" >> $GITHUB_PATH
sf --version
# Store secret for dev hub
- name: "Populate auth file with SALESFORCE_AUTH_URL secret"
shell: bash
run: |
echo ${{ secrets.SALESFORCE_AUTH_URL}} > ./SALESFORCE_AUTH_URL.txt
secretFileSize=$(wc -c "./SALESFORCE_AUTH_URL.txt" | awk '{print $1}')
if [ $secretFileSize == 1 ]; then
echo "Missing SALESFORCE_AUTH_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 --sfdx-url-file ./SALESFORCE_AUTH_URL.txt --alias devhub --set-default-dev-hub
# Create scratch org
- name: "Create scratch org"
run: sf org create scratch --definition-file config/project-scratch-def.json --alias ScratchOrg --set-default --duration-days 1 --wait 20 --no-track-source
# Deploy source to scratch org
- name: "Push source to scratch org"
run: sf deploy metadata
# Run Apex tests in scratch org
- name: "Run Apex tests"
run: sf apex run test --test-level RunLocalTests --code-coverage --result-format human --output-dir ./tests/apex --wait 20
# 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: sf org delete scratch --no-prompt --target-org ScratchOrg