Skip to content

Commit 58f8377

Browse files
committed
Enhance winget publish workflow to use GitHub API headers and improve output handling
1 parent e842da6 commit 58f8377

File tree

1 file changed

+27
-8
lines changed

1 file changed

+27
-8
lines changed

.github/workflows/publish-winget.yml

Lines changed: 27 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -35,25 +35,44 @@ jobs:
3535
3636
- name: Fetch release info
3737
id: release_info
38+
env:
39+
GH_API: https://api.github.com
3840
run: |
41+
$ErrorActionPreference = 'Stop'
42+
43+
$headers = @{
44+
Authorization = "Bearer $env:GITHUB_TOKEN"
45+
"User-Agent" = "netbird-winget-action"
46+
Accept = "application/vnd.github+json"
47+
"X-GitHub-Api-Version"= "2022-11-28"
48+
}
49+
3950
if ("${{ github.event_name }}" -eq "workflow_dispatch") {
4051
# For manual dispatch, fetch release info from GitHub API
41-
$release = Invoke-RestMethod -Uri "https://api.github.com/repos/netbirdio/netbird/releases/tags/v${{ env.VERSION }}"
52+
$release = Invoke-RestMethod -Headers $headers -Uri "$env:GH_API/repos/netbirdio/netbird/releases/tags/v${{ env.VERSION }}"
4253
} else {
4354
# For release event, use the current release
44-
$release = Invoke-RestMethod -Uri "${{ github.event.release.url }}"
55+
$release = Invoke-RestMethod -Headers $headers -Uri "${{ github.event.release.url }}"
4556
}
46-
57+
4758
# Find MSI installer URL
48-
$installerUrl = $release.assets | Where-Object { $_.name -like "*windows_amd64.msi" } | Select-Object -ExpandProperty browser_download_url
49-
59+
$installerUrl = $release.assets |
60+
Where-Object { $_.name -like "*windows_amd64.msi" } |
61+
Select-Object -ExpandProperty browser_download_url -First 1
62+
5063
if (-not $installerUrl) {
5164
Write-Error "No MSI installer found for version ${{ env.VERSION }}"
5265
exit 1
5366
}
54-
55-
echo "installer_url=$installerUrl" >> $env:GITHUB_OUTPUT
56-
echo "release_notes=$($release.body)" >> $env:GITHUB_OUTPUT
67+
68+
# Write single-line output safely
69+
"installer_url=$installerUrl" | Out-File -FilePath $env:GITHUB_OUTPUT -Append
70+
71+
# Write multiline release notes using a unique delimiter
72+
$delim = "EOF_$([Guid]::NewGuid().ToString('N'))"
73+
Add-Content -Path $env:GITHUB_OUTPUT -Value "release_notes<<$delim"
74+
Add-Content -Path $env:GITHUB_OUTPUT -Value ($release.body -replace "`r","")
75+
Add-Content -Path $env:GITHUB_OUTPUT -Value $delim
5776
5877
- name: Update Winget Manifest
5978
run: |

0 commit comments

Comments
 (0)