Skip to content

Commit ca237e7

Browse files
committed
fix(windows release): Fix stable version detection
Authentication check - Verifies if GitHub token is available Repository validation - Shows which repository we're querying Exit code monitoring - Captures gh CLI exit codes for diagnosis Detailed error messages - Shows both exceptions and command output
1 parent 66f57d6 commit ca237e7

File tree

1 file changed

+92
-6
lines changed

1 file changed

+92
-6
lines changed

.github/workflows/windows_build.yml

Lines changed: 92 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -194,10 +194,55 @@ jobs:
194194
if ($isPreRelease) {
195195
# For pre-releases, compare against latest stable release
196196
Write-Host "Fetching latest stable release..."
197-
$releases = gh release list --limit 50 --json tagName,isPrerelease 2>$null
197+
Write-Host "GitHub token available: $($env:GH_TOKEN -ne $null -and $env:GH_TOKEN -ne '')"
198+
Write-Host "Repository: ${{ github.repository }}"
199+
200+
# Try multiple approaches to fetch releases
201+
$releases = $null
202+
203+
# First try with gh CLI
204+
try {
205+
$releases = gh release list --repo "${{ github.repository }}" --limit 50 --json tagName,isPrerelease 2>&1
206+
if ($LASTEXITCODE -ne 0) {
207+
Write-Host "gh CLI failed with exit code: $LASTEXITCODE"
208+
Write-Host "gh CLI output: $releases"
209+
$releases = $null
210+
}
211+
}
212+
catch {
213+
Write-Host "gh CLI exception: $($_.Exception.Message)"
214+
$releases = $null
215+
}
216+
217+
# Fallback to REST API if gh CLI fails
198218
if (-not $releases) {
199-
Write-Host "Failed to fetch releases"
200-
echo "notes=" >> $env:GITHUB_OUTPUT
219+
Write-Host "Trying REST API fallback..."
220+
try {
221+
$releases = gh api "repos/${{ github.repository }}/releases?per_page=50" --jq '.[] | {tagName: .tag_name, isPrerelease: .prerelease}' | ConvertTo-Json -AsArray
222+
}
223+
catch {
224+
Write-Host "REST API also failed: $($_.Exception.Message)"
225+
}
226+
}
227+
228+
if (-not $releases) {
229+
Write-Host "All methods failed to fetch releases, using fallback"
230+
$fallbackNotes = @"
231+
## 🚧 Development Build
232+
233+
**⚠️ This is an unstable development build. Use at your own risk!**
234+
235+
### Recent Changes:
236+
Unable to fetch detailed change log. This build contains the latest development changes.
237+
238+
---
239+
**Build Info:**
240+
- Commit: [${{ github.sha }}](https://github.com/${{ github.repository }}/commit/${{ github.sha }})
241+
- Build: #${{ github.run_number }}
242+
- Date: $(Get-Date -Format 'yyyy-MM-dd HH:mm:ss UTC')
243+
"@
244+
$fallbackNotes = $fallbackNotes -replace "(\r\n|\r|\n)", "%0A"
245+
echo "notes=$fallbackNotes" >> $env:GITHUB_OUTPUT
201246
return
202247
}
203248
@@ -217,10 +262,51 @@ jobs:
217262
} elseif ($isStableRelease) {
218263
# For stable releases, compare against previous release (stable or pre-release)
219264
Write-Host "Fetching previous releases..."
220-
$releases = gh release list --limit 50 --json tagName 2>$null
265+
Write-Host "Repository: ${{ github.repository }}"
266+
267+
# Try multiple approaches to fetch releases
268+
$releases = $null
269+
270+
# First try with gh CLI
271+
try {
272+
$releases = gh release list --repo "${{ github.repository }}" --limit 50 --json tagName 2>&1
273+
if ($LASTEXITCODE -ne 0) {
274+
Write-Host "gh CLI failed with exit code: $LASTEXITCODE"
275+
$releases = $null
276+
}
277+
}
278+
catch {
279+
Write-Host "gh CLI exception: $($_.Exception.Message)"
280+
$releases = $null
281+
}
282+
283+
# Fallback to REST API if gh CLI fails
221284
if (-not $releases) {
222-
Write-Host "Failed to fetch releases"
223-
echo "notes=" >> $env:GITHUB_OUTPUT
285+
Write-Host "Trying REST API fallback..."
286+
try {
287+
$releases = gh api "repos/${{ github.repository }}/releases?per_page=50" --jq '.[] | {tagName: .tag_name}' | ConvertTo-Json -AsArray
288+
}
289+
catch {
290+
Write-Host "REST API also failed: $($_.Exception.Message)"
291+
}
292+
}
293+
294+
if (-not $releases) {
295+
Write-Host "All methods failed to fetch releases, using fallback"
296+
$currentVersion = "${{ github.ref }}" -replace "refs/tags/", ""
297+
$fallbackNotes = @"
298+
## 🎉 Stable Release
299+
300+
### Release $currentVersion:
301+
Unable to fetch detailed change log. Please refer to the commit history for changes.
302+
303+
---
304+
**Release Info:**
305+
- Version: $currentVersion
306+
- Date: $(Get-Date -Format 'yyyy-MM-dd HH:mm:ss UTC')
307+
"@
308+
$fallbackNotes = $fallbackNotes -replace "(\r\n|\r|\n)", "%0A"
309+
echo "notes=$fallbackNotes" >> $env:GITHUB_OUTPUT
224310
return
225311
}
226312

0 commit comments

Comments
 (0)