Skip to content

Commit 2c9222a

Browse files
nirinchevbwachter
andauthored
Start running Unity tests on CI (#2963)
Co-authored-by: Bernd Wachter <[email protected]>
1 parent 8d0e841 commit 2c9222a

22 files changed

+357
-64
lines changed

.github/templates/build-unity.yml

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#@ load("@ytt:template", "template")
2-
#@ load("common.lib.yml", "checkoutCode", "uploadArtifacts", "nugetPackages", "setupNugetCache")
2+
#@ load("common.lib.yml", "checkoutCode", "uploadArtifacts", "nugetPackages", "actionDownloadArtifact")
33
#@ load("test.lib.yml", "fetchPackageArtifacts")
44

55
#@ unityPkgName = "io.realm.unity-${{ inputs.version }}.tgz"
@@ -16,18 +16,17 @@ env:
1616
REALM_DISABLE_ANALYTICS: true
1717
DOTNET_NOLOGO: true
1818
jobs:
19-
build-unity:
19+
prepare-unity-packages:
2020
runs-on: windows-latest
2121
name: Unity
2222
timeout-minutes: 30
2323
steps:
2424
- #@ template.replace(checkoutCode())
2525
- #@ template.replace(fetchPackageArtifacts(packages = nugetPackages))
26-
- #@ setupNugetCache([ "Tools/SetupUnityPackage" ])
2726
- name: Build Unity
2827
run: dotnet run --project Tools/SetupUnityPackage/ -- realm --packages-path Realm/packages --pack
2928
- #@ uploadArtifacts(unityPkgName, "Realm/Realm.Unity/" + unityPkgName)
3029
- #@ uploadArtifacts("AssetStorePublisher-${{ inputs.version }}", "Tools/AssetStorePublisher", "${{ (github.event_name != 'pull_request' || contains(github.head_ref, 'release')) && 30 || 1 }}")
3130
- name: Build Tests
3231
run: #@ "dotnet run --project Tools/SetupUnityPackage/ -- tests --realm-package Realm/Realm.Unity/" + unityPkgName
33-
- #@ uploadArtifacts("UnityTests", "Tests/Tests.Unity")
32+
- #@ uploadArtifacts("UnityTests", "Tests/Tests.Unity")

.github/templates/build.lib.yml

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#@ load("@ytt:template", "template")
2-
#@ load("common.lib.yml", "checkoutCode", "setupNugetCache")
2+
#@ load("common.lib.yml", "checkoutCode")
33

44
#@ isRelease = "contains(github.head_ref, 'release')"
55

@@ -110,3 +110,17 @@ build-unity:
110110
- build-packages
111111
if: #@ ignoreSkippedJobsCondition
112112
#@ end
113+
114+
#@ def testUnity(settings, platforms):
115+
test-unity:
116+
uses: ./.github/workflows/test-unity.yml
117+
name: Test
118+
with:
119+
version: ${{ needs.build-packages.outputs.package_version }}
120+
settings: #@ settings
121+
platform: #@ platforms
122+
needs:
123+
- build-packages
124+
- build-unity
125+
if: #@ ignoreSkippedJobsCondition
126+
#@ end

.github/templates/common.lib.yml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,6 @@ with:
6565
- name: Add msbuild to PATH
6666
uses: #@ actionSetupMSBuild
6767
if: ${{ runner.os == 'Windows' }}
68-
- #@ setupNugetCache(projectPaths)
6968
#@ for projectPath in projectPaths:
7069
- name: #@ "Build " + projectPath
7170
run: #@ "msbuild " + projectPath + target + " -p:Configuration=" + configuration + " -restore" + parsedProps
@@ -77,7 +76,6 @@ with:
7776
#@ for prop in properties.keys():
7877
#@ propsArg += " -p:" + prop + "=" + properties[prop]
7978
#@ end
80-
- #@ setupNugetCache([ projectPath ])
8179
- name: #@ "Publish " + projectPath
8280
run: #@ "dotnet publish " + projectPath + " -c " + configuration + " -f " + framework + " -r " + runtime + propsArg + " --no-self-contained"
8381
- name: Output executable path

.github/templates/pr.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
#@ load("@ytt:template", "template")
2-
#@ load("common.lib.yml", "checkoutCode", "uploadArtifacts", "actionDownloadArtifact", "uploadPackagesToSleet", "cleanupWorkspace")
3-
#@ load("build.lib.yml", "deployBaas", "cleanupBaas", "runTests", "runNetCoreTests", "buildUnity")
2+
#@ load("build.lib.yml", "deployBaas", "cleanupBaas", "runTests", "runNetCoreTests", "buildUnity", "testUnity")
43
---
54
name: PR Build
65
"on":
@@ -34,9 +33,10 @@ jobs:
3433
with:
3534
build-docs: ${{ contains(github.head_ref, 'release') }}
3635
_: #@ template.replace(buildUnity())
36+
_: #@ template.replace(testUnity('["Mono-Net4"]', '[{ "os": "windows", "testPlatform": "Windows64" }, { "os": "linux", "testPlatform": "Linux64" }]'))
3737
_: #@ template.replace(runTests(".NET Framework", runSyncTests = False))
3838
_: #@ template.replace(runTests("UWP Managed", runSyncTests = False, additionalSecrets = ["Pfx_Password", "Base64_Encoded_Pfx"]))
39-
_: #@ template.replace(runNetCoreTests("[\"net6.0\"]"))
39+
_: #@ template.replace(runNetCoreTests('["net6.0"]'))
4040
_: #@ template.replace(runTests("macOS", runSyncTests = False))
4141
_: #@ template.replace(runTests("iOS", runSyncTests = False))
4242
_: #@ template.replace(runTests("Android", runSyncTests = False, additionalSecrets=["AWS_DEVICEFARM_ACCESS_KEY_ID", "AWS_DEVICEFARM_SECRET_ACCESS_KEY", "DEVICEFARM_PROJECT_ARN", "DEVICEFARM_ANDROID_POOL_ARN"]))

.github/templates/test-net-core.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#@ load("@ytt:template", "template")
2-
#@ load("common.lib.yml", "checkoutCode", "setupDotnet")
2+
#@ load("common.lib.yml", "checkoutCode", "uploadArtifacts", "setupDotnet")
33
#@ load("test.lib.yml", "fetchPackageArtifacts", "baasTestArgs", "publishTestsResults", "testDefinition", "buildTests", "dotnetBuildTests")
44

55
---

.github/templates/test-unity.yml

Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
#@ load("@ytt:template", "template")
2+
#@ load("common.lib.yml", "uploadArtifacts", "actionDownloadArtifact", "checkoutCode")
3+
#@ load("test.lib.yml", "publishTestsResults")
4+
5+
#@ unityPkgName = "io.realm.unity-${{ inputs.version }}.tgz"
6+
7+
---
8+
name: test-unity
9+
"on":
10+
workflow_call:
11+
inputs:
12+
version:
13+
type: string
14+
required: true
15+
platform:
16+
type: string
17+
required: true
18+
settings:
19+
type: string
20+
required: true
21+
env:
22+
REALM_DISABLE_ANALYTICS: true
23+
DOTNET_NOLOGO: true
24+
jobs:
25+
build-tests:
26+
runs-on:
27+
- unity
28+
- ${{ matrix.platform.os }}
29+
name: Build Unity ${{ matrix.platform.os }}
30+
strategy:
31+
fail-fast: false
32+
matrix:
33+
platform: ${{ fromJson(inputs.platform) }}
34+
settings: ${{ fromJson(inputs.settings) }}
35+
timeout-minutes: 30
36+
steps:
37+
- #@ template.replace(checkoutCode())
38+
- name: Cleanup Workspace
39+
run: git clean -fdx
40+
- name: Fetch Unity Package
41+
uses: #@ actionDownloadArtifact
42+
with:
43+
name: #@ unityPkgName
44+
path: Realm/Realm.Unity
45+
- name: Fetch Unity Tests
46+
uses: #@ actionDownloadArtifact
47+
with:
48+
name: UnityTests
49+
path: Tests/Tests.Unity
50+
- name: Build Unity Tests
51+
run: |
52+
unity-editor -runTests -batchmode -projectPath ${{ github.workspace }}/Tests/Tests.Unity -testPlatform Standalone${{ matrix.platform.testPlatform }} -testSettingsFile ${{ github.workspace }}/Tests/Tests.Unity/.TestConfigs/${{ matrix.settings }}.json -logFile ${{ matrix.platform.os == 'windows' && 'build.log' || '-'}}
53+
- #@ uploadArtifacts("UnityTestsRunner.${{ matrix.platform.os }}", "Tests/Tests.Unity/Player_Standalone${{ matrix.platform.testPlatform }}_${{ matrix.settings }}/")
54+
55+
run-tests-linux:
56+
runs-on: ubuntu-latest
57+
name: Unity Linux
58+
timeout-minutes: 30
59+
needs:
60+
- build-tests
61+
if: ${{ contains(inputs.platform, 'Linux') }}
62+
steps:
63+
- #@ template.replace(checkoutCode())
64+
- name: Download Test Runner
65+
uses: #@ actionDownloadArtifact
66+
with:
67+
name: UnityTestsRunner.linux
68+
path: TestRunner
69+
- name: Install xvfb
70+
run: sudo apt install -y xvfb libglu1 libxcursor1
71+
- name: Run Tests
72+
run: |
73+
chmod +x ${{ github.workspace }}/TestRunner/PlayerWithTests.x86_64
74+
xvfb-run --auto-servernum --server-args='-screen 0 640x480x24:32' ${{ github.workspace }}/TestRunner/PlayerWithTests.x86_64 -logFile - --result=${{ github.workspace }}/TestResults.xml
75+
- #@ publishTestsResults("TestResults.xml", "Unity Linux Mono_Net4")
76+
77+
run-tests-windows:
78+
runs-on: windows-latest
79+
name: Unity Windows
80+
if: ${{ contains(inputs.platform, 'Windows') }}
81+
timeout-minutes: 30
82+
needs:
83+
- build-tests
84+
steps:
85+
- #@ template.replace(checkoutCode())
86+
- name: Download Test Runner
87+
uses: #@ actionDownloadArtifact
88+
with:
89+
name: UnityTestsRunner.windows
90+
path: TestRunner
91+
- name: Run Tests
92+
run: |
93+
Start-Process ${{ github.workspace }}\TestRunner\PlayerWithTests.exe -Wait -ArgumentList "-logFile","${{ github.workspace }}\test.log","--result=${{ github.workspace }}\TestResults.xml"
94+
cat ${{ github.workspace }}\test.log
95+
shell: powershell
96+
- #@ publishTestsResults("TestResults.xml", "Unity Windows Mono_Net4")

.github/workflows/build-packages.yml

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -128,10 +128,6 @@ jobs:
128128
- name: Add msbuild to PATH
129129
uses: microsoft/[email protected]
130130
if: ${{ runner.os == 'Windows' }}
131-
- uses: actions/cache@v2
132-
with:
133-
path: ~/.nuget/packages
134-
key: ${{ runner.os }}-nuget-${{ hashFiles('Realm/Realm.Fody/*.csproj', 'Realm/Realm/*.csproj', 'Realm/Realm.UnityUtils/*.csproj', 'Realm/Realm.UnityWeaver/*.csproj') }}
135131
- name: Build Realm/Realm.Fody
136132
run: msbuild Realm/Realm.Fody -t:Pack -p:Configuration=Release -restore -p:PackageOutputPath=${{ github.workspace }}/Realm/packages -p:VersionSuffix=${{ steps.set-version-suffix.outputs.build_suffix }}
137133
- name: Build Realm/Realm

.github/workflows/build-unity.yml

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ env:
99
REALM_DISABLE_ANALYTICS: true
1010
DOTNET_NOLOGO: true
1111
jobs:
12-
build-unity:
12+
prepare-unity-packages:
1313
runs-on: windows-latest
1414
name: Unity
1515
timeout-minutes: 30
@@ -43,10 +43,6 @@ jobs:
4343
with:
4444
name: Realm.UnityWeaver.${{ inputs.version }}
4545
path: ${{ github.workspace }}/Realm/packages/
46-
- uses: actions/cache@v2
47-
with:
48-
path: ~/.nuget/packages
49-
key: ${{ runner.os }}-nuget-${{ hashFiles('Tools/SetupUnityPackage/*.csproj') }}
5046
- name: Build Unity
5147
run: dotnet run --project Tools/SetupUnityPackage/ -- realm --packages-path Realm/packages --pack
5248
- name: Store artifacts for io.realm.unity-${{ inputs.version }}.tgz

.github/workflows/main.yml

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -202,10 +202,6 @@ jobs:
202202
uses: actions/setup-dotnet@v1
203203
with:
204204
dotnet-version: 6.0.x
205-
- uses: actions/cache@v2
206-
with:
207-
path: ~/.nuget/packages
208-
key: ${{ runner.os }}-nuget-${{ hashFiles('Tests/Tests.XUnit/*.csproj') }}
209205
- name: Publish Tests/Tests.XUnit
210206
run: dotnet publish Tests/Tests.XUnit -c Release -f net6.0 -r win-x64 -p:RestoreConfigFile=Tests/Test.NuGet.Config -p:UseRealmNupkgsWithVersion=${{ needs.build-packages.outputs.package_version }} --no-self-contained
211207
- name: Output executable path
@@ -263,10 +259,6 @@ jobs:
263259
uses: actions/setup-dotnet@v1
264260
with:
265261
dotnet-version: 6.0.x
266-
- uses: actions/cache@v2
267-
with:
268-
path: ~/.nuget/packages
269-
key: ${{ runner.os }}-nuget-${{ hashFiles('Tests/Benchmarks/PerformanceTests/*.csproj') }}
270262
- name: Publish Tests/Benchmarks/PerformanceTests
271263
run: dotnet publish Tests/Benchmarks/PerformanceTests -c Release -f net6.0 -r linux-x64 -p:RestoreConfigFile=Tests/Test.NuGet.Config -p:UseRealmNupkgsWithVersion=${{ needs.build-packages.outputs.package_version }} -p:RealmTestsStandaloneExe=true --no-self-contained
272264
- name: Output executable path

.github/workflows/pr.yml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,17 @@ jobs:
4646
needs:
4747
- build-packages
4848
if: always() && !cancelled() && !contains(needs.*.result, 'failure') && !contains(needs.*.result, 'cancelled')
49+
test-unity:
50+
uses: ./.github/workflows/test-unity.yml
51+
name: Test
52+
with:
53+
version: ${{ needs.build-packages.outputs.package_version }}
54+
settings: '["Mono-Net4"]'
55+
platform: '[{ "os": "windows", "testPlatform": "Windows64" }, { "os": "linux", "testPlatform": "Linux64" }]'
56+
needs:
57+
- build-packages
58+
- build-unity
59+
if: always() && !cancelled() && !contains(needs.*.result, 'failure') && !contains(needs.*.result, 'cancelled')
4960
test-net-framework:
5061
uses: ./.github/workflows/test-net-framework.yml
5162
name: Test

0 commit comments

Comments
 (0)