test: add timeouts to winget arm64 probe #2
Workflow file for this run
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Probe WinGet ARM64 Store Download | |
| on: | |
| workflow_dispatch: | |
| push: | |
| branches: | |
| - codex/probe-winget-arm64 | |
| permissions: | |
| contents: read | |
| jobs: | |
| probe: | |
| name: Probe WinGet ARM64 download | |
| runs-on: windows-latest | |
| timeout-minutes: 45 | |
| steps: | |
| - uses: actions/checkout@v6 | |
| - name: Download Codex ARM64 via WinGet | |
| id: winget | |
| shell: pwsh | |
| run: | | |
| $ErrorActionPreference = "Continue" | |
| $ProgressPreference = "SilentlyContinue" | |
| New-Item -ItemType Directory -Force -Path winget-output, winget-logs | Out-Null | |
| $outputDir = (Resolve-Path "winget-output").Path | |
| $logDir = (Resolve-Path "winget-logs").Path | |
| $resultPath = Join-Path $logDir "result.txt" | |
| "timestamp=$((Get-Date).ToUniversalTime().ToString("o"))" | Set-Content -Encoding utf8 -Path $resultPath | |
| "runner_os=$env:RUNNER_OS" | Add-Content -Encoding utf8 -Path $resultPath | |
| "processor_architecture=$env:PROCESSOR_ARCHITECTURE" | Add-Content -Encoding utf8 -Path $resultPath | |
| $wingetCommand = Get-Command winget -ErrorAction SilentlyContinue | |
| if (-not $wingetCommand) { | |
| "winget_available=false" | Add-Content -Encoding utf8 -Path $resultPath | |
| "exitCode=127" | Add-Content -Encoding utf8 -Path $resultPath | |
| "arm64PackageCount=0" | Out-File -FilePath $env:GITHUB_OUTPUT -Encoding utf8 -Append | |
| exit 0 | |
| } | |
| "winget_available=true" | Add-Content -Encoding utf8 -Path $resultPath | |
| $wingetCommand | Format-List * | Out-File -Encoding utf8 -FilePath (Join-Path $logDir "winget-command.txt") | |
| function Write-ProbeLog { | |
| param( | |
| [Parameter(Mandatory = $true)] | |
| [string] $Path, | |
| [Parameter(Mandatory = $true)] | |
| [string] $Message | |
| ) | |
| $Message | Add-Content -Encoding utf8 -Path $Path | |
| Write-Host $Message | |
| } | |
| function Invoke-WinGetLogged { | |
| param( | |
| [Parameter(Mandatory = $true)] | |
| [string[]] $Arguments, | |
| [Parameter(Mandatory = $true)] | |
| [string] $LogName, | |
| [Parameter(Mandatory = $true)] | |
| [int] $TimeoutSeconds | |
| ) | |
| $logPath = Join-Path $logDir $LogName | |
| $startedAt = Get-Date | |
| Write-ProbeLog -Path $logPath -Message "command=winget $($Arguments -join ' ')" | |
| Write-ProbeLog -Path $logPath -Message "startedAt=$($startedAt.ToUniversalTime().ToString("o"))" | |
| Write-ProbeLog -Path $logPath -Message "timeoutSeconds=$TimeoutSeconds" | |
| try { | |
| $startInfo = [System.Diagnostics.ProcessStartInfo]::new() | |
| $startInfo.FileName = $wingetCommand.Source | |
| foreach ($argument in $Arguments) { | |
| [void] $startInfo.ArgumentList.Add($argument) | |
| } | |
| $startInfo.RedirectStandardOutput = $true | |
| $startInfo.RedirectStandardError = $true | |
| $startInfo.UseShellExecute = $false | |
| $startInfo.CreateNoWindow = $true | |
| $process = [System.Diagnostics.Process]::new() | |
| $process.StartInfo = $startInfo | |
| [void] $process.Start() | |
| $stdoutTask = $process.StandardOutput.ReadToEndAsync() | |
| $stderrTask = $process.StandardError.ReadToEndAsync() | |
| $timedOut = -not $process.WaitForExit($TimeoutSeconds * 1000) | |
| if ($timedOut) { | |
| Write-ProbeLog -Path $logPath -Message "timedOut=true" | |
| try { | |
| $process.Kill($true) | |
| } catch { | |
| Write-ProbeLog -Path $logPath -Message "killException=$($_.Exception.Message)" | |
| } | |
| $process.WaitForExit() | |
| } | |
| $stdout = $stdoutTask.GetAwaiter().GetResult() | |
| $stderr = $stderrTask.GetAwaiter().GetResult() | |
| if (-not [string]::IsNullOrEmpty($stdout)) { | |
| Write-ProbeLog -Path $logPath -Message "stdout:" | |
| Write-ProbeLog -Path $logPath -Message $stdout | |
| } | |
| if (-not [string]::IsNullOrEmpty($stderr)) { | |
| Write-ProbeLog -Path $logPath -Message "stderr:" | |
| Write-ProbeLog -Path $logPath -Message $stderr | |
| } | |
| $elapsedSeconds = [int] ((Get-Date) - $startedAt).TotalSeconds | |
| Write-ProbeLog -Path $logPath -Message "elapsedSeconds=$elapsedSeconds" | |
| if ($timedOut) { | |
| Write-ProbeLog -Path $logPath -Message "exitCode=124" | |
| return 124 | |
| } | |
| Write-ProbeLog -Path $logPath -Message "exitCode=$($process.ExitCode)" | |
| return $process.ExitCode | |
| } catch { | |
| Write-ProbeLog -Path $logPath -Message "exception=$($_.Exception.Message)" | |
| return 125 | |
| } | |
| } | |
| $infoExitCode = Invoke-WinGetLogged -Arguments @("--info") -LogName "winget-info.log" -TimeoutSeconds 60 | |
| "infoExitCode=$infoExitCode" | Add-Content -Encoding utf8 -Path $resultPath | |
| $sourceListExitCode = Invoke-WinGetLogged -Arguments @("source", "list") -LogName "winget-source-list.log" -TimeoutSeconds 120 | |
| "sourceListExitCode=$sourceListExitCode" | Add-Content -Encoding utf8 -Path $resultPath | |
| $sourceUpdateExitCode = Invoke-WinGetLogged -Arguments @("source", "update") -LogName "winget-source-update.log" -TimeoutSeconds 180 | |
| "sourceUpdateExitCode=$sourceUpdateExitCode" | Add-Content -Encoding utf8 -Path $resultPath | |
| $downloadArgs = @( | |
| "download", | |
| "--id", "9PLM9XGG6VKS", | |
| "--source", "msstore", | |
| "--architecture", "arm64", | |
| "--platform", "Windows.Desktop", | |
| "--skip-license", | |
| "--accept-source-agreements", | |
| "--accept-package-agreements", | |
| "--verbose-logs", | |
| "--download-directory", $outputDir | |
| ) | |
| "winget $($downloadArgs -join ' ')" | | |
| Set-Content -Encoding utf8 -Path (Join-Path $logDir "winget-download-command.txt") | |
| $downloadExitCode = Invoke-WinGetLogged -Arguments $downloadArgs -LogName "winget-download-arm64.log" -TimeoutSeconds 600 | |
| "exitCode=$downloadExitCode" | Add-Content -Encoding utf8 -Path $resultPath | |
| $files = @(Get-ChildItem -LiteralPath $outputDir -Recurse -File -ErrorAction SilentlyContinue) | |
| $files | | |
| Select-Object FullName, Name, Length, LastWriteTimeUtc | | |
| ConvertTo-Json -Depth 3 | | |
| Set-Content -Encoding utf8 -Path (Join-Path $logDir "downloaded-files.json") | |
| if ($files.Count -gt 0) { | |
| Get-FileHash -Algorithm SHA256 -LiteralPath $files.FullName | | |
| Select-Object Algorithm, Hash, Path | | |
| ConvertTo-Json -Depth 3 | | |
| Set-Content -Encoding utf8 -Path (Join-Path $logDir "downloaded-file-hashes.json") | |
| } | |
| $arm64Packages = @( | |
| $files | Where-Object { | |
| $_.Name -match '^OpenAI\.Codex_.*_arm64__.*\.(Msix|msix|Appx|appx|MsixBundle|msixbundle|AppxBundle|appxbundle)$' | |
| } | |
| ) | |
| "arm64PackageCount=$($arm64Packages.Count)" | Out-File -FilePath $env:GITHUB_OUTPUT -Encoding utf8 -Append | |
| "arm64PackageCount=$($arm64Packages.Count)" | Add-Content -Encoding utf8 -Path $resultPath | |
| if ($arm64Packages.Count -gt 0) { | |
| "arm64Packages=$($arm64Packages.Name -join ',')" | Add-Content -Encoding utf8 -Path $resultPath | |
| } | |
| exit 0 | |
| - name: Upload WinGet probe logs | |
| if: always() | |
| uses: actions/upload-artifact@v7 | |
| with: | |
| name: winget-arm64-probe-logs | |
| path: winget-logs | |
| if-no-files-found: warn | |
| - name: Fail when ARM64 package was not downloaded | |
| if: always() | |
| shell: pwsh | |
| run: | | |
| $resultPath = "winget-logs/result.txt" | |
| if (Test-Path -LiteralPath $resultPath) { | |
| Get-Content -LiteralPath $resultPath | |
| } | |
| if ("${{ steps.winget.outputs.arm64PackageCount }}" -ne "0") { | |
| exit 0 | |
| } | |
| Write-Error "WinGet did not download an OpenAI Codex ARM64 Store package." | |
| exit 1 |