diff --git a/.github/workflows/Legacy-Release-Test.yml b/.github/workflows/Legacy-Release-Test.yml index 0e57b13..cc3390f 100644 --- a/.github/workflows/Legacy-Release-Test.yml +++ b/.github/workflows/Legacy-Release-Test.yml @@ -8,14 +8,15 @@ on: permissions: {} concurrency: - group: Release-GHRepository-Test-Legacy + group: Release-GHRepository-Test queue: max jobs: Select: name: Verify the merged legacy case if: >- - ${{ github.repository == 'PSModule/Release-GHRepository-Test-Legacy' + ${{ github.repository == 'PSModule/Release-GHRepository-Test' + && github.repository_id == '1477027955' && github.event_name == 'pull_request' && github.event.action == 'closed' && github.event.pull_request.merged == true && github.event.pull_request.base.ref == 'main' && github.event.pull_request.head.repo.id == github.event.pull_request.base.repo.id @@ -52,6 +53,7 @@ jobs: CI: name: Test the exact squash commit needs: Select + if: ${{ needs.Select.outputs.caseId != '' }} runs-on: ubuntu-24.04 permissions: contents: read @@ -83,14 +85,15 @@ jobs: Add-Content -LiteralPath $env:GITHUB_OUTPUT -Value "sha=$sha" Gate: - name: Require current main and an empty inventory + name: Require current main and calculate the expected tag needs: [Select, CI] - if: ${{ needs.CI.outputs.testedSha == needs.Select.outputs.source }} + if: ${{ needs.Select.outputs.caseId != '' && needs.CI.outputs.testedSha == needs.Select.outputs.source }} runs-on: ubuntu-24.04 permissions: contents: read outputs: before: ${{ steps.gate.outputs.before }} + expectedTag: ${{ steps.gate.outputs.expectedTag }} steps: - name: Check out the exact squash commit uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0 @@ -98,7 +101,7 @@ jobs: ref: ${{ needs.Select.outputs.source }} persist-credentials: false - - name: Check main and the release and tag inventory + - name: Check main and calculate the expected tag id: gate shell: pwsh env: @@ -121,7 +124,7 @@ jobs: ref: ${{ needs.Select.outputs.source }} persist-credentials: true - - name: Check main and the inventory again + - name: Check main and the expected tag again shell: pwsh env: GH_TOKEN: ${{ github.token }} @@ -143,7 +146,7 @@ jobs: Verify: name: Verify the fixture result needs: [Select, CI, Gate, Publish] - if: ${{ !cancelled() && needs.Select.result == 'success' }} + if: ${{ !cancelled() && needs.Select.result == 'success' && needs.Select.outputs.caseId != '' }} runs-on: ubuntu-24.04 permissions: contents: read @@ -166,6 +169,7 @@ jobs: FIXTURE_HEAD: ${{ needs.Select.outputs.head }} FIXTURE_SOURCE: ${{ needs.Select.outputs.source }} FIXTURE_BEFORE: ${{ needs.Gate.outputs.before }} + FIXTURE_EXPECTED_TAG: ${{ needs.Gate.outputs.expectedTag }} FIXTURE_CI: ${{ needs.CI.result }} FIXTURE_TESTED_SHA: ${{ needs.CI.outputs.testedSha }} FIXTURE_PUBLISH: ${{ needs.Publish.result }} diff --git a/README.md b/README.md index 2d07d2a..8baa49c 100644 --- a/README.md +++ b/README.md @@ -37,7 +37,7 @@ Known v2.0.3 behavior that the candidate changes on purpose: - With `AutoPatching` off (the lane setting) and no deciding label, the "Skipping release creation" branch does not skip. It only leaves its `LogGroup` block, and the script attempts the unchanged version (`v0.0.0` on an empty inventory, or the latest tag again, which `gh` rejects). This is command evidence from the doubles. The released defaults (`AutoPatching` on) patch without a label. The candidate requires a decision. - `release:skip` is unknown to v2.0.3. With auto-patching on, it still releases. -- The source of a release is the tip of `main` when `gh release create` runs. The doubles cannot show it. Only a hosted write run in the isolated legacy repository can. +- The source of a release is the tip of `main` when `gh release create` runs. The doubles cannot show it. Only a hosted write run of the legacy lane can. The legacy lane below provides the hosted write evidence: one stable tag at the exact squash commit. The staged plan and the push CI gate exist only in the candidate. No legacy equivalent exists for those cases, so the baseline does not cover them. The doubles prove the logic only. They do not prove GitHub permissions, tag targets or the git push. @@ -59,17 +59,28 @@ Invoke-Pester -Path .\tests-baseline ## Legacy lane -[`Legacy-Release-Test.yml`](.github/workflows/Legacy-Release-Test.yml) tests the published v2.0.3 composite (`PSModule/Release-GHRepository@750abed0ecab02394554b610dc3aa191e75e3248`) on a real merged pull request. It runs only in the separate repository `PSModule/Release-GHRepository-Test-Legacy`. This repository does not publish through it. The legacy repository is not provisioned yet. +[`Legacy-Release-Test.yml`](.github/workflows/Legacy-Release-Test.yml) tests the published v2.0.3 composite (`PSModule/Release-GHRepository@750abed0ecab02394554b610dc3aa191e75e3248`) on a real merged pull request in this repository. It does not use a separate repository. -Requirements for the legacy repository: +Routing: a case file whose `candidate` is the v2.0.3 SHA belongs to the legacy lane. The candidate lane skips it. Any other case belongs to the candidate lane, and the legacy lane skips it. Each case runs in exactly one lane. -- Create it as a separate repository with exactly the same `main` as this repository at provisioning time. Pin its numeric ID after creation. -- Keep its release and tag inventory empty before the case. The workflow stops if a release or tag exists, or if `main` is not the squash commit. -- Use normal review. Do not merge any other PR while the case runs. `gh release create` tags the current tip of `main`, so a concurrent merge breaks the case. +- Both lanes share one concurrency group and one release and tag inventory. v2.0.3 bumps the patch number of the latest release, or starts at `v0.0.1`. The `Gate` job calculates that tag from the inventory, and `Verify` expects exactly that one new stable release and tag at the squash commit. +- Use normal review. Do not merge any other PR while a legacy case runs. `gh release create` tags the current tip of `main`, so a concurrent merge breaks the case. `Gate` and `Publish` stop if `main` is not the squash commit. - Shelly opens `release-fixture/-` with `release:patch` as the only label. v2.0.3 also reads `major`, `breaking`, `minor`, `feature` and `NoRelease`, so any other label fails the case. `Select` also fails if `.github/auto-release.yml` exists at the squash, because v2.0.3 lets that file override the workflow inputs. The PR adds only `tests/cases/-.json` with `{"scenario":"one-step","candidate":"750abed0ecab02394554b610dc3aa191e75e3248"}`. A verified single-parent squash must contain the same file. -Read-only jobs select the case, test the exact squash commit, and gate on current `main` and the empty inventory. Only `Publish` has `contents: write`. It uses only `GITHUB_TOKEN`, with `AutoPatching`, `AutoCleanup`, and the alias tags turned off. v2.0.3 runs `git push origin --tags`, which fails without credentials, so only `Publish` persists the job token at checkout. `Verify` expects one new stable `v..` release and tag at the squash commit. It reports a schema 2 `release-fixture-result` comment on the PR. +Read-only jobs select the case, test the exact squash commit, and gate on current `main` and the expected tag. Only `Publish` has `contents: write`. It uses only `GITHUB_TOKEN`, with `AutoPatching`, `AutoCleanup`, and the alias tags turned off. v2.0.3 runs `git push origin --tags`, which fails without credentials, so only `Publish` persists the job token at checkout. `Verify` reports a schema 2 `release-fixture-result` comment on the PR. +## Upgrade tracking + +To see what an upgrade needs, run the same scenario twice: once with the legacy SHA and once with the candidate SHA. Compare the two reports (`candidate`, `tag`, `run`). The differences that the candidate introduces: + +| Area | v2.0.3 (legacy) | Candidate | +| --- | --- | --- | +| Inputs | No `Mode`, `DefaultBump` or `ReleasePlan` | Has all three | +| Staged plan and push CI gate | None | Yes | +| No deciding label | Patches when `AutoPatching` is on | Requires a decision | +| `release:skip` | Unknown | Supported | +| `major`, `minor`, `NoRelease` and similar labels | Read without a prefix | Namespaced | +| Release source | Tip of `main` when `gh release create` runs | Exact squash commit | Run the case selection and inventory tests without GitHub credentials: ```powershell diff --git a/tests/Invoke-LegacyFixture.ps1 b/tests/Invoke-LegacyFixture.ps1 index 946b132..ec4a208 100644 --- a/tests/Invoke-LegacyFixture.ps1 +++ b/tests/Invoke-LegacyFixture.ps1 @@ -10,8 +10,9 @@ $ErrorActionPreference = 'Stop' Import-Module (Join-Path $PSScriptRoot 'ReleaseInventory.psm1') Import-Module (Join-Path $PSScriptRoot 'LegacyCase.psm1') -if ($env:GITHUB_REPOSITORY -cne 'PSModule/Release-GHRepository-Test-Legacy' -or $env:GITHUB_EVENT_NAME -cne 'pull_request') { - throw 'This suite runs only for pull requests in PSModule/Release-GHRepository-Test-Legacy.' +if ($env:GITHUB_REPOSITORY -cne 'PSModule/Release-GHRepository-Test' -or $env:GITHUB_REPOSITORY_ID -ne '1477027955' -or + $env:GITHUB_EVENT_NAME -cne 'pull_request') { + throw 'This suite runs only for pull requests in PSModule/Release-GHRepository-Test.' } $repository = $env:GITHUB_REPOSITORY @@ -74,11 +75,17 @@ if ($Stage -ceq 'Select') { $squash = [string] $pullRequest.merge_commit_sha if (-not $caseId -or $squash -cnotmatch '\A[0-9a-f]{40}\z') { throw 'The pull request does not identify a case and squash commit.' } + $squashCase = Get-CaseFile -Id $caseId -Ref $squash + if (-not (Test-LegacyCase -CaseJson $squashCase)) { + Write-Information "Case [$caseId] is not pinned to the legacy action. The candidate lane owns it." -InformationAction Continue + return + } + $commit = gh api "repos/$repository/commits/$squash" | ConvertFrom-Json -AsHashtable if ($LASTEXITCODE -ne 0) { throw "Could not read the squash commit [$squash]." } $case = Get-LegacyFixtureCase -EventPayload $eventPayload -Repository $repository ` -RepositoryId ([long] $env:GITHUB_REPOSITORY_ID) -Commit $commit -CommitFiles @($commit.files) ` - -HeadCase (Get-CaseFile -Id $caseId -Ref $pullRequest.head.sha) -SquashCase (Get-CaseFile -Id $caseId -Ref $squash) + -HeadCase (Get-CaseFile -Id $caseId -Ref $pullRequest.head.sha) -SquashCase $squashCase # v2.0.3 lets this file override the workflow inputs. The path uses a backslash by default. foreach ($configuration in '.github/auto-release.yml', '.github\auto-release.yml') { @@ -98,9 +105,17 @@ if ($Stage -ceq 'Select') { if ($Stage -ceq 'Gate') { $inventory = Get-ReleaseInventory - Assert-LegacyPublicationReady -MainSha (Get-MainSha) -Source $env:FIXTURE_SOURCE -Inventory $inventory + $latestTag = '' + if (@($inventory.releases).Count -gt 0) { + $latestTag = gh api "repos/$repository/releases/latest" --jq .tag_name + if ($LASTEXITCODE -ne 0) { throw 'Could not read the latest release.' } + } + $expectedTag = Get-LegacyExpectedTag -MainSha (Get-MainSha) -Source $env:FIXTURE_SOURCE -Inventory $inventory -LatestTag $latestTag if ($env:GITHUB_OUTPUT) { - Add-Content -LiteralPath $env:GITHUB_OUTPUT -Value "before=$(Get-ReleaseInventoryFingerprint -Inventory $inventory)" + Add-Content -LiteralPath $env:GITHUB_OUTPUT -Value @( + "before=$(Get-ReleaseInventoryFingerprint -Inventory $inventory)" + "expectedTag=$expectedTag" + ) } return } @@ -132,7 +147,8 @@ try { if ((Get-MainSha) -cne $report.source) { throw 'Main moved during the run.' } $after = Get-ReleaseInventory - $tag = Get-LegacyObservedTag -Source $report.source -After $after + $tag = $env:FIXTURE_EXPECTED_TAG + if ($tag -cnotmatch '\Av[0-9]+\.[0-9]+\.[0-9]+\z') { throw 'The gate did not supply a stable expected tag.' } Assert-ReleaseInventory -Before $env:FIXTURE_BEFORE -After $after -Source $report.source -ExpectedTag $tag $report.tag = $tag $report.oracle = 'success' diff --git a/tests/LegacyCase.Tests.ps1 b/tests/LegacyCase.Tests.ps1 index be53277..ad16535 100644 --- a/tests/LegacyCase.Tests.ps1 +++ b/tests/LegacyCase.Tests.ps1 @@ -1,7 +1,7 @@ BeforeAll { Import-Module (Join-Path $PSScriptRoot 'LegacyCase.psm1') -Force - $script:repository = 'PSModule/Release-GHRepository-Test-Legacy' + $script:repository = 'PSModule/Release-GHRepository-Test' $script:candidate = '750abed0ecab02394554b610dc3aa191e75e3248' $script:squash = 'c' * 40 $script:workflow = Get-Content -LiteralPath (Join-Path $PSScriptRoot '..\.github\workflows\Legacy-Release-Test.yml') -Raw @@ -12,15 +12,15 @@ Describe 'Legacy fixture case' { $caseFile = "{`"scenario`":`"one-step`",`"candidate`":`"$candidate`"}" $script:arguments = @{ Repository = $repository - RepositoryId = 77 + RepositoryId = 1477027955 EventPayload = @{ action = 'closed' pull_request = @{ number = 3 merged = $true user = @{ id = 314722336; login = 'psmodule-s-shelly[bot]' } - base = @{ ref = 'main'; repo = @{ id = 77; full_name = $repository } } - head = @{ ref = 'release-fixture/123-1'; sha = 'b' * 40; repo = @{ id = 77; full_name = $repository } } + base = @{ ref = 'main'; repo = @{ id = 1477027955; full_name = $repository } } + head = @{ ref = 'release-fixture/123-1'; sha = 'b' * 40; repo = @{ id = 1477027955; full_name = $repository } } labels = @(@{ name = 'release:patch' }) merge_commit_sha = $squash } @@ -46,8 +46,11 @@ Describe 'Legacy fixture case' { $case.Scenario | Should -BeExactly 'one-step' } - It 'rejects the candidate repository' { - $arguments.Repository = 'PSModule/Release-GHRepository-Test' + It 'rejects another repository or repository ID' { + $arguments.Repository = 'PSModule/Release-GHRepository-Test-Legacy' + { Get-LegacyFixtureCase @arguments } | Should -Throw '*Only*' + $arguments.Repository = $repository + $arguments.RepositoryId = 77 { Get-LegacyFixtureCase @arguments } | Should -Throw '*Only*' } @@ -94,39 +97,47 @@ Describe 'Legacy fixture case' { } } -Describe 'Legacy publication gate and verdict' { - It 'requires main at the squash and an empty inventory' { - $empty = @{ tags = @(); releases = @() } - { Assert-LegacyPublicationReady -MainSha $squash -Source $squash -Inventory $empty } | Should -Not -Throw - { Assert-LegacyPublicationReady -MainSha ('d' * 40) -Source $squash -Inventory $empty } | Should -Throw '*moved*' - { Assert-LegacyPublicationReady -MainSha $squash -Source $squash -Inventory @{ - tags = @(@{ name = 'v0.0.1'; sha = $squash }); releases = @() - } } | Should -Throw '*no release or tag*' +Describe 'Legacy case routing' { + It 'owns only cases pinned to the published legacy action' { + Test-LegacyCase -CaseJson "{`"scenario`":`"one-step`",`"candidate`":`"$candidate`"}" | Should -BeTrue + Test-LegacyCase -CaseJson ('{"scenario":"one-step","candidate":"' + ('f' * 40) + '"}') | Should -BeFalse + Test-LegacyCase -CaseJson 'not json' | Should -BeFalse + Test-LegacyCase -CaseJson '[]' | Should -BeFalse } +} - Context 'observed tag' { - BeforeEach { - $script:after = @{ - tags = @(@{ name = 'v0.0.1'; sha = $squash }) - releases = @(@{ tag = 'v0.0.1'; id = 9; draft = $false; prerelease = $false }) - } +Describe 'Legacy publication gate' { + BeforeEach { + $script:inventory = @{ + tags = @(@{ name = 'v1.2.9'; sha = 'a' * 40 }, @{ name = 'v1.2.10'; sha = 'b' * 40 }) + releases = @(@{ tag = 'v1.2.9'; id = 1; draft = $false; prerelease = $false }, @{ tag = 'v1.2.10'; id = 2; draft = $false; prerelease = $false }) } + } - It 'returns the one stable tag at the squash' { - Get-LegacyObservedTag -Source $squash -After $after | Should -BeExactly 'v0.0.1' - } + It 'starts at v0.0.1 in an empty inventory' { + Get-LegacyExpectedTag -MainSha $squash -Source $squash -Inventory @{ tags = @(); releases = @() } | + Should -BeExactly 'v0.0.1' + } - It 'rejects ' -ForEach @( - @{ Name = 'a tag at another commit'; Change = { $after.tags[0].sha = 'd' * 40 } } - @{ Name = 'an alias tag'; Change = { $after.tags += @{ name = 'v0'; sha = $squash } } } - @{ Name = 'a prerelease'; Change = { $after.releases[0].prerelease = $true } } - @{ Name = 'a draft'; Change = { $after.releases[0].draft = $true } } - @{ Name = 'no release'; Change = { $after.releases = @() } } - @{ Name = 'a release for another tag'; Change = { $after.releases[0].tag = 'v0.0.2' } } - ) { - & $Change - { Get-LegacyObservedTag -Source $squash -After $after } | Should -Throw + It 'bumps the patch number of the latest release numerically' { + Get-LegacyExpectedTag -MainSha $squash -Source $squash -Inventory $inventory -LatestTag 'v1.2.10' | + Should -BeExactly 'v1.2.11' + } + + It 'rejects ' -ForEach @( + @{ Name = 'a main that moved'; Change = { $script:main = 'd' * 40 } } + @{ Name = 'a latest tag that is not stable'; Change = { $script:latest = 'v1.2.3-beta1' } } + @{ Name = 'releases without a latest release'; Change = { $script:latest = '' } } + @{ Name = 'an existing tag for the next version'; Change = { $inventory.tags += @{ name = 'v1.2.11'; sha = 'c' * 40 } } } + @{ Name = 'an existing release for the next version'; Change = { + $inventory.releases += @{ tag = 'v1.2.11'; id = 3; draft = $true; prerelease = $false } + } } + ) { + $script:main = $squash + $script:latest = 'v1.2.10' + & $Change + { Get-LegacyExpectedTag -MainSha $main -Source $squash -Inventory $inventory -LatestTag $latest } | Should -Throw } } @@ -154,8 +165,14 @@ Describe 'Legacy workflow contract' { $workflow | Should -Not -Match 'pull_request_target|workflow_dispatch|\bpush:' } - It 'guards on the exact legacy repository, merged Shelly case, and main' { - foreach ($guard in "github.repository == 'PSModule/Release-GHRepository-Test-Legacy'", + It 'shares the candidate lane concurrency group and runs jobs only for legacy cases' { + $workflow | Should -Match '(?m)^ group: Release-GHRepository-Test$' + ([regex]::Matches($workflow, "needs\.Select\.outputs\.caseId != ''")).Count | Should -BeGreaterOrEqual 3 + } + + It 'guards on this repository, a merged Shelly case, and main' { + foreach ($guard in "github.repository == 'PSModule/Release-GHRepository-Test'", + "github.repository_id == '1477027955'", "github.event.action == 'closed'", 'github.event.pull_request.merged == true', 'head.repo.id == github.event.pull_request.base.repo.id', 'user.id == 314722336', "'psmodule-s-shelly[bot]'", "'release-fixture/'") { diff --git a/tests/LegacyCase.psm1 b/tests/LegacyCase.psm1 index c3e51bf..42befc3 100644 --- a/tests/LegacyCase.psm1 +++ b/tests/LegacyCase.psm1 @@ -1,4 +1,5 @@ -$script:LegacyRepository = 'PSModule/Release-GHRepository-Test-Legacy' +$script:Repository = 'PSModule/Release-GHRepository-Test' +$script:RepositoryId = 1477027955 $script:LegacyCandidate = '750abed0ecab02394554b610dc3aa191e75e3248' function Get-LegacyFixtureCase { @@ -36,8 +37,8 @@ function Get-LegacyFixtureCase { [string] $SquashCase ) - if ($Repository -cne $script:LegacyRepository) { - throw "Only [$script:LegacyRepository] can publish a legacy fixture." + if ($Repository -cne $script:Repository -or $RepositoryId -ne $script:RepositoryId) { + throw "Only [$script:Repository] can publish a legacy fixture." } $pullRequest = $EventPayload.pull_request if ($EventPayload.action -cne 'closed' -or $pullRequest -isnot [System.Collections.IDictionary] -or @@ -46,7 +47,7 @@ function Get-LegacyFixtureCase { } if ($RepositoryId -le 0 -or $pullRequest.base.repo.id -ne $RepositoryId -or $pullRequest.head.repo.id -ne $RepositoryId -or $pullRequest.base.repo.full_name -cne $Repository -or $pullRequest.head.repo.full_name -cne $Repository) { - throw 'The pull request head and base must be the same legacy repository, by name and numeric ID.' + throw 'The pull request head and base must be this repository, by name and numeric ID.' } if ($pullRequest.user.id -ne 314722336 -or $pullRequest.user.login -cne 'psmodule-s-shelly[bot]') { throw 'Only Shelly can open a legacy fixture case.' @@ -93,58 +94,63 @@ function Get-LegacyFixtureCase { } } -function Assert-LegacyPublicationReady { +function Test-LegacyCase { <# .SYNOPSIS - Verifies that main is still the squash commit and that no release or tag exists yet. + Tells whether a case file pins the published legacy action, so the legacy lane owns the case. #> [CmdletBinding()] + [OutputType([bool])] param( [Parameter(Mandatory)] - [string] $MainSha, - - [Parameter(Mandatory)] - [string] $Source, - - [Parameter(Mandatory)] - [System.Collections.IDictionary] $Inventory + [string] $CaseJson ) - if ($MainSha -cne $Source) { throw "Main moved from [$Source] to [$MainSha]. Do not publish." } - if (@($Inventory.tags).Count -ne 0 -or @($Inventory.releases).Count -ne 0) { - throw 'The legacy repository must have no release or tag before publication.' - } + try { $case = ConvertFrom-Json -InputObject $CaseJson -AsHashtable -NoEnumerate } catch { return $false } + $case -is [System.Collections.IDictionary] -and $case.candidate -is [string] -and $case.candidate -ceq $script:LegacyCandidate } -function Get-LegacyObservedTag { +function Get-LegacyExpectedTag { <# .SYNOPSIS - Returns the one stable tag that publication added, after checking the whole inventory. + Checks that main is still the squash commit and returns the tag that v2.0.3 must create. + + .DESCRIPTION + The repository also holds candidate releases, so the inventory is not empty. v2.0.3 bumps the patch + number of the latest release, or starts at v0.0.1 when there is none. The new tag must not exist yet. #> [CmdletBinding()] [OutputType([string])] param( + [Parameter(Mandatory)] + [string] $MainSha, + [Parameter(Mandatory)] [string] $Source, [Parameter(Mandatory)] - [System.Collections.IDictionary] $After + [System.Collections.IDictionary] $Inventory, + + [AllowEmptyString()] + [string] $LatestTag = '' ) - $tags = @($After.tags) - $releases = @($After.releases) - if ($tags.Count -ne 1 -or $releases.Count -ne 1) { - throw "Expected exactly one new tag and one new release, found [$($tags.Count)] and [$($releases.Count)]." - } - $name = [string] $tags[0].name - if ($name -cnotmatch '\Av[0-9]+\.[0-9]+\.[0-9]+\z' -or $tags[0].sha -cne $Source) { - throw "Expected one stable tag at the squash commit [$Source], found [$name]." + if ($MainSha -cne $Source) { throw "Main moved from [$Source] to [$MainSha]. Do not publish." } + + $expected = if ([string]::IsNullOrEmpty($LatestTag)) { + if (@($Inventory.releases).Count -ne 0) { throw 'The inventory has releases but GitHub reports no latest release.' } + 'v0.0.1' + } else { + $version = [regex]::Match($LatestTag, '\Av([0-9]+)\.([0-9]+)\.([0-9]+)\z') + if (-not $version.Success) { throw "The latest release tag [$LatestTag] is not a stable v.. tag." } + 'v{0}.{1}.{2}' -f $version.Groups[1].Value, $version.Groups[2].Value, ([bigint] $version.Groups[3].Value + 1) } - if ($releases[0].tag -cne $name -or $releases[0].id -le 0 -or - $releases[0].draft -ne $false -or $releases[0].prerelease -ne $false) { - throw "Expected one stable release for [$name]." + if (@($Inventory.tags | Where-Object name -CEQ $expected).Count -ne 0 -or + @($Inventory.releases | Where-Object tag -CEQ $expected).Count -ne 0) { + throw "The tag or release [$expected] already exists. Do not publish." } - $name + $expected } -Export-ModuleMember -Function Get-LegacyFixtureCase, Assert-LegacyPublicationReady, Get-LegacyObservedTag +Export-ModuleMember -Function Get-LegacyFixtureCase, Get-LegacyExpectedTag, Test-LegacyCase + diff --git a/tests/ReleaseCase.Tests.ps1 b/tests/ReleaseCase.Tests.ps1 index 58fb7b5..6a09f12 100644 --- a/tests/ReleaseCase.Tests.ps1 +++ b/tests/ReleaseCase.Tests.ps1 @@ -48,6 +48,16 @@ Describe 'Release fixture case selection' { $case.Scenario | Should -BeExactly 'missing-decision' } + It 'leaves a case pinned to the published legacy action to the legacy lane' { + @{ scenario = 'one-step'; candidate = '750abed0ecab02394554b610dc3aa191e75e3248' } | ConvertTo-Json | Set-Content -LiteralPath $descriptor + + Get-ReleaseFixtureCase -Path $caseRoot -EventName pull_request -Source $source -PullRequests @($pr) | + Should -BeNullOrEmpty + $pr.labels = @(@{ name = 'release:patch' }, @{ name = 'major' }) + Get-ReleaseFixtureCase -Path $caseRoot -EventName push -Source $source -PullRequests @($pr) | + Should -BeNullOrEmpty + } + It 'does not select a fixture case from a fork' { $pr.head.repo.id = 42 Get-ReleaseFixtureCase -Path $caseRoot -EventName pull_request -Source $source -PullRequests @($pr) | diff --git a/tests/ReleaseCase.psm1 b/tests/ReleaseCase.psm1 index b2e5c6e..9b68586 100644 --- a/tests/ReleaseCase.psm1 +++ b/tests/ReleaseCase.psm1 @@ -59,6 +59,8 @@ function Get-ReleaseFixtureCase { if ($case.candidate -isnot [string] -or $case.candidate -cnotmatch '\A[0-9a-f]{40}\z' -or $case.candidate -ceq ('0' * 40)) { throw "Case [$caseId] must pin a full lowercase candidate SHA." } + # The published legacy action has no Mode or plan inputs. Legacy-Release-Test.yml owns these cases. + if ($case.candidate -ceq '750abed0ecab02394554b610dc3aa191e75e3248') { return } if ($EventName -ceq 'push' -and $case.scenario -ceq 'missing-decision') { throw 'Close the missing-decision pull request without merging it.' }