Skip to content

Commit 8e5aa8b

Browse files
committed
Added fallback command in windows monitor CI
1 parent 4967bf5 commit 8e5aa8b

1 file changed

Lines changed: 66 additions & 25 deletions

File tree

.github/workflows/daily-windows-monitor.yml

Lines changed: 66 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,13 @@ jobs:
3333
shell: pwsh
3434
run: |
3535
winget --version
36-
winget source update --disable-interactivity
36+
try {
37+
winget source update --disable-interactivity
38+
} catch {
39+
Write-Host "winget source update failed; resetting sources and retrying..."
40+
winget source reset --force
41+
winget source update --disable-interactivity
42+
}
3743
3844
- name: Install or update cvecli
3945
shell: pwsh
@@ -50,11 +56,19 @@ jobs:
5056
$env:Path = "$linksPath;$env:Path"
5157
}
5258
53-
$listOutput = (winget list -e --id $env:WINGET_ID --source winget --disable-interactivity 2>&1 | Out-String)
54-
if ($listOutput -match "No installed package found") {
55-
winget install -e --id $env:WINGET_ID --source winget --accept-package-agreements --accept-source-agreements --disable-interactivity
56-
} else {
57-
winget upgrade -e --id $env:WINGET_ID --source winget --accept-package-agreements --accept-source-agreements --disable-interactivity
59+
$runWinget = {
60+
$listOutput = (winget list -e --id $env:WINGET_ID --source winget --disable-interactivity 2>&1 | Out-String)
61+
if ($listOutput -match "No installed package found") {
62+
winget install -e --id $env:WINGET_ID --source winget --accept-package-agreements --accept-source-agreements --disable-interactivity
63+
} else {
64+
winget upgrade -e --id $env:WINGET_ID --source winget --accept-package-agreements --accept-source-agreements --disable-interactivity
65+
}
66+
return $true
67+
}
68+
69+
$ok = & $runWinget
70+
if (-not $ok) {
71+
throw "winget install/upgrade did not complete"
5872
}
5973
6074
$show = (winget show -e --id $env:WINGET_ID --source winget --disable-interactivity 2>&1 | Out-String)
@@ -66,30 +80,45 @@ jobs:
6680
"WINGET_VERSION=$wgVersion" | Out-File -FilePath $env:GITHUB_ENV -Append
6781
6882
$commandPath = $null
69-
$cmd = Get-Command $env:COMMAND_NAME -ErrorAction SilentlyContinue
70-
if ($cmd) {
71-
$commandPath = $cmd.Source
72-
}
83+
for ($attempt = 1; $attempt -le 10; $attempt++) {
84+
$cmd = Get-Command $env:COMMAND_NAME -ErrorAction SilentlyContinue
85+
if ($cmd) {
86+
$commandPath = $cmd.Source
87+
}
7388
74-
if (-not $commandPath) {
75-
$candidate1 = Join-Path $linksPath "$($env:COMMAND_NAME).exe"
76-
$candidate2 = Join-Path $linksPath "$($env:COMMAND_NAME)"
77-
if (Test-Path $candidate1) {
78-
$commandPath = $candidate1
79-
} elseif (Test-Path $candidate2) {
80-
$commandPath = $candidate2
89+
if (-not $commandPath) {
90+
$candidate1 = Join-Path $linksPath "$($env:COMMAND_NAME).exe"
91+
$candidate2 = Join-Path $linksPath "$($env:COMMAND_NAME)"
92+
if (Test-Path $candidate1) {
93+
$commandPath = $candidate1
94+
} elseif (Test-Path $candidate2) {
95+
$commandPath = $candidate2
96+
}
8197
}
82-
}
8398
84-
if (-not $commandPath) {
85-
$packagesRoot = Join-Path $localAppData "Microsoft\WinGet\Packages"
86-
if (Test-Path $packagesRoot) {
87-
$found = Get-ChildItem -Path $packagesRoot -Recurse -Filter "$($env:COMMAND_NAME).exe" -ErrorAction SilentlyContinue |
88-
Select-Object -First 1
89-
if ($found) {
90-
$commandPath = $found.FullName
99+
if (-not $commandPath) {
100+
$where = (where.exe $env:COMMAND_NAME 2>$null | Select-Object -First 1)
101+
if ($where) {
102+
$commandPath = $where.ToString().Trim()
91103
}
92104
}
105+
106+
if (-not $commandPath) {
107+
$packagesRoot = Join-Path $localAppData "Microsoft\WinGet\Packages"
108+
if (Test-Path $packagesRoot) {
109+
$found = Get-ChildItem -Path $packagesRoot -Recurse -Filter "$($env:COMMAND_NAME).exe" -ErrorAction SilentlyContinue |
110+
Select-Object -First 1
111+
if ($found) {
112+
$commandPath = $found.FullName
113+
}
114+
}
115+
}
116+
117+
if ($commandPath) {
118+
break
119+
}
120+
121+
Start-Sleep -Seconds 2
93122
}
94123
95124
if ($commandPath) {
@@ -114,6 +143,12 @@ jobs:
114143
run: |
115144
$command = if ([string]::IsNullOrWhiteSpace($env:COMMAND_PATH)) { $env:COMMAND_NAME } else { $env:COMMAND_PATH }
116145
146+
if ([string]::IsNullOrWhiteSpace($command) -or -not (Get-Command $command -ErrorAction SilentlyContinue)) {
147+
"ERROR_DETAILS=Cannot run version check; '$($env:COMMAND_NAME)' not found." | Out-File -FilePath $env:GITHUB_ENV -Append
148+
"CVECLI_VERSION=unknown" | Out-File -FilePath $env:GITHUB_ENV -Append
149+
exit 0
150+
}
151+
117152
$raw = (& $command --version 2>$null | Select-Object -First 1 | ForEach-Object { $_.ToString().Trim() })
118153
$version = $raw
119154
if (-not [string]::IsNullOrWhiteSpace($raw)) {
@@ -136,6 +171,12 @@ jobs:
136171
$ErrorActionPreference = "Continue"
137172
138173
$command = if ([string]::IsNullOrWhiteSpace($env:COMMAND_PATH)) { $env:COMMAND_NAME } else { $env:COMMAND_PATH }
174+
if ([string]::IsNullOrWhiteSpace($command) -or -not (Get-Command $command -ErrorAction SilentlyContinue)) {
175+
"ERROR_DETAILS=Cannot run CVE test; '$($env:COMMAND_NAME)' not found." | Out-File -FilePath $env:GITHUB_ENV -Append
176+
"TEST_STATUS=failed" | Out-File -FilePath $env:GITHUB_ENV -Append
177+
"CVE_OUTPUT_RETURNED=no" | Out-File -FilePath $env:GITHUB_ENV -Append
178+
exit 0
179+
}
139180
140181
$output = ""
141182
$rc = 1

0 commit comments

Comments
 (0)