From 0be848f6914ba143b5901c44e4660c4e8cbe3116 Mon Sep 17 00:00:00 2001 From: PrimeBuild Date: Sat, 28 Nov 2026 14:45:52 +0100 Subject: [PATCH] fix: validate release versions and WinGet submission results --- .github/workflows/release.yml | 19 ++++++++----------- build/submit-winget-pr.ps1 | 24 +++++++++++++++++++++--- 2 files changed, 29 insertions(+), 14 deletions(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index e46d6ef..600522b 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -48,20 +48,17 @@ jobs: shell: pwsh env: REF_NAME: ${{ github.ref_name }} + REF_TYPE: ${{ github.ref_type }} + DOTNET_NOLOGO: "true" run: | - $refName = $env:REF_NAME - if ($refName -match '^v\d+\.\d+\.\d+(-[0-9A-Za-z.-]+)?$') { - $version = $refName.TrimStart('v') - $tag = $refName + $version = (& dotnet msbuild ThreadPilot.csproj -nologo -getProperty:Version | Out-String).Trim() + if ($LASTEXITCODE -ne 0 -or $version -notmatch '^\d+\.\d+\.\d+(?:-[0-9A-Za-z.-]+)?$') { + throw "Unable to resolve a valid release version from ThreadPilot.csproj." } - else { - [xml]$project = Get-Content "ThreadPilot.csproj" - $version = $project.Project.PropertyGroup.Version - if ([string]::IsNullOrWhiteSpace($version)) { - throw "Unable to resolve version from tag or ThreadPilot.csproj" - } - $tag = "v$version" + $tag = "v$version" + if ($env:REF_TYPE -eq 'tag' -and $env:REF_NAME -cne $tag) { + throw "Tag '$env:REF_NAME' does not match project version '$version'." } $prerelease = $version.Contains('-').ToString().ToLowerInvariant() diff --git a/build/submit-winget-pr.ps1 b/build/submit-winget-pr.ps1 index 2881bf4..d26d7dd 100644 --- a/build/submit-winget-pr.ps1 +++ b/build/submit-winget-pr.ps1 @@ -36,7 +36,7 @@ if (-not (Test-Path -LiteralPath $ManifestSourcePath)) { throw "Manifest source path not found: $ManifestSourcePath" } -$manifestFiles = Get-ChildItem -LiteralPath $ManifestSourcePath -Recurse -File -Filter '*.yaml' +$manifestFiles = @(Get-ChildItem -LiteralPath $ManifestSourcePath -Recurse -File -Filter '*.yaml') if (-not $manifestFiles -or $manifestFiles.Count -eq 0) { throw "No winget manifest files found under $ManifestSourcePath" } @@ -64,6 +64,9 @@ try { $branch = "threadpilot-$Version" & git checkout -B $branch + if ($LASTEXITCODE -ne 0) { + throw 'Failed to prepare the WinGet submission branch.' + } $packageParts = $PackageIdentifier.Split('.') if ($packageParts.Count -lt 2) { @@ -91,18 +94,33 @@ try { } & git add $targetDir - & git status --short + if ($LASTEXITCODE -ne 0) { + throw 'Failed to stage the WinGet manifests.' + } $hasChanges = (& git diff --cached --name-only | Out-String).Trim() + if ($LASTEXITCODE -ne 0) { + throw 'Failed to inspect staged WinGet manifests.' + } if ([string]::IsNullOrWhiteSpace($hasChanges)) { Write-Host "No manifest changes detected for $Version. Nothing to submit." exit 0 } & git commit -m "Add $PackageIdentifier version $Version" - & git push -u origin $branch --force + if ($LASTEXITCODE -ne 0) { + throw 'Failed to commit the WinGet manifests.' + } + + & git push -u origin $branch --force-with-lease + if ($LASTEXITCODE -ne 0) { + throw 'Failed to push the WinGet submission branch.' + } $existingPr = (& gh pr list --repo microsoft/winget-pkgs --state open --head $branch --author $ForkOwner --json number | Out-String).Trim() + if ($LASTEXITCODE -ne 0) { + throw 'Failed to check for an existing WinGet pull request.' + } if (-not [string]::IsNullOrWhiteSpace($existingPr) -and $existingPr -ne '[]') { Write-Host "Winget PR already exists for branch $branch." exit 0