diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 13f2a29bd..c99a21eaf 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -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 @@ -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 diff --git a/scripts/unity-utils.ps1 b/scripts/unity-utils.ps1 index 28ca8d288..bcedc0539 100644 --- a/scripts/unity-utils.ps1 +++ b/scripts/unity-utils.ps1 @@ -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 ")) { @@ -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.") { @@ -66,38 +67,25 @@ 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) @@ -105,7 +93,7 @@ function SubscribeToUnityLogFile([System.Diagnostics.Process] $unityProcess) 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" diff --git a/scripts/unity.ps1 b/scripts/unity.ps1 index e3c1b4a55..fa6307aac 100644 --- a/scripts/unity.ps1 +++ b/scripts/unity.ps1 @@ -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 \ No newline at end of file +RunUnity $args[0] ($args | Select-Object -Skip 1) \ No newline at end of file diff --git a/test/Scripts.Integration.Test/IntegrationGlobals.ps1 b/test/Scripts.Integration.Test/IntegrationGlobals.ps1 index 061baa8bf..266ab9924 100644 --- a/test/Scripts.Integration.Test/IntegrationGlobals.ps1 +++ b/test/Scripts.Integration.Test/IntegrationGlobals.ps1 @@ -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 } diff --git a/test/Scripts.Integration.Test/integration-build-project.ps1 b/test/Scripts.Integration.Test/integration-build-project.ps1 index 8aad16983..8a3f9c00c 100644 --- a/test/Scripts.Integration.Test/integration-build-project.ps1 +++ b/test/Scripts.Integration.Test/integration-build-project.ps1 @@ -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 diff --git a/test/Scripts.Integration.Test/integration-create-project.ps1 b/test/Scripts.Integration.Test/integration-create-project.ps1 index 42f49a28b..fa5cc2cb8 100644 --- a/test/Scripts.Integration.Test/integration-create-project.ps1 +++ b/test/Scripts.Integration.Test/integration-create-project.ps1 @@ -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" diff --git a/test/Scripts.Integration.Test/integration-update-sentry.ps1 b/test/Scripts.Integration.Test/integration-update-sentry.ps1 index 2a0a39f3e..b72d200b9 100644 --- a/test/Scripts.Integration.Test/integration-update-sentry.ps1 +++ b/test/Scripts.Integration.Test/integration-update-sentry.ps1 @@ -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