Skip to content

Commit

Permalink
chore: fix integration test scripts for macOS CI
Browse files Browse the repository at this point in the history
  • Loading branch information
vaind committed May 2, 2022
1 parent 6eae8b1 commit b0a49dd
Show file tree
Hide file tree
Showing 7 changed files with 26 additions and 42 deletions.
8 changes: 4 additions & 4 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -317,10 +317,10 @@ jobs:
run: New-Item -ItemType SymbolicLink -Path "C:\${{ steps.env.outputs.unityVersion }}" -Target "C:\Program Files\Unity\Hub\Editor\${{ steps.env.outputs.unityVersion }}"

- name: Create new Project
run: ./test/Scripts.Integration.Test/integration-create-project.ps1 "${{ env.UNITY_PATH }}"
run: ./test/Scripts.Integration.Test/integration-create-project.ps1 -UnityPath "${{ env.UNITY_PATH }}"

- name: Build Standalone Player without Sentry SDK
run: ./test/Scripts.Integration.Test/integration-build-project.ps1 "${{ env.UNITY_PATH }}"
run: ./test/Scripts.Integration.Test/integration-build-project.ps1 -UnityPath "${{ env.UNITY_PATH }}"

- name: Download UPM package
uses: vaind/download-artifact@989a39a417730897d098ab11c34e49ac4e13ed70
Expand All @@ -333,10 +333,10 @@ jobs:
run: ./test/Scripts.Integration.Test/integration-extract-package.ps1

- name: Add Sentry to test project
run: ./test/Scripts.Integration.Test/integration-update-sentry.ps1 "${{ env.UNITY_PATH }}"
run: ./test/Scripts.Integration.Test/integration-update-sentry.ps1 -UnityPath "${{ env.UNITY_PATH }}"

- name: Build Standalone Player Sentry SDK
run: ./test/Scripts.Integration.Test/integration-build-project.ps1 "${{ env.UNITY_PATH }}"
run: ./test/Scripts.Integration.Test/integration-build-project.ps1 -UnityPath "${{ env.UNITY_PATH }}"

- name: Run Player - Smoke Test
run: ./test/Scripts.Integration.Test/integration-run-smoke-test.ps1 -Smoke
Expand Down
44 changes: 16 additions & 28 deletions scripts/unity-utils.ps1
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
$RunUnityLicenseRetryTimeoutSeconds = 3600
$RunUnityLicenseRetryIntervalSeconds = 60
$RunUnityLogFile = 'unity.log'

function RunUnity([string] $unityPath, [string[]] $arguments)
function RunUnity([string] $unityPath, [string[]] $arguments, [switch] $ReturnLogOutput)
{
If ($unityPath.StartsWith("docker "))
{
Expand All @@ -24,30 +23,32 @@ function RunUnity([string] $unityPath, [string[]] $arguments)
$unityPath = "xvfb-run"
}

$logFilePath = "$pwd/unity.log"

foreach ($arg in $arguments)
{
if ($arg -ieq "logfile" -or $arg -ieq "-logfile")
{
# Note: if we really needed to use a custom value: get the next arg and overwrite $RunUnityLogFile.
# Note: if we really needed to use a custom value: get the next arg and overwrite $logFilePath.
# The only issue then would be if it was stdout ('-').
throw "You must not pass the 'logfile' argument - this script needs to set it to a custom value."
}
}

$arguments += @("-logfile", $RunUnityLogFile)
$arguments += @("-logfile", $logFilePath)

$stopwatch = [System.Diagnostics.Stopwatch]::new()
$stopwatch.Start()

do
{
ClearUnityLog
ClearUnityLog $logFilePath
New-Item $logFilePath

Write-Host "Running $unityPath $arguments"
$process = Start-Process -FilePath $unityPath -ArgumentList $arguments -PassThru

Write-Host "Waiting for Unity to finish."
WaitForLogFile 30
$stdout = SubscribeToUnityLogFile $process
$stdout = WaitForUnityExit $logFilePath $process

if ($stdout -match "No valid Unity Editor license found. Please activate your license.")
{
Expand All @@ -66,46 +67,33 @@ function RunUnity([string] $unityPath, [string[]] $arguments)
{
Throw "Unity exited with code $($process.ExitCode)"
}
return $stdout
return $ReturnLogOutput ? $stdout : $null
}
} while ($stopwatch.Elapsed.TotalSeconds -lt $RunUnityLicenseRetryTimeoutSeconds)
}

function ClearUnityLog
function ClearUnityLog([string] $logFilePath)
{
Write-Host -NoNewline "Removing Unity log:"
If (Test-Path -Path "$RunUnityLogFile")
If (Test-Path -Path $logFilePath)
{
#Force is required if it's opened by another process.
Remove-Item -Path "$RunUnityLogFile" -Force
Remove-Item -Path $logFilePath -Force
}
Write-Host " OK"
}

function WaitForLogFile
{
for ($i = 0; $i -lt 30; $i++)
{
if (Test-Path -Path "$RunUnityLogFile")
{
return
}
Write-Host "Waiting for log file to appear: $RunUnityLogFile ..."
Start-Sleep -Seconds 1
}
Throw "Timeout while waiting for the log file to appear: $RunUnityLogFile"
}

function SubscribeToUnityLogFile([System.Diagnostics.Process] $unityProcess)
function WaitForUnityExit([string] $RunUnityLogFile, [System.Diagnostics.Process] $unityProcess)
{
Write-Host "Waiting for Unity to finish."
$unityClosedDelay = 0

If ($unityProcess -eq $null)
{
Throw "Unity process not received"
}

$logFileStream = New-Object System.IO.FileStream("$RunUnityLogFile", [System.IO.FileMode]::Open, [System.IO.FileAccess]::Read, [System.IO.FileShare]::ReadWrite)
$logFileStream = New-Object System.IO.FileStream($RunUnityLogFile, [System.IO.FileMode]::Open, [System.IO.FileAccess]::Read, [System.IO.FileShare]::ReadWrite)
If (-not $logFileStream)
{
Throw "Failed to open logfile on $RunUnityLogFile"
Expand Down
2 changes: 1 addition & 1 deletion scripts/unity.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ $ErrorActionPreference = "Stop"
. $PSScriptRoot/unity-utils.ps1

# Redirecting the output to $null because RunUnity prints logs using Write-Host AND Write-Output - we don't need both here.
RunUnity $args[0] ($args | Select-Object -Skip 1) > $null
RunUnity $args[0] ($args | Select-Object -Skip 1)
4 changes: 2 additions & 2 deletions test/Scripts.Integration.Test/IntegrationGlobals.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,9 @@ function FormatUnityPath
If ($path)
{
#Ajust path on MacOS
If ($path -match "Unity.app/$")
If ($path -match "Unity.app/?$")
{
$path = $path + "Contents/MacOS"
$path = $path + "/Contents/MacOS"
}
$unityPath = $path
}
Expand Down
4 changes: 1 addition & 3 deletions test/Scripts.Integration.Test/integration-build-project.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,8 @@ $unityPath = FormatUnityPath $UnityPath
$buildMethod = BuildMethodFor $Platform
$outputPath = "$NewProjectBuildPath/$(GetTestAppName $buildMethod)"

ClearUnityLog

Write-Host -NoNewline "Executing ${buildMethod}:"
RunUnityCustom $unityPath @("-batchmode", "-projectPath ", "$NewProjectPath", `
"-executeMethod", $buildMethod , "-buildPath", $outputPath, "-quit") > $null
"-executeMethod", $buildMethod , "-buildPath", $outputPath, "-quit")
Write-Host "Project built successfully" -ForegroundColor Green
Get-ChildItem $NewProjectBuildPath
4 changes: 1 addition & 3 deletions test/Scripts.Integration.Test/integration-create-project.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,12 @@ If (Test-Path -Path "$NewProjectPath" )
Write-Host " OK"
}

ClearUnityLog

Write-Host -NoNewline "Creating directory for integration test:"
New-Item -Path "$(ProjectRoot)/samples" -Name $NewProjectName -ItemType "directory"
Write-Host " OK"

Write-Host "Creating integration project:"
RunUnityCustom $UnityPath @("-batchmode", "-createProject", "$NewProjectPath", "-quit") > $null
RunUnityCustom $UnityPath @("-batchmode", "-createProject", "$NewProjectPath", "-quit")

Write-Host -NoNewline "Copying Test scene"
New-Item -Path "$NewProjectAssetsPath/Scenes" -Name $NewProjectName -ItemType "directory"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ $UnityPath = FormatUnityPath $UnityPath

function RunUnityAndExpect([string] $name, [string] $successMessage, [string] $failMessage, [string[]] $arguments)
{
$stdout = RunUnityCustom $UnityPath $arguments
$stdout = RunUnityCustom $UnityPath $arguments -ReturnLogOutput
If ($null -ne ($stdout | Select-String $successMessage))
{
Write-Host "`n$name | SUCCESS" -ForegroundColor Green
Expand Down

0 comments on commit b0a49dd

Please sign in to comment.