From e9b6af51f70f3934b6d3037ccf4908e08f33d034 Mon Sep 17 00:00:00 2001 From: Copilot Date: Wed, 29 Apr 2026 09:26:58 +0200 Subject: [PATCH] fix: support initial winget publication Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- .github/workflows/release.yml | 53 ++++++++++++++++++++++++--- README.md | 4 ++ winget/jmanuelcorral.SquadCenter.yaml | 8 ++-- winget/update.ps1 | 12 ++++-- 4 files changed, 65 insertions(+), 12 deletions(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 7d644f1..716752b 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -164,16 +164,59 @@ jobs: run: | Invoke-WebRequest -Uri https://aka.ms/wingetcreate/latest -OutFile wingetcreate.exe + - name: Check winget package status + id: winget_status + shell: pwsh + run: | + $ErrorActionPreference = 'Stop' + $packagePath = 'manifests/j/jmanuelcorral/SquadCenter' + $headers = @{ 'User-Agent' = 'jmanuelcorral/squadcenter-release' } + $response = Invoke-WebRequest ` + -Uri "https://api.github.com/repos/microsoft/winget-pkgs/contents/$packagePath" ` + -Headers $headers ` + -SkipHttpErrorCheck + + if ($response.StatusCode -eq 200) { + echo "EXISTS=true" >> $env:GITHUB_OUTPUT + Write-Host "winget package already exists; using wingetcreate update." + } elseif ($response.StatusCode -eq 404) { + echo "EXISTS=false" >> $env:GITHUB_OUTPUT + Write-Host "winget package does not exist yet; submitting local manifest as the initial package." + } else { + throw "Unable to determine winget package status. GitHub API returned $($response.StatusCode)." + } + - name: Submit winget manifest shell: pwsh run: | + $ErrorActionPreference = 'Stop' + $packageId = 'jmanuelcorral.SquadCenter' $version = "${{ steps.version.outputs.VERSION }}" $url = "https://github.com/jmanuelcorral/squadcenter/releases/download/v${version}/Squad-Center-Setup-${version}.exe" - .\wingetcreate.exe update jmanuelcorral.SquadCenter ` - --version $version ` - --urls $url ` - --submit ` - --token $env:WINGET_TOKEN + $manifestPath = Join-Path $PWD 'winget\jmanuelcorral.SquadCenter.yaml' + + if ([string]::IsNullOrWhiteSpace($env:WINGET_TOKEN)) { + throw "WINGET_TOKEN is required. Create a GitHub PAT with repo/public_repo access, an expiration of 90 days or less, and SSO authorization for microsoft/winget-pkgs." + } + + if ("${{ steps.winget_status.outputs.EXISTS }}" -eq 'true') { + .\wingetcreate.exe update $packageId ` + --version $version ` + --urls $url ` + --submit ` + --token $env:WINGET_TOKEN ` + --no-open ` + --prtitle "$packageId version $version" + } else { + .\wingetcreate.exe submit $manifestPath ` + --token $env:WINGET_TOKEN ` + --no-open ` + --prtitle "New package: $packageId version $version" + } + + if ($LASTEXITCODE -ne 0) { + throw "wingetcreate failed. If the error mentions Microsoft Open Source PAT lifetime policy or SAML SSO, rotate WINGET_TOKEN to a GitHub PAT with an expiration of 90 days or less and authorize SSO for microsoft/winget-pkgs." + } env: WINGET_TOKEN: ${{ secrets.WINGET_TOKEN }} diff --git a/README.md b/README.md index 18240f2..71fe481 100644 --- a/README.md +++ b/README.md @@ -84,6 +84,10 @@ choco install squad-center winget install jmanuelcorral.SquadCenter ``` +> WinGet availability depends on Microsoft accepting the package submission in +> `microsoft/winget-pkgs`. If the package is not found yet, use GitHub Releases, +> Chocolatey, or npm while the initial submission is pending. + #### 🐧 apt (Debian/Ubuntu) ```bash # Add the GPG key diff --git a/winget/jmanuelcorral.SquadCenter.yaml b/winget/jmanuelcorral.SquadCenter.yaml index 2780429..6b1613f 100644 --- a/winget/jmanuelcorral.SquadCenter.yaml +++ b/winget/jmanuelcorral.SquadCenter.yaml @@ -1,6 +1,6 @@ # yaml-language-server: $schema=https://aka.ms/winget-manifest.singleton.1.6.0.schema.json PackageIdentifier: jmanuelcorral.SquadCenter -PackageVersion: 0.2.0 +PackageVersion: 0.3.1 PackageLocale: en-US Publisher: jmanuelcorral PublisherUrl: https://github.com/jmanuelcorral @@ -18,9 +18,9 @@ Tags: - electron Installers: - Architecture: x64 - InstallerType: nsis - InstallerUrl: https://github.com/jmanuelcorral/squadcenter/releases/download/v0.2.0/Squad-Center-Setup-0.2.0.exe - InstallerSha256: "" + InstallerType: nullsoft + InstallerUrl: https://github.com/jmanuelcorral/squadcenter/releases/download/v0.3.1/Squad-Center-Setup-0.3.1.exe + InstallerSha256: 617A998F0BE23D6B5AB5FF4786ED23F6949BBF97BFD5BDAB84C4516F9B0A0D6C InstallerSwitches: Silent: /S SilentWithProgress: /S diff --git a/winget/update.ps1 b/winget/update.ps1 index 686e19c..89b0f27 100644 --- a/winget/update.ps1 +++ b/winget/update.ps1 @@ -12,16 +12,22 @@ $manifestPath = Join-Path $PSScriptRoot 'jmanuelcorral.SquadCenter.yaml' Write-Host "Updating winget manifest to version $Version ..." $content = Get-Content $manifestPath -Raw +$installerUrl = "https://github.com/jmanuelcorral/squadcenter/releases/download/v${Version}/Squad-Center-Setup-${Version}.exe" # Update PackageVersion -$content = $content -replace '(?<=PackageVersion:\s)[\d]+\.[\d]+\.[\d]+', $Version +$content = $content -replace '(?m)^PackageVersion:\s.*$', "PackageVersion: $Version" # Update InstallerUrl -$content = $content -replace 'v[\d]+\.[\d]+\.[\d]+/Squad-Center-Setup-[\d]+\.[\d]+\.[\d]+\.exe', "v${Version}/Squad-Center-Setup-${Version}.exe" +$content = $content -replace '(?m)^ InstallerUrl:\s.*$', " InstallerUrl: $installerUrl" # Update InstallerSha256 if ($Sha256) { - $content = $content -replace '(?<=InstallerSha256:\s).*', $Sha256 + $normalizedSha = $Sha256.Trim().ToUpperInvariant() + if ($normalizedSha -notmatch '^[A-F0-9]{64}$') { + throw "Invalid SHA256 value: $Sha256" + } + + $content = $content -replace '(?m)^ InstallerSha256:\s.*$', " InstallerSha256: $normalizedSha" } Set-Content -Path $manifestPath -Value $content -NoNewline -Encoding UTF8