@@ -45,14 +45,100 @@ jobs:
4545 "winget_available=true" | Add-Content -Encoding utf8 -Path $resultPath
4646 $wingetCommand | Format-List * | Out-File -Encoding utf8 -FilePath (Join-Path $logDir "winget-command.txt")
4747
48- & winget --info *>&1 |
49- Tee-Object -FilePath (Join-Path $logDir "winget-info.log")
48+ function Write-ProbeLog {
49+ param(
50+ [Parameter(Mandatory = $true)]
51+ [string] $Path,
52+ [Parameter(Mandatory = $true)]
53+ [string] $Message
54+ )
55+
56+ $Message | Add-Content -Encoding utf8 -Path $Path
57+ Write-Host $Message
58+ }
59+
60+ function Invoke-WinGetLogged {
61+ param(
62+ [Parameter(Mandatory = $true)]
63+ [string[]] $Arguments,
64+ [Parameter(Mandatory = $true)]
65+ [string] $LogName,
66+ [Parameter(Mandatory = $true)]
67+ [int] $TimeoutSeconds
68+ )
69+
70+ $logPath = Join-Path $logDir $LogName
71+ $startedAt = Get-Date
72+ Write-ProbeLog -Path $logPath -Message "command=winget $($Arguments -join ' ')"
73+ Write-ProbeLog -Path $logPath -Message "startedAt=$($startedAt.ToUniversalTime().ToString("o"))"
74+ Write-ProbeLog -Path $logPath -Message "timeoutSeconds=$TimeoutSeconds"
75+
76+ try {
77+ $startInfo = [System.Diagnostics.ProcessStartInfo]::new()
78+ $startInfo.FileName = $wingetCommand.Source
79+ foreach ($argument in $Arguments) {
80+ [void] $startInfo.ArgumentList.Add($argument)
81+ }
82+ $startInfo.RedirectStandardOutput = $true
83+ $startInfo.RedirectStandardError = $true
84+ $startInfo.UseShellExecute = $false
85+ $startInfo.CreateNoWindow = $true
86+
87+ $process = [System.Diagnostics.Process]::new()
88+ $process.StartInfo = $startInfo
89+ [void] $process.Start()
90+
91+ $stdoutTask = $process.StandardOutput.ReadToEndAsync()
92+ $stderrTask = $process.StandardError.ReadToEndAsync()
93+ $timedOut = -not $process.WaitForExit($TimeoutSeconds * 1000)
94+
95+ if ($timedOut) {
96+ Write-ProbeLog -Path $logPath -Message "timedOut=true"
97+ try {
98+ $process.Kill($true)
99+ } catch {
100+ Write-ProbeLog -Path $logPath -Message "killException=$($_.Exception.Message)"
101+ }
102+ $process.WaitForExit()
103+ }
104+
105+ $stdout = $stdoutTask.GetAwaiter().GetResult()
106+ $stderr = $stderrTask.GetAwaiter().GetResult()
107+
108+ if (-not [string]::IsNullOrEmpty($stdout)) {
109+ Write-ProbeLog -Path $logPath -Message "stdout:"
110+ Write-ProbeLog -Path $logPath -Message $stdout
111+ }
112+
113+ if (-not [string]::IsNullOrEmpty($stderr)) {
114+ Write-ProbeLog -Path $logPath -Message "stderr:"
115+ Write-ProbeLog -Path $logPath -Message $stderr
116+ }
117+
118+ $elapsedSeconds = [int] ((Get-Date) - $startedAt).TotalSeconds
119+ Write-ProbeLog -Path $logPath -Message "elapsedSeconds=$elapsedSeconds"
120+
121+ if ($timedOut) {
122+ Write-ProbeLog -Path $logPath -Message "exitCode=124"
123+ return 124
124+ }
125+
126+ Write-ProbeLog -Path $logPath -Message "exitCode=$($process.ExitCode)"
127+ return $process.ExitCode
128+ } catch {
129+ Write-ProbeLog -Path $logPath -Message "exception=$($_.Exception.Message)"
130+ return 125
131+ }
132+ }
133+
134+ $infoExitCode = Invoke-WinGetLogged -Arguments @("--info") -LogName "winget-info.log" -TimeoutSeconds 60
135+ "infoExitCode=$infoExitCode" | Add-Content -Encoding utf8 -Path $resultPath
50136
51- & winget source list *>&1 |
52- Tee-Object -FilePath (Join -Path $logDir "winget-source-list.log")
137+ $sourceListExitCode = Invoke-WinGetLogged -Arguments @(" source", " list") -LogName "winget-source-list.log" -TimeoutSeconds 120
138+ "sourceListExitCode=$sourceListExitCode" | Add-Content -Encoding utf8 -Path $resultPath
53139
54- & winget source update *>&1 |
55- Tee-Object -FilePath (Join -Path $logDir "winget-source-update.log")
140+ $sourceUpdateExitCode = Invoke-WinGetLogged -Arguments @(" source", " update") -LogName "winget-source-update.log" -TimeoutSeconds 180
141+ "sourceUpdateExitCode=$sourceUpdateExitCode" | Add-Content -Encoding utf8 -Path $resultPath
56142
57143 $downloadArgs = @(
58144 "download",
70156 "winget $($downloadArgs -join ' ')" |
71157 Set-Content -Encoding utf8 -Path (Join-Path $logDir "winget-download-command.txt")
72158
73- & winget @downloadArgs *>&1 |
74- Tee-Object -FilePath (Join-Path $logDir "winget-download-arm64.log")
75- $downloadExitCode = $LASTEXITCODE
159+ $downloadExitCode = Invoke-WinGetLogged -Arguments $downloadArgs -LogName "winget-download-arm64.log" -TimeoutSeconds 600
76160 "exitCode=$downloadExitCode" | Add-Content -Encoding utf8 -Path $resultPath
77161
78162 $files = @(Get-ChildItem -LiteralPath $outputDir -Recurse -File -ErrorAction SilentlyContinue)
0 commit comments