Skip to content

Commit 115b6de

Browse files
committed
fix
1 parent a7175de commit 115b6de

File tree

1 file changed

+24
-31
lines changed

1 file changed

+24
-31
lines changed

.github/workflows/publish-winget.yml

Lines changed: 24 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -77,71 +77,64 @@ jobs:
7777
"installer_urls_file=installer_urls.txt" >> $env:GITHUB_OUTPUT
7878
"installer_url=$($any[0])" >> $env:GITHUB_OUTPUT
7979
80-
# ---------- Fork under PAT owner, then sync ----------
80+
# ---------- Fork under PAT user, then sync ----------
8181

8282
- name: Install GitHub CLI
8383
shell: pwsh
8484
run: choco install gh -y
8585

86-
- name: Authenticate gh with PAT and resolve PAT owner
86+
- name: Resolve PAT user (who will own the fork)
8787
id: whoami
8888
shell: pwsh
8989
env:
90-
WINGET_PAT: ${{ secrets.WINGET_PAT }}
90+
GH_TOKEN: ${{ secrets.WINGET_PAT }} # <-- set for THIS step
9191
run: |
92-
echo "GH_TOKEN=$env:WINGET_PAT" >> $env:GITHUB_ENV
93-
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))"
92+
$login = gh api /user --jq .login
93+
if (-not $login) { throw "Could not determine PAT owner via /user" }
94+
"login=$login" >> $env:GITHUB_OUTPUT
95+
Write-Host "PAT user: $login"
10096
101-
- name: Ensure fork exists (create if missing) under PAT owner
97+
- name: Ensure fork exists under PAT user (create if missing)
10298
shell: pwsh
10399
env:
104-
GH_TOKEN: ${{ env.GH_TOKEN }}
100+
GH_TOKEN: ${{ secrets.WINGET_PAT }} # <-- set for THIS step
105101
run: |
106-
$owner = "${{ env.FORK_OWNER }}"
107-
$forkSlug = "$owner/winget-pkgs"
102+
$login = "${{ steps.whoami.outputs.login }}"
103+
$fork = "$login/winget-pkgs"
104+
Write-Host "Checking fork $fork ..."
108105
109-
Write-Host "Checking for fork $forkSlug ..."
110106
$exists = $false
111107
try {
112-
gh repo view $forkSlug --json name -q .name | Out-Null
108+
gh repo view $fork --json name -q .name | Out-Null
113109
if ($LASTEXITCODE -eq 0) { $exists = $true }
114110
} catch { $exists = $false }
115111
116112
if (-not $exists) {
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)
113+
Write-Host "Fork not found; creating under $login ..."
114+
gh api --method POST -H "Accept: application/vnd.github+json" /repos/microsoft/winget-pkgs/forks -F default_branch_only=true
115+
116+
# forking is async: poll until it appears
126117
$deadline = (Get-Date).AddSeconds(90)
127118
do {
128119
Start-Sleep -Seconds 3
129120
try {
130-
gh repo view $forkSlug --json defaultBranchRef -q .defaultBranchRef.name | Out-Null
121+
gh repo view $fork --json defaultBranchRef -q .defaultBranchRef.name | Out-Null
131122
if ($LASTEXITCODE -eq 0) { $exists = $true }
132123
} catch { $exists = $false }
133124
} until ($exists -or (Get-Date) -gt $deadline)
134125
135-
if (-not $exists) { throw "Fork creation did not complete in time for $forkSlug." }
126+
if (-not $exists) { throw "Fork creation did not complete in time for $fork." }
136127
} else {
137128
Write-Host "Fork already exists."
138129
}
139130
140-
- name: Sync PAT-owner fork with upstream (master)
131+
- name: Sync fork with upstream
141132
shell: pwsh
142133
env:
143-
GH_TOKEN: ${{ env.GH_TOKEN }}
144-
run: gh repo sync "${{ env.FORK_OWNER }}/winget-pkgs" -b master --force
134+
GH_TOKEN: ${{ secrets.WINGET_PAT }} # <-- set for THIS step
135+
run: |
136+
$login = "${{ steps.whoami.outputs.login }}"
137+
gh repo sync "$login/winget-pkgs" -b master --force
145138
146139
# ---------- Submit with wingetcreate ----------
147140

0 commit comments

Comments
 (0)