-
Notifications
You must be signed in to change notification settings - Fork 1
93 lines (91 loc) · 3.71 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
name: run-tests
on:
workflow_call:
inputs:
use-scanner-tarball:
description: 'If true, install scanner via tarball'
required: false
type: boolean
default: false
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.
- name: 'Install node module dependencies'
run: yarn install --frozen-lockfile
# 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 Scanner Tarball
if: ${{ inputs.use-scanner-tarball == true }}
id: download
uses: actions/download-artifact@v4
with:
name: scanner-tarball
# Download the tarball to a subdirectory of HOME, so it's guaranteed
# to be somewhere the installation command can see.
path: ~/downloads/tarball
- name: Install Scanner Tarball
if: ${{ inputs.use-scanner-tarball == true }}
shell: bash
run: |
# Determine the tarball's name.
TARBALL_NAME=$(ls ~/downloads/tarball/sfdx-scanner | grep salesforce-sfdx-scanner-[0-9]*\\.[0-9]*\\.[0-9]*\\.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.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
if: ${{ inputs.use-scanner-tarball == false }}
run: sf plugins install @salesforce/sfdx-scanner
# Run the tests. (Linux and non-Linux need slightly different commands.)
- name: 'Run Tests (Linux)'
run: xvfb-run -a yarn test
if: runner.os == 'Linux'
- name: 'Run Tests (non-Linux)'
run: yarn test
if: runner.os != 'Linux'
# Lint, to make sure we're following best practices.
- name: 'Lint'
run: yarn 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