-
Notifications
You must be signed in to change notification settings - Fork 2
134 lines (132 loc) · 5.62 KB
/
run-tests.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
name: run-tests
on:
workflow_call:
inputs:
use-scanner-tarballs:
description: 'If true, install scanner via tarball'
required: false
type: boolean
default: false
v4-tarball-suffix:
description: 'The suffix attached to the name of the v4 tarball'
required: false
type: string
default: 'dev-4'
v5-tarball-suffix:
description: 'The suffix attached to the name of the v5 tarball'
required: false
type: string
default: 'dev'
target-branch:
description: "What branch should be checked out?"
required: false
type: string
# If no target branch is specified, just use the one we'd use normally.
default: ${{ github.sha }}
jobs:
build-and-run:
strategy:
matrix:
os: [macos-latest, ubuntu-latest, windows-latest]
runs-on: ${{ matrix.os }}
steps:
- name: 'Check out the code'
uses: actions/checkout@v4
with:
ref: ${{ inputs.target-branch }}
- name: 'Set up NodeJS'
uses: actions/setup-node@v4
with:
node-version: 'lts/*' # Node LTS should always be fine.
- name: 'Install Java v11'
uses: actions/setup-java@v4
with:
distribution: 'temurin'
java-version: '11' # Always use Java v11 for running tests.
- uses: actions/setup-python@v5
with:
python-version: 3.12
- name: 'Install node module dependencies'
run: npm ci
# We'll need to install the CLI tool, since some of the tests
# are integration tests.
- name: Install SF CLI
run: npm install --global @salesforce/cli
# We'll need to install Salesforce Code Analyzer, since some
# of the tests are integration tests.
# NOTE: SFCA can come from a tarball built in a previous step,
# or be installed as the currently-latest version.
- name: Download v4 Scanner Tarball
if: ${{ inputs.use-scanner-tarballs == true }}
id: download-v4
uses: actions/download-artifact@v4
with:
name: scanner-tarball-${{ inputs.v4-tarball-suffix}}
# Download the tarball to a subdirectory of HOME, so it's guaranteed
# to be somewhere the installation command can see.
path: ~/downloads/tarball-v4
- name: Install v4 Scanner Tarball
if: ${{ inputs.use-scanner-tarballs == true }}
shell: bash
run: |
# Determine the tarball's name.
TARBALL_NAME=$(ls ~/downloads/tarball-v4/sfdx-scanner | grep salesforce-.*\\.tgz)
echo $TARBALL_NAME
# Figure out where the tarball was downloaded to.
# To allow compatibility with Windows, replace backslashes with forward slashes
# and rip off a leading `C:` if present.
DOWNLOAD_PATH=`echo '${{ steps.download-v4.outputs.download-path }}' | tr '\\' '/'`
echo $DOWNLOAD_PATH
DOWNLOAD_PATH=`[[ $DOWNLOAD_PATH = C* ]] && echo $DOWNLOAD_PATH | cut -d':' -f 2 || echo $DOWNLOAD_PATH`
echo $DOWNLOAD_PATH
# Pipe in a `y` to simulate agreeing to install an unsigned package. Use a URI of the file's full path.
echo y | sf plugins install "file://${DOWNLOAD_PATH}/sfdx-scanner/${TARBALL_NAME}"
- name: Download v5 Scanner Tarball
if: ${{ inputs.use-scanner-tarballs == true }}
id: download-v5
uses: actions/download-artifact@v4
with:
name: scanner-tarball-${{ inputs.v5-tarball-suffix }}
# Download the tarball to a subdirectory of HOME, so it's guaranteed
# to be somewhere the installation command can see.
path: ~/downloads/tarball-v5
- name: Install v5 Scanner Tarball
if: ${{ inputs.use-scanner-tarballs == true }}
shell: bash
run: |
# Determine the tarball's name.
TARBALL_NAME=$(ls ~/downloads/tarball-v5/sfdx-scanner | grep salesforce-.*\\.tgz)
echo $TARBALL_NAME
# Figure out where the tarball was downloaded to.
# To allow compatibility with Windows, replace backslashes with forward slashes
# and rip off a leading `C:` if present.
DOWNLOAD_PATH=`echo '${{ steps.download-v5.outputs.download-path }}' | tr '\\' '/'`
echo $DOWNLOAD_PATH
DOWNLOAD_PATH=`[[ $DOWNLOAD_PATH = C* ]] && echo $DOWNLOAD_PATH | cut -d':' -f 2 || echo $DOWNLOAD_PATH`
echo $DOWNLOAD_PATH
# Pipe in a `y` to simulate agreeing to install an unsigned package. Use a URI of the file's full path.
echo y | sf plugins install "file://${DOWNLOAD_PATH}/sfdx-scanner/${TARBALL_NAME}"
- name: Install Production scanner v4
if: ${{ inputs.use-scanner-tarballs == false }}
run: sf plugins install @salesforce/sfdx-scanner
- name: Install Production scanner v5
if: ${{ inputs.use-scanner-tarballs == false }}
run: sf plugins install code-analyzer
# Run the tests. (Linux and non-Linux need slightly different commands.)
- name: 'Run Tests (Linux)'
run: xvfb-run -a npm run test
if: runner.os == 'Linux'
- name: 'Run Tests (non-Linux)'
run: npm run test
if: runner.os != 'Linux'
# Lint, to make sure we're following best practices.
- name: 'Lint'
run: npm run lint
# Upload the code coverage from the test as an artifact with
# the name 'code-coverage-[whatever the OS is]'.
- name: Upload coverage artifact
if: ${{ always() }}
uses: actions/upload-artifact@v4
with:
name: code-coverage-${{ runner.os }}
path: ./coverage