2020
2121 - name : Set up WingetCreate
2222 shell : pwsh
23- run : |
24- Invoke-WebRequest https://aka.ms/wingetcreate/latest -OutFile wingetcreate.exe
23+ run : Invoke-WebRequest https://aka.ms/wingetcreate/latest -OutFile wingetcreate.exe
2524
2625 - name : Determine version
2726 id : version
7877 "installer_urls_file=installer_urls.txt" >> $env:GITHUB_OUTPUT
7978 "installer_url=$($any[0])" >> $env:GITHUB_OUTPUT
8079
81- # --- PAT-owner-based fork handling + sync ---
80+ # ---------- Fork under PAT owner, then sync ------- ---
8281
8382 - name : Install GitHub CLI
8483 shell : pwsh
@@ -90,32 +89,50 @@ jobs:
9089 env :
9190 WINGET_PAT : ${{ secrets.WINGET_PAT }}
9291 run : |
93- # Make PAT available to gh
9492 echo "GH_TOKEN=$env:WINGET_PAT" >> $env:GITHUB_ENV
9593
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
94+ $u = gh api /user --jq "{login: .login, type: .type}"
95+ if (-not $u) { throw "Could not determine PAT owner via /user" }
96+ $obj = $u | ConvertFrom-Json
97+ "FORK_OWNER=$($obj.login)" >> $env:GITHUB_ENV
98+ "FORK_OWNER_TYPE=$($obj.type)" >> $env:GITHUB_ENV
99+ Write-Host "PAT owner: $($obj.login) ($($obj.type))"
101100
102- - name : Ensure fork exists under PAT owner (create if missing)
101+ - name : Ensure fork exists (create if missing) under PAT owner
103102 shell : pwsh
104103 env :
105104 GH_TOKEN : ${{ env.GH_TOKEN }}
106105 run : |
107- $fork = "${{ env.FORK_OWNER }}/winget-pkgs"
108- Write-Host "Checking for fork $fork ..."
106+ $owner = "${{ env.FORK_OWNER }}"
107+ $forkSlug = "$owner/winget-pkgs"
108+
109+ Write-Host "Checking for fork $forkSlug ..."
109110 $exists = $false
110111 try {
111- gh repo view $fork --json name -q .name | Out-Null
112- $exists = $LASTEXITCODE -eq 0
112+ gh repo view $forkSlug --json name -q .name | Out-Null
113+ if ( $LASTEXITCODE -eq 0) { $exists = $true }
113114 } catch { $exists = $false }
114115
115116 if (-not $exists) {
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
117+ Write-Host "Fork not found; creating under $owner ..."
118+ # POST /repos/{owner}/{repo}/forks; add organization=... if PAT owner is an Organization
119+ if ("${{ env.FORK_OWNER_TYPE }}" -eq "Organization") {
120+ gh api --method POST -H "Accept: application/vnd.github+json" /repos/microsoft/winget-pkgs/forks -f organization="$owner" -F default_branch_only=true
121+ } else {
122+ gh api --method POST -H "Accept: application/vnd.github+json" /repos/microsoft/winget-pkgs/forks -F default_branch_only=true
123+ }
124+
125+ # Forking is async: poll until the repo appears (max ~90s)
126+ $deadline = (Get-Date).AddSeconds(90)
127+ do {
128+ Start-Sleep -Seconds 3
129+ try {
130+ gh repo view $forkSlug --json defaultBranchRef -q .defaultBranchRef.name | Out-Null
131+ if ($LASTEXITCODE -eq 0) { $exists = $true }
132+ } catch { $exists = $false }
133+ } until ($exists -or (Get-Date) -gt $deadline)
134+
135+ if (-not $exists) { throw "Fork creation did not complete in time for $forkSlug." }
119136 } else {
120137 Write-Host "Fork already exists."
121138 }
@@ -124,10 +141,9 @@ jobs:
124141 shell : pwsh
125142 env :
126143 GH_TOKEN : ${{ env.GH_TOKEN }}
127- run : |
128- gh repo sync "${{ env.FORK_OWNER }}/winget-pkgs" -b master --force
144+ run : gh repo sync "${{ env.FORK_OWNER }}/winget-pkgs" -b master --force
129145
130- # --- end fork handling ---
146+ # ---------- Submit with wingetcreate ------- ---
131147
132148 - name : Update Winget Manifest
133149 shell : pwsh
0 commit comments