@@ -58,19 +58,15 @@ jobs:
5858 }
5959
6060 $assets = $release.assets
61- if (-not $assets) {
62- throw "Release v${{ env.VERSION }} has no assets (is the tag correct and the build finished?)."
63- }
61+ if (-not $assets) { throw "Release v${{ env.VERSION }} has no assets." }
6462
6563 $msi_x64 = $assets | Where-Object { $_.name -like "*windows_amd64.msi" } | Select-Object -ExpandProperty browser_download_url -First 1
6664 $exe_x64 = $assets | Where-Object { $_.name -like "*windows_amd64.exe" } | Select-Object -ExpandProperty browser_download_url -First 1
6765 $msi_arm = $assets | Where-Object { $_.name -like "*windows_arm64.msi" } | Select-Object -ExpandProperty browser_download_url -First 1
6866 $exe_arm = $assets | Where-Object { $_.name -like "*windows_arm64.exe" } | Select-Object -ExpandProperty browser_download_url -First 1
6967
7068 $any = @($msi_x64, $exe_x64, $msi_arm, $exe_arm) | Where-Object { $_ }
71- if (-not $any -or $any.Count -eq 0) {
72- throw "No Windows installers (MSI/EXE) found in v${{ env.VERSION }}."
73- }
69+ if (-not $any) { throw "No Windows installers (MSI/EXE) found in v${{ env.VERSION }}." }
7470
7571 $qualified = @()
7672 if ($msi_x64) { $qualified += "$msi_x64|x64" }
@@ -82,55 +78,63 @@ jobs:
8278 "installer_urls_file=installer_urls.txt" >> $env:GITHUB_OUTPUT
8379 "installer_url=$($any[0])" >> $env:GITHUB_OUTPUT
8480
85- $notes = ($release.body ?? "") -replace "`r",""
86- $delimNotes = "EOF_$([Guid]::NewGuid().ToString('N'))"
87- Add-Content $env:GITHUB_OUTPUT "release_notes<<$delimNotes"
88- Add-Content $env:GITHUB_OUTPUT $notes
89- Add-Content $env:GITHUB_OUTPUT $delimNotes
90-
81+ # --- PAT-owner-based fork handling + sync ---
9182
9283 - name : Install GitHub CLI
9384 shell : pwsh
9485 run : choco install gh -y
9586
96- - name : Configure GH_TOKEN for gh CLI
87+ - name : Authenticate gh with PAT and resolve PAT owner
88+ id : whoami
9789 shell : pwsh
9890 env :
9991 WINGET_PAT : ${{ secrets.WINGET_PAT }}
10092 run : |
101- # Use PAT so 'gh' can create/sync fork
93+ # Make PAT available to gh
10294 echo "GH_TOKEN=$env:WINGET_PAT" >> $env:GITHUB_ENV
10395
104- - name : Ensure winget-pkgs fork exists (create if missing)
96+ # Use REST to get the PAT owner's login (works for classic & fine-grained PATs)
97+ $user = Invoke-RestMethod -Headers @{ Authorization = "Bearer $env:WINGET_PAT"; "User-Agent"="netbird-winget-action"; Accept="application/vnd.github+json" } -Uri "https://api.github.com/user"
98+ if (-not $user.login) { throw "Could not determine PAT owner via /user" }
99+ "FORK_OWNER=$($user.login)" >> $env:GITHUB_ENV
100+ "login=$($user.login)" >> $env:GITHUB_OUTPUT
101+
102+ - name : Ensure fork exists under PAT owner (create if missing)
105103 shell : pwsh
106104 env :
107105 GH_TOKEN : ${{ env.GH_TOKEN }}
108106 run : |
109- $forkName = "${{ github.actor }}/winget-pkgs"
110- Write-Host "Checking for fork $forkName..."
111- $exists = (gh repo view $forkName) -ne $null
107+ $fork = "${{ env.FORK_OWNER }}/winget-pkgs"
108+ Write-Host "Checking for fork $fork ..."
109+ $exists = $false
110+ try {
111+ gh repo view $fork --json name -q .name | Out-Null
112+ $exists = $LASTEXITCODE -eq 0
113+ } catch { $exists = $false }
114+
112115 if (-not $exists) {
113- Write-Host "Fork not found; creating…"
114- gh repo fork microsoft/winget-pkgs --clone=false --remote=false
116+ Write-Host "Fork not found; creating under ${{ env.FORK_OWNER }} ..."
117+ # Create the fork via REST (equivalent to: POST /repos/microsoft/winget-pkgs/forks)
118+ gh api --method POST -H "Accept: application/vnd.github+json" /repos/microsoft/winget-pkgs/forks -f default_branch_only=true
115119 } else {
116120 Write-Host "Fork already exists."
117121 }
118122
119- - name : Sync winget-pkgs fork with upstream (master)
123+ - name : Sync PAT-owner fork with upstream (master)
120124 shell : pwsh
121125 env :
122126 GH_TOKEN : ${{ env.GH_TOKEN }}
123127 run : |
124- gh repo sync "${{ github.actor }}/winget-pkgs" -b master --force
128+ gh repo sync "${{ env.FORK_OWNER }}/winget-pkgs" -b master --force
129+
130+ # --- end fork handling ---
125131
126132 - name : Update Winget Manifest
127133 shell : pwsh
128134 env :
129135 WINGET_PAT : ${{ secrets.WINGET_PAT }}
130136 run : |
131137 Write-Host "Updating Winget manifest for Netbird ${{ env.VERSION }}"
132- Write-Host "Example installer: ${{ steps.release_info.outputs.installer_url }}"
133-
134138 $urls = Get-Content "${{ steps.release_info.outputs.installer_urls_file }}" | Where-Object { $_.Trim() }
135139 if (-not $urls) { throw "No installer URLs to submit." }
136140
0 commit comments