From a5e1337b52cbdf35f20240c9197745e9823f8c9f Mon Sep 17 00:00:00 2001 From: Johannes Schindelin Date: Fri, 17 Apr 2026 11:57:29 +0200 Subject: [PATCH] fixup! Adding winget workflows The `wingetcreate.exe submit` command uses a GitHub token to fork microsoft/winget-pkgs (if needed) and open a PR with the new manifest. When the fork already exists but is behind upstream, wingetcreate fails with "The forked repository could not be synced with the upstream commits. Sync your fork manually and try again." This happened in https://github.com/microsoft/git/actions/runs/24558034627/job/71799343977 because dscho/winget-pkgs was 21,033 commits behind upstream. Fix this by calling the GitHub REST API's "sync a fork branch with the upstream repository" endpoint before invoking `submit`: POST /repos/{owner}/{repo}/merge-upstream (documented at https://docs.github.com/en/rest/branches/branches#sync-a-fork-branch-with-the-upstream-repository) This is the programmatic equivalent of clicking the "Sync fork" / "Update branch" button in the GitHub web UI. The sync call is wrapped in a try/catch that tolerates a 404 response, because on the very first run there may be no fork yet. In that case `wingetcreate submit` will create the fork fresh (and therefore up-to-date), so a 404 is harmless. Any other error is re-thrown so the workflow still fails visibly. Assisted-by: Claude Opus 4.6 Signed-off-by: Johannes Schindelin --- .github/workflows/release-winget.yml | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/.github/workflows/release-winget.yml b/.github/workflows/release-winget.yml index 42a78fcfe884ee..bbcfe78a248911 100644 --- a/.github/workflows/release-winget.yml +++ b/.github/workflows/release-winget.yml @@ -76,6 +76,32 @@ jobs: "$($asset_arm64_url)|arm64|machine" ` "$($asset_arm64_url)|arm64|user" + # Sync the winget-pkgs fork with upstream before submitting, + # to avoid "The forked repository could not be synced with + # the upstream commits" errors from wingetcreate. + # If the fork does not exist yet, wingetcreate will create + # it fresh (and therefore up-to-date), so a 404 is fine. + # See https://docs.github.com/en/rest/branches/branches#sync-a-fork-branch-with-the-upstream-repository + $headers = @{ + Authorization = "token $env:WINGET_CREATE_GITHUB_TOKEN" + Accept = "application/vnd.github+json" + } + $user = (Invoke-RestMethod -Uri "https://api.github.com/user" -Headers $headers).login + try { + Invoke-RestMethod -Method Post ` + -Uri "https://api.github.com/repos/$user/winget-pkgs/merge-upstream" ` + -Headers $headers ` + -Body '{"branch":"master"}' ` + -ContentType "application/json" + Write-Host "Synced $user/winget-pkgs fork with upstream." + } catch { + if ($_.Exception.Response.StatusCode.value__ -eq 404) { + Write-Host "No fork found at $user/winget-pkgs; wingetcreate will create one." + } else { + throw + } + } + # Submit the manifest to the winget-pkgs repository $manifestDirectory = "$PWD\manifests\m\Microsoft\Git\$version" $output = & .\wingetcreate.exe submit $manifestDirectory