-
Notifications
You must be signed in to change notification settings - Fork 50
133 lines (130 loc) · 5.23 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
name: run-tests
on:
workflow_call:
inputs:
node-matrix:
description: "An array of node versions against which the tests should be run"
required: false
type: string
default: "[{version: 'lts/*', artifact: 'lts'}]"
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:
unit-tests:
strategy:
# By default, if any job in a matrix fails, all other jobs are immediately canceled. This makes the jobs run
# to completion instead.
fail-fast: false
matrix:
node: ${{ fromJson(inputs.node-matrix) }}
os: [ubuntu-latest, windows-latest, macos-latest]
runs-on: ${{ matrix.os }}
steps:
# Check out the code
- uses: actions/checkout@v4
with:
ref: ${{ inputs.target-branch }}
# Make sure we're on the right version on Node
- uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node.version }}
- run: yarn
- run: yarn build
- run: yarn test
id: jest-tests
- run: yarn lint
- name: Upload full artifact
if: ${{ always() }}
uses: actions/upload-artifact@v4
with:
name: tests-${{ runner.os }}-${{ matrix.node.artifact }}
path: |
./reports
./coverage
# The smoke tests should mimic a production setup as closely as possible. To that end, we'll spin up a tarball and
# then upload it as an artifact, so the smoke test jobs can pull it down and install it.
build-installable-tarball:
runs-on: ubuntu-latest
steps:
# Obviously, we need to get the code first
- uses: actions/checkout@v4
with:
ref: ${{ inputs.target-branch }}
# Make sure we're on the right version of Node
- uses: actions/setup-node@v4
with:
node-version: 'lts/*' # Always use Node LTS for building the tarball
# Install/build dependencies
- run: yarn
- run: yarn build
# Create the tarball
- run: npm pack
# Upload the tarball as an artifact
- uses: actions/upload-artifact@v4
with:
name: smoke-test-tarball
path: ./salesforce-plugin-code-analyzer-*.tgz
# For now, the smoke tests are no-ops, so the job doesn't have to do anything exciting.
# When smoke-tests stop being no-ops, we'll need a build-dependencies step to create a tarball artifact, and so forth.
# We'll be able to use the v4 workflow as a template.
smoke-tests:
needs: build-installable-tarball
strategy:
# By default, if any job in a matrix fails, all other jobs are automatically cancelled. This makes the jobs run
# to completion instead.
fail-fast: false
matrix:
node: ${{ fromJson(inputs.node-matrix) }}
os: [{vm: ubuntu-latest, exe: .sh}, {vm: macos-latest, exe: .sh}, {vm: windows-latest, exe: .cmd}]
runs-on: ${{ matrix.os.vm }}
steps:
# Check out the code
- uses: actions/checkout@v4
with:
ref: ${{ inputs.target-branch }}
# Set up Node and Java
- uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node.version }}
- uses: actions/setup-java@v4
with:
distribution: 'temurin'
java-version: '11'
- uses: actions/setup-python@v5
with:
python-version: '3.12'
# Install SF CLI via NPM
- run: npm install -g @salesforce/cli
# Download and install the Tarball artifact
- uses: actions/download-artifact@v4
id: download
with:
name: smoke-test-tarball
# Download the tarball to a subdirectory of HOME, to guarantee that it's somewhere the installation command
# can see
path: ~/downloads/tarball
- name: Echo tarball download location
run: echo ${{ steps.download.outputs.download-path }}
- name: Install Tarball
shell: bash
run: |
# We need to determine the Tarball's name first.
TARBALL_NAME=$(ls ~/downloads/tarball | grep salesforce-plugin-code-analyzer-5\\.0\\.0-alpha\\.[0-9]*\\.tgz)
# We need to determine the Tarball's location in an installable way.
# Get the path to the download folder. Swap out backslashes for forward slashes to ensure Windows compatibility.
RAW_TARBALL_PATH=`echo '${{ steps.download.outputs.download-path }}' | tr '\\' '/'`
# If the path starts with "C:", that needs to be pulled off.
ADJUSTED_TARBALL_PATH=`[[ $RAW_TARBALL_PATH = C* ]] && echo $RAW_TARBALL_PATH | cut -d':' -f 2 || echo $RAW_TARBALL_PATH`
# Install the tarball, piping in a `y` to simulate agreeing to install an unsigned package. Use the URI of the file's full path.
echo y | sf plugins install "file://${ADJUSTED_TARBALL_PATH}/${TARBALL_NAME}"
- name: Run smoke tests
run: smoke-tests/smoke-test${{ matrix.os.exe }} sf
- uses: actions/upload-artifact@v4
if: ${{always()}}
with:
name: smoke-test-results-${{ runner.os }}-node-${{ matrix.node.artifact }}
path: smoke-test-results