-
Notifications
You must be signed in to change notification settings - Fork 42
272 lines (243 loc) · 10.5 KB
/
test.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
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
name: Tests
on:
push:
branches:
- "**"
paths-ignore:
- "docs/**"
- "**.md"
- ".vscode/**"
pull_request:
branches: [main]
repository_dispatch:
types: [run-tests]
workflow_dispatch:
inputs:
overwrite-snapshots:
type: boolean
description: Overwrite snapshots
jobs:
tests:
name: ${{ matrix.suite.name }} - Unity ${{ matrix.unity.version }}
permissions:
contents: write
pages: write
id-token: write
checks: write
pull-requests: write
strategy:
fail-fast: false
matrix:
platform:
- ubuntu-latest
unity:
- { version: "2021.3.28f1" }
- { version: "2021.1.28f1" }
- { version: "2020.3.43f1" }
suite:
- {
name: "Unit Tests",
assemblies: "ReactUnity.Tests;ReactUnity.Tests.Editor",
}
include:
- main: true
coverage: true
unity: { version: "2022.3.4f1" }
suite:
{
name: "Unit Tests",
assemblies: "ReactUnity.Tests;ReactUnity.Tests.Editor",
}
- performance: true
unity: { version: "2022.3.4f1" }
suite:
{
name: "Performance Tests",
assemblies: "ReactUnity.Tests.Performance",
}
runs-on: ${{ matrix.platform || 'ubuntu-20.04' }}
steps:
- name: Checkout core library
uses: actions/checkout@v3
with:
fetch-depth: 0
path: core
- name: Checkout test project
uses: actions/checkout@v3
with:
fetch-depth: 0
ref: ${{ matrix.suite.testBranch || 'tests' }}
path: tests
- name: Checkout Jint plugin
uses: actions/checkout@v3
with:
fetch-depth: 0
ref: main
path: jint
repository: ReactUnity/jint
- name: Checkout QuickJS plugin
uses: actions/checkout@v3
with:
fetch-depth: 0
ref: main
path: quickjs
repository: ReactUnity/quickjs
- name: Checkout ClearScript plugin
uses: actions/checkout@v3
with:
fetch-depth: 0
ref: main
path: clearscript
repository: ReactUnity/clearscript
- name: Cache Unity Library
uses: actions/cache@v3
with:
path: tests/Library
key: Library-${{ matrix.unity.version }}-${{ matrix.platform || 'ubuntu-20.04' }}
- name: Clear React Unity package lock
run: |
echo $(cat tests/Packages/packages-lock.json | jq 'del(.dependencies["com.reactunity.core"])') > tests/Packages/packages-lock.json
echo $(cat tests/Packages/packages-lock.json | jq 'del(.dependencies["com.reactunity.jint"])') > tests/Packages/packages-lock.json
echo $(cat tests/Packages/packages-lock.json | jq 'del(.dependencies["com.reactunity.quickjs"])') > tests/Packages/packages-lock.json
echo $(cat tests/Packages/packages-lock.json | jq 'del(.dependencies["com.reactunity.clearscript"])') > tests/Packages/packages-lock.json
- name: Install local React Unity package
run: |
echo $(cat tests/Packages/manifest.json | jq '.dependencies["com.reactunity.core"]="file:../../core"') > tests/Packages/manifest.json
echo $(cat tests/Packages/manifest.json | jq '.dependencies["com.reactunity.jint"]="file:../../jint"') > tests/Packages/manifest.json
echo $(cat tests/Packages/manifest.json | jq '.dependencies["com.reactunity.quickjs"]="file:../../quickjs"') > tests/Packages/manifest.json
echo $(cat tests/Packages/manifest.json | jq '.dependencies["com.reactunity.clearscript"]="file:../../clearscript"') > tests/Packages/manifest.json
- name: Run Unity Tests
uses: game-ci/unity-test-runner@v2
id: testRunner
continue-on-error: true
env:
UNITY_LICENSE: ${{ secrets[matrix.unity.license || 'UNITY_LICENSE'] }}
with:
projectPath: tests
checkName: ${{ matrix.suite.name }} ${{ matrix.unity.version }}
unityVersion: ${{ matrix.unity.version }}
testMode: ${{ contains(matrix.suite.assemblies, 'Editor') && 'All' || 'PlayMode' }}
customParameters: >-
${{ matrix.coverage && '-enableCodeCoverage -debugCodeOptimization -coverageOptions assemblyFilters:+ReactUnity,+ReactUnity.*' || '' }}
-assemblyNames ${{ matrix.suite.assemblies }}
${{ matrix.performance && '-profiler-enable' || '' }}
${{ (contains(github.event.head_commit.message, '[snapshots]') || github.event.inputs.overwrite-snapshots == 'true') && '-reactOverwriteSnapshots' || '' }}
- name: Cache Performance Test Results
if: matrix.performance
uses: actions/cache@v3
with:
path: tests/PerformanceTestResults
key: performance-results-${{ github.sha }}
restore-keys: |
performance-results-
- name: Copy Test Results to Performance Test Results
if: matrix.performance
working-directory: ./tests
run: |
mkdir -p PerformanceTestResults
cd "${{ github.workspace }}/${{ steps.testRunner.outputs.artifactsPath }}"
find . -name \*.xml -exec bash -c 'cp $0 "${{ github.workspace }}/tests/PerformanceTestResults/$(date +%s)-$(basename ""$0"")"' {} \;
- name: Keep only last 10 files
if: matrix.performance
working-directory: tests/PerformanceTestResults
continue-on-error: true
run: ls -A1t | tail -n +11 | xargs rm
- uses: actions/setup-dotnet@v4
if: matrix.performance
with:
dotnet-version: '3.1.x'
cache: true
- name: Generate Performance Report
if: matrix.performance
working-directory: ./tests
run: dotnet PerformanceReporter/UnityPerformanceBenchmarkReporter.dll --results="${{ github.workspace }}/tests/PerformanceTestResults" --reportdirpath=PerformanceReport
- name: Rename Performance Report
working-directory: ./tests/PerformanceReport/UnityPerformanceBenchmark
if: matrix.performance
run: |
find . -name '*.html' -exec bash -c 'mv $0 index.html' {} \;
cd ..
mv UnityPerformanceBenchmark Performance
- name: Commit Snapshots
if: hashFiles('core/Tests/.snapshots/snapshots.lock') != '' && matrix.main
uses: EndBug/add-and-commit@v9
with:
add: "Tests/.snapshots"
cwd: "./core"
default_author: github_actions
message: "Update snapshots"
- name: Set artifacts folder ownership to current user
run: sudo chown -R $(id -u):$(id -g) "${{ github.workspace }}/${{ steps.testRunner.outputs.artifactsPath }}"
- uses: EnricoMi/publish-unit-test-result-action@v2
id: test-results
with:
check_name: "${{ matrix.suite.name }} ${{ matrix.unity.version }}"
nunit_files: "${{ github.workspace }}/${{ steps.testRunner.outputs.artifactsPath }}/*.xml"
- name: Set badge color
shell: bash
run: |
case ${{ fromJSON( steps.test-results.outputs.json ).conclusion }} in
success)
echo "BADGE_COLOR=31c653" >> $GITHUB_ENV
;;
failure)
echo "BADGE_COLOR=800000" >> $GITHUB_ENV
;;
neutral)
echo "BADGE_COLOR=696969" >> $GITHUB_ENV
;;
esac
- name: Create badge
uses: emibcn/badge-action@v1
with:
label: Tests
status: "${{ fromJSON( steps.test-results.outputs.json ).stats.tests_succ }}/${{ fromJSON( steps.test-results.outputs.json ).stats.tests }}"
color: ${{ env.BADGE_COLOR }}
path: ReactUnityTestBadge.svg
style: flat
scale: 1.4
- name: Upload badge to Gist
if: github.ref == 'refs/heads/main' && always() && matrix.main
uses: andymckay/append-gist-action@1fbfbbce708a39bd45846f0955ed5521f2099c6d
with:
token: ${{ secrets.GIST_TOKEN }}
gistURL: https://gist.githubusercontent.com/KurtGokhan/f744e86dd53cd0159d4f1d56ae9aae19
file: ReactUnityTestBadge.svg
- name: Upload Test Result Artifacts
uses: actions/upload-artifact@v3
if: always()
with:
name: "${{ matrix.suite.name }} ${{ matrix.unity.version }}"
path: ${{ steps.testRunner.outputs.artifactsPath }}
- name: Fail workflow if tests failed
if: steps.testRunner.outcome == 'failure' && (fromJSON(steps.test-results.outputs.json).conclusion == 'failure' || fromJSON(steps.test-results.outputs.json).stats.tests == 0)
uses: actions/github-script@v3
with:
script: |
core.setFailed('Tests failed!')
- name: Upload Coverage to codecov
if: matrix.coverage && matrix.main
uses: codecov/codecov-action@v3
with:
working-directory: ./core
files: ../CodeCoverage/tests-opencov/PlayMode/TestCoverageResults_0000.xml,../CodeCoverage/tests-opencov/PlayMode/TestCoverageResults_0001.xml,../CodeCoverage/tests-opencov/EditMode/TestCoverageResults_0000.xml,../CodeCoverage/tests-opencov/EditMode/TestCoverageResults_0001.xml
path_to_write_report: ../CodeCoverage/codecov_report.txt
flags: unittests
- name: Upload Code Coverage Artifacts
uses: actions/upload-artifact@v3
if: always() && matrix.main && matrix.coverage && contains(github.event.head_commit.message, '[coverage]')
with:
name: "${{ matrix.suite.name }} ${{ matrix.unity.version }} Code Coverage"
path: CodeCoverage
- name: Setup Github Pages
if: github.ref == 'refs/heads/main' && matrix.performance && always()
uses: actions/configure-pages@v2
- name: Upload Pages Artifact
if: github.ref == 'refs/heads/main' && matrix.performance && always()
uses: actions/upload-pages-artifact@v1
with:
path: "./tests/PerformanceReport/Performance"
- name: Deploy to GitHub Pages
if: github.ref == 'refs/heads/main' && matrix.performance && always()
id: deployment
uses: actions/deploy-pages@v1