|
| 1 | +#!/usr/bin/env pwsh |
| 2 | +[CmdletBinding()] |
| 3 | +param() |
| 4 | + |
| 5 | +$ErrorActionPreference = 'Stop' |
| 6 | + |
| 7 | +$resolver = Join-Path $PSScriptRoot 'Resolve-ReleaseBaseTag.ps1' |
| 8 | +$repo = Join-Path ([System.IO.Path]::GetTempPath()) ("release-base-test-" + [System.Guid]::NewGuid().ToString('N')) |
| 9 | + |
| 10 | +function Invoke-Git { |
| 11 | + param( |
| 12 | + [Parameter(Mandatory = $true)] |
| 13 | + [string[]] $Arguments |
| 14 | + ) |
| 15 | + |
| 16 | + & git @Arguments | Out-Null |
| 17 | + if ($LASTEXITCODE -ne 0) { |
| 18 | + throw "git $($Arguments -join ' ') failed with exit code $LASTEXITCODE" |
| 19 | + } |
| 20 | +} |
| 21 | + |
| 22 | +function Add-TestCommit { |
| 23 | + param( |
| 24 | + [Parameter(Mandatory = $true)] |
| 25 | + [string] $Content, |
| 26 | + [Parameter(Mandatory = $true)] |
| 27 | + [string] $Subject |
| 28 | + ) |
| 29 | + |
| 30 | + Set-Content -LiteralPath (Join-Path $repo 'sample.txt') -Value $Content -Encoding UTF8 |
| 31 | + Invoke-Git @('add', 'sample.txt') |
| 32 | + Invoke-Git @('commit', '-m', $Subject) |
| 33 | +} |
| 34 | + |
| 35 | +try { |
| 36 | + New-Item -ItemType Directory -Path $repo -Force | Out-Null |
| 37 | + Push-Location $repo |
| 38 | + |
| 39 | + Invoke-Git @('init', '-q') |
| 40 | + Invoke-Git @('config', 'user.email', 'release-test@example.com') |
| 41 | + Invoke-Git @('config', 'user.name', 'Release Test') |
| 42 | + |
| 43 | + Add-TestCommit -Content 'base' -Subject 'chore: base' |
| 44 | + Invoke-Git @('tag', 'v2026.5.1.0') |
| 45 | + |
| 46 | + Add-TestCommit -Content 'pre' -Subject 'feat: prerelease patch' |
| 47 | + Invoke-Git @('tag', 'v2026.5.2.0-beta') |
| 48 | + |
| 49 | + Add-TestCommit -Content 'stable' -Subject 'fix: stable patch' |
| 50 | + Invoke-Git @('tag', 'v2026.5.3.0') |
| 51 | + |
| 52 | + $stableBase = & $resolver -Tag 'v2026.5.3.0' |
| 53 | + if ($stableBase -ne 'v2026.5.1.0') { |
| 54 | + throw "Stable base was '$stableBase', expected 'v2026.5.1.0'." |
| 55 | + } |
| 56 | + |
| 57 | + $preBase = & $resolver -Tag 'v2026.5.2.0-beta' |
| 58 | + if ($preBase -ne 'v2026.5.1.0') { |
| 59 | + throw "Prerelease base was '$preBase', expected 'v2026.5.1.0'." |
| 60 | + } |
| 61 | + |
| 62 | + Write-Host 'Resolve-ReleaseBaseTag tests passed.' |
| 63 | +} |
| 64 | +finally { |
| 65 | + Pop-Location |
| 66 | + Remove-Item -LiteralPath $repo -Recurse -Force |
| 67 | +} |
0 commit comments