Skip to content

Commit

Permalink
Start running Unity tests on CI (#2963)
Browse files Browse the repository at this point in the history
Co-authored-by: Bernd Wachter <[email protected]>
  • Loading branch information
nirinchev and bwachter authored Sep 1, 2022
1 parent 8d0e841 commit 2c9222a
Show file tree
Hide file tree
Showing 22 changed files with 357 additions and 64 deletions.
7 changes: 3 additions & 4 deletions .github/templates/build-unity.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#@ load("@ytt:template", "template")
#@ load("common.lib.yml", "checkoutCode", "uploadArtifacts", "nugetPackages", "setupNugetCache")
#@ load("common.lib.yml", "checkoutCode", "uploadArtifacts", "nugetPackages", "actionDownloadArtifact")
#@ load("test.lib.yml", "fetchPackageArtifacts")

#@ unityPkgName = "io.realm.unity-${{ inputs.version }}.tgz"
Expand All @@ -16,18 +16,17 @@ env:
REALM_DISABLE_ANALYTICS: true
DOTNET_NOLOGO: true
jobs:
build-unity:
prepare-unity-packages:
runs-on: windows-latest
name: Unity
timeout-minutes: 30
steps:
- #@ template.replace(checkoutCode())
- #@ template.replace(fetchPackageArtifacts(packages = nugetPackages))
- #@ setupNugetCache([ "Tools/SetupUnityPackage" ])
- name: Build Unity
run: dotnet run --project Tools/SetupUnityPackage/ -- realm --packages-path Realm/packages --pack
- #@ uploadArtifacts(unityPkgName, "Realm/Realm.Unity/" + unityPkgName)
- #@ uploadArtifacts("AssetStorePublisher-${{ inputs.version }}", "Tools/AssetStorePublisher", "${{ (github.event_name != 'pull_request' || contains(github.head_ref, 'release')) && 30 || 1 }}")
- name: Build Tests
run: #@ "dotnet run --project Tools/SetupUnityPackage/ -- tests --realm-package Realm/Realm.Unity/" + unityPkgName
- #@ uploadArtifacts("UnityTests", "Tests/Tests.Unity")
- #@ uploadArtifacts("UnityTests", "Tests/Tests.Unity")
16 changes: 15 additions & 1 deletion .github/templates/build.lib.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#@ load("@ytt:template", "template")
#@ load("common.lib.yml", "checkoutCode", "setupNugetCache")
#@ load("common.lib.yml", "checkoutCode")

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

Expand Down Expand Up @@ -110,3 +110,17 @@ build-unity:
- build-packages
if: #@ ignoreSkippedJobsCondition
#@ end

#@ def testUnity(settings, platforms):
test-unity:
uses: ./.github/workflows/test-unity.yml
name: Test
with:
version: ${{ needs.build-packages.outputs.package_version }}
settings: #@ settings
platform: #@ platforms
needs:
- build-packages
- build-unity
if: #@ ignoreSkippedJobsCondition
#@ end
2 changes: 0 additions & 2 deletions .github/templates/common.lib.yml
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@ with:
- name: Add msbuild to PATH
uses: #@ actionSetupMSBuild
if: ${{ runner.os == 'Windows' }}
- #@ setupNugetCache(projectPaths)
#@ for projectPath in projectPaths:
- name: #@ "Build " + projectPath
run: #@ "msbuild " + projectPath + target + " -p:Configuration=" + configuration + " -restore" + parsedProps
Expand All @@ -77,7 +76,6 @@ with:
#@ for prop in properties.keys():
#@ propsArg += " -p:" + prop + "=" + properties[prop]
#@ end
- #@ setupNugetCache([ projectPath ])
- name: #@ "Publish " + projectPath
run: #@ "dotnet publish " + projectPath + " -c " + configuration + " -f " + framework + " -r " + runtime + propsArg + " --no-self-contained"
- name: Output executable path
Expand Down
6 changes: 3 additions & 3 deletions .github/templates/pr.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
#@ load("@ytt:template", "template")
#@ load("common.lib.yml", "checkoutCode", "uploadArtifacts", "actionDownloadArtifact", "uploadPackagesToSleet", "cleanupWorkspace")
#@ load("build.lib.yml", "deployBaas", "cleanupBaas", "runTests", "runNetCoreTests", "buildUnity")
#@ load("build.lib.yml", "deployBaas", "cleanupBaas", "runTests", "runNetCoreTests", "buildUnity", "testUnity")
---
name: PR Build
"on":
Expand Down Expand Up @@ -34,9 +33,10 @@ jobs:
with:
build-docs: ${{ contains(github.head_ref, 'release') }}
_: #@ template.replace(buildUnity())
_: #@ template.replace(testUnity('["Mono-Net4"]', '[{ "os": "windows", "testPlatform": "Windows64" }, { "os": "linux", "testPlatform": "Linux64" }]'))
_: #@ template.replace(runTests(".NET Framework", runSyncTests = False))
_: #@ template.replace(runTests("UWP Managed", runSyncTests = False, additionalSecrets = ["Pfx_Password", "Base64_Encoded_Pfx"]))
_: #@ template.replace(runNetCoreTests("[\"net6.0\"]"))
_: #@ template.replace(runNetCoreTests('["net6.0"]'))
_: #@ template.replace(runTests("macOS", runSyncTests = False))
_: #@ template.replace(runTests("iOS", runSyncTests = False))
_: #@ template.replace(runTests("Android", runSyncTests = False, additionalSecrets=["AWS_DEVICEFARM_ACCESS_KEY_ID", "AWS_DEVICEFARM_SECRET_ACCESS_KEY", "DEVICEFARM_PROJECT_ARN", "DEVICEFARM_ANDROID_POOL_ARN"]))
Expand Down
2 changes: 1 addition & 1 deletion .github/templates/test-net-core.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#@ load("@ytt:template", "template")
#@ load("common.lib.yml", "checkoutCode", "setupDotnet")
#@ load("common.lib.yml", "checkoutCode", "uploadArtifacts", "setupDotnet")
#@ load("test.lib.yml", "fetchPackageArtifacts", "baasTestArgs", "publishTestsResults", "testDefinition", "buildTests", "dotnetBuildTests")

---
Expand Down
96 changes: 96 additions & 0 deletions .github/templates/test-unity.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
#@ load("@ytt:template", "template")
#@ load("common.lib.yml", "uploadArtifacts", "actionDownloadArtifact", "checkoutCode")
#@ load("test.lib.yml", "publishTestsResults")

#@ unityPkgName = "io.realm.unity-${{ inputs.version }}.tgz"

---
name: test-unity
"on":
workflow_call:
inputs:
version:
type: string
required: true
platform:
type: string
required: true
settings:
type: string
required: true
env:
REALM_DISABLE_ANALYTICS: true
DOTNET_NOLOGO: true
jobs:
build-tests:
runs-on:
- unity
- ${{ matrix.platform.os }}
name: Build Unity ${{ matrix.platform.os }}
strategy:
fail-fast: false
matrix:
platform: ${{ fromJson(inputs.platform) }}
settings: ${{ fromJson(inputs.settings) }}
timeout-minutes: 30
steps:
- #@ template.replace(checkoutCode())
- name: Cleanup Workspace
run: git clean -fdx
- name: Fetch Unity Package
uses: #@ actionDownloadArtifact
with:
name: #@ unityPkgName
path: Realm/Realm.Unity
- name: Fetch Unity Tests
uses: #@ actionDownloadArtifact
with:
name: UnityTests
path: Tests/Tests.Unity
- name: Build Unity Tests
run: |
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' || '-'}}
- #@ uploadArtifacts("UnityTestsRunner.${{ matrix.platform.os }}", "Tests/Tests.Unity/Player_Standalone${{ matrix.platform.testPlatform }}_${{ matrix.settings }}/")

run-tests-linux:
runs-on: ubuntu-latest
name: Unity Linux
timeout-minutes: 30
needs:
- build-tests
if: ${{ contains(inputs.platform, 'Linux') }}
steps:
- #@ template.replace(checkoutCode())
- name: Download Test Runner
uses: #@ actionDownloadArtifact
with:
name: UnityTestsRunner.linux
path: TestRunner
- name: Install xvfb
run: sudo apt install -y xvfb libglu1 libxcursor1
- name: Run Tests
run: |
chmod +x ${{ github.workspace }}/TestRunner/PlayerWithTests.x86_64
xvfb-run --auto-servernum --server-args='-screen 0 640x480x24:32' ${{ github.workspace }}/TestRunner/PlayerWithTests.x86_64 -logFile - --result=${{ github.workspace }}/TestResults.xml
- #@ publishTestsResults("TestResults.xml", "Unity Linux Mono_Net4")

run-tests-windows:
runs-on: windows-latest
name: Unity Windows
if: ${{ contains(inputs.platform, 'Windows') }}
timeout-minutes: 30
needs:
- build-tests
steps:
- #@ template.replace(checkoutCode())
- name: Download Test Runner
uses: #@ actionDownloadArtifact
with:
name: UnityTestsRunner.windows
path: TestRunner
- name: Run Tests
run: |
Start-Process ${{ github.workspace }}\TestRunner\PlayerWithTests.exe -Wait -ArgumentList "-logFile","${{ github.workspace }}\test.log","--result=${{ github.workspace }}\TestResults.xml"
cat ${{ github.workspace }}\test.log
shell: powershell
- #@ publishTestsResults("TestResults.xml", "Unity Windows Mono_Net4")
4 changes: 0 additions & 4 deletions .github/workflows/build-packages.yml
Original file line number Diff line number Diff line change
Expand Up @@ -128,10 +128,6 @@ jobs:
- name: Add msbuild to PATH
uses: microsoft/[email protected]
if: ${{ runner.os == 'Windows' }}
- uses: actions/cache@v2
with:
path: ~/.nuget/packages
key: ${{ runner.os }}-nuget-${{ hashFiles('Realm/Realm.Fody/*.csproj', 'Realm/Realm/*.csproj', 'Realm/Realm.UnityUtils/*.csproj', 'Realm/Realm.UnityWeaver/*.csproj') }}
- name: Build Realm/Realm.Fody
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 }}
- name: Build Realm/Realm
Expand Down
6 changes: 1 addition & 5 deletions .github/workflows/build-unity.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ env:
REALM_DISABLE_ANALYTICS: true
DOTNET_NOLOGO: true
jobs:
build-unity:
prepare-unity-packages:
runs-on: windows-latest
name: Unity
timeout-minutes: 30
Expand Down Expand Up @@ -43,10 +43,6 @@ jobs:
with:
name: Realm.UnityWeaver.${{ inputs.version }}
path: ${{ github.workspace }}/Realm/packages/
- uses: actions/cache@v2
with:
path: ~/.nuget/packages
key: ${{ runner.os }}-nuget-${{ hashFiles('Tools/SetupUnityPackage/*.csproj') }}
- name: Build Unity
run: dotnet run --project Tools/SetupUnityPackage/ -- realm --packages-path Realm/packages --pack
- name: Store artifacts for io.realm.unity-${{ inputs.version }}.tgz
Expand Down
8 changes: 0 additions & 8 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -202,10 +202,6 @@ jobs:
uses: actions/setup-dotnet@v1
with:
dotnet-version: 6.0.x
- uses: actions/cache@v2
with:
path: ~/.nuget/packages
key: ${{ runner.os }}-nuget-${{ hashFiles('Tests/Tests.XUnit/*.csproj') }}
- name: Publish Tests/Tests.XUnit
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
- name: Output executable path
Expand Down Expand Up @@ -263,10 +259,6 @@ jobs:
uses: actions/setup-dotnet@v1
with:
dotnet-version: 6.0.x
- uses: actions/cache@v2
with:
path: ~/.nuget/packages
key: ${{ runner.os }}-nuget-${{ hashFiles('Tests/Benchmarks/PerformanceTests/*.csproj') }}
- name: Publish Tests/Benchmarks/PerformanceTests
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
- name: Output executable path
Expand Down
11 changes: 11 additions & 0 deletions .github/workflows/pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,17 @@ jobs:
needs:
- build-packages
if: always() && !cancelled() && !contains(needs.*.result, 'failure') && !contains(needs.*.result, 'cancelled')
test-unity:
uses: ./.github/workflows/test-unity.yml
name: Test
with:
version: ${{ needs.build-packages.outputs.package_version }}
settings: '["Mono-Net4"]'
platform: '[{ "os": "windows", "testPlatform": "Windows64" }, { "os": "linux", "testPlatform": "Linux64" }]'
needs:
- build-packages
- build-unity
if: always() && !cancelled() && !contains(needs.*.result, 'failure') && !contains(needs.*.result, 'cancelled')
test-net-framework:
uses: ./.github/workflows/test-net-framework.yml
name: Test
Expand Down
4 changes: 0 additions & 4 deletions .github/workflows/test-android.yml
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,6 @@ jobs:
- name: Add msbuild to PATH
uses: microsoft/[email protected]
if: ${{ runner.os == 'Windows' }}
- uses: actions/cache@v2
with:
path: ~/.nuget/packages
key: ${{ runner.os }}-nuget-${{ hashFiles('Tests/Tests.Android/*.csproj') }}
- name: Build Tests/Tests.Android
run: msbuild Tests/Tests.Android -t:SignAndroidPackage -p:Configuration=Release -restore -p:RestoreConfigFile=Tests/Test.NuGet.Config -p:UseRealmNupkgsWithVersion=${{ inputs.version }} -p:AndroidSupportedAbis=armeabi-v7a -p:AndroidUseSharedRuntime=False -p:EmbedAssembliesIntoApk=True
- name: Configure AWS Credentials
Expand Down
4 changes: 0 additions & 4 deletions .github/workflows/test-code-coverage.yml
Original file line number Diff line number Diff line change
Expand Up @@ -124,10 +124,6 @@ jobs:
dotnet tool install coverlet.console --tool-path tools
dotnet tool install dotnet-reportgenerator-globaltool --tool-path tools
echo "${{ github.workspace }}/tools" >> $GITHUB_PATH
- uses: actions/cache@v2
with:
path: ~/.nuget/packages
key: ${{ runner.os }}-nuget-${{ hashFiles('Tests/Realm.Tests/*.csproj') }}
- name: Publish Tests/Realm.Tests
run: dotnet publish Tests/Realm.Tests -c Release -f net6.0 -r linux-x64 -p:RealmTestsStandaloneExe=true --no-self-contained
- name: Output executable path
Expand Down
4 changes: 0 additions & 4 deletions .github/workflows/test-ios.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,6 @@ jobs:
- name: Add msbuild to PATH
uses: microsoft/[email protected]
if: ${{ runner.os == 'Windows' }}
- uses: actions/cache@v2
with:
path: ~/.nuget/packages
key: ${{ runner.os }}-nuget-${{ hashFiles('Tests/Tests.iOS/*.csproj') }}
- name: Build Tests/Tests.iOS
run: msbuild Tests/Tests.iOS -p:Configuration=Release -restore -p:RestoreConfigFile=Tests/Test.NuGet.Config -p:UseRealmNupkgsWithVersion=${{ inputs.version }} -p:Platform=iPhoneSimulator
- name: Run the tests
Expand Down
4 changes: 0 additions & 4 deletions .github/workflows/test-macos.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,6 @@ jobs:
- name: Add msbuild to PATH
uses: microsoft/[email protected]
if: ${{ runner.os == 'Windows' }}
- uses: actions/cache@v2
with:
path: ~/.nuget/packages
key: ${{ runner.os }}-nuget-${{ hashFiles('Tests/Tests.XamarinMac/*.csproj') }}
- name: Build Tests/Tests.XamarinMac
run: msbuild Tests/Tests.XamarinMac -p:Configuration=Release -restore -p:RestoreConfigFile=Tests/Test.NuGet.Config -p:UseRealmNupkgsWithVersion=${{ inputs.version }}
- name: Run the tests
Expand Down
4 changes: 0 additions & 4 deletions .github/workflows/test-net-core.yml
Original file line number Diff line number Diff line change
Expand Up @@ -73,10 +73,6 @@ jobs:
with:
name: Realm.Fody.${{ inputs.version }}
path: ${{ github.workspace }}/Realm/packages/
- uses: actions/cache@v2
with:
path: ~/.nuget/packages
key: ${{ runner.os }}-nuget-${{ hashFiles('Tests/Realm.Tests/*.csproj') }}
- name: Publish Tests/Realm.Tests
run: dotnet publish Tests/Realm.Tests -c Release -f ${{ matrix.framework }} -r ${{ matrix.os.runtime }} -p:RestoreConfigFile=Tests/Test.NuGet.Config -p:UseRealmNupkgsWithVersion=${{ inputs.version }} -p:RealmTestsStandaloneExe=true --no-self-contained
- name: Output executable path
Expand Down
4 changes: 0 additions & 4 deletions .github/workflows/test-net-framework.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,6 @@ jobs:
- name: Add msbuild to PATH
uses: microsoft/[email protected]
if: ${{ runner.os == 'Windows' }}
- uses: actions/cache@v2
with:
path: ~/.nuget/packages
key: ${{ runner.os }}-nuget-${{ hashFiles('Tests/Realm.Tests/*.csproj') }}
- name: Build Tests/Realm.Tests
run: msbuild Tests/Realm.Tests -p:Configuration=Release -restore -p:RestoreConfigFile=Tests/Test.NuGet.Config -p:UseRealmNupkgsWithVersion=${{ inputs.version }} -p:TargetFramework=net461 -p:RealmTestsStandaloneExe=true
- name: Run the tests
Expand Down
Loading

0 comments on commit 2c9222a

Please sign in to comment.