|
2 | 2 | 'PSUseDeclaredVarsMoreThanAssignments', '', |
3 | 3 | Justification = 'Variables are assigned in BeforeAll and used inside It blocks.' |
4 | 4 | )] |
| 5 | +[Diagnostics.CodeAnalysis.SuppressMessageAttribute( |
| 6 | + 'PSAvoidUsingCmdletAliases', 'Context', |
| 7 | + Justification = 'Context is a Pester test block, not an implicit call to Get-Context.' |
| 8 | +)] |
5 | 9 | [CmdletBinding()] |
6 | 10 | param() |
7 | 11 |
|
8 | 12 | BeforeAll { |
9 | 13 | Import-Module -Name 'PSModule' -Force |
| 14 | + Import-Module -Name (Join-Path -Path $PSScriptRoot -ChildPath '../../Get-PSModuleSettings/src/Get-PSModuleSettings.Helpers.psm1') -Force |
10 | 15 | Import-Module -Name (Join-Path -Path $PSScriptRoot -ChildPath '../src/Resolve-PSModuleVersion.Helpers.psm1') -Force |
11 | 16 |
|
12 | 17 | function Get-TestConfiguration { |
@@ -574,45 +579,75 @@ Describe 'Resolve-PSModuleVersion' { |
574 | 579 | $result.PatchRelease | Should -BeTrue |
575 | 580 | } |
576 | 581 |
|
577 | | - It 'resolves the labeled minor version once a recovery dispatch supplies pull request context' { |
578 | | - # End-to-end guard for issue #530, using the reproduction numbers from |
579 | | - # MariusStorhaug/MariusTestModule: latest release v0.4.13 and merged pull request #64 |
580 | | - # labeled 'minor', so the correct release is 0.5.0. This asserts the version consequence |
581 | | - # of the two possible contexts a default-branch dispatch can produce. Get-PSModuleSettings |
582 | | - # decides which one it is; that decision is guarded by |
583 | | - # Test-ShouldResolveAssociatedPullRequest in the settings action tests. |
584 | | - $configuration = Get-TestConfiguration |
585 | | - $versionFor = { |
586 | | - param($SettingsJson) |
587 | | - $pullRequest = Get-GitHubPullRequest -SettingsJson $SettingsJson |
588 | | - $decision = Resolve-ReleaseDecision -Configuration $configuration -PullRequest $pullRequest |
589 | | - $resolved = Get-ResolvedModuleVersion -GitHubVersion ([PSSemVer]'0.4.13') ` |
590 | | - -PSGalleryVersion ([PSSemVer]'0.4.13') ` |
591 | | - -Decision $decision ` |
592 | | - -Configuration $configuration ` |
593 | | - -ModuleName 'MariusTestModule' |
594 | | - $resolved.ToString() |
595 | | - } |
596 | | - |
597 | | - $dispatchContext = @{ |
598 | | - IsPushToDefaultBranch = $false |
599 | | - IsManualDispatchToDefaultBranch = $true |
| 582 | + It 'resolves <ExpectedVersion> for a <EventName> with <Label> release intent' -ForEach @( |
| 583 | + @{ EventName = 'workflow_dispatch'; Label = 'major'; ExpectedVersion = 'v1.0.0' } |
| 584 | + @{ EventName = 'workflow_dispatch'; Label = 'minor'; ExpectedVersion = 'v0.5.0' } |
| 585 | + @{ EventName = 'workflow_dispatch'; Label = 'patch'; ExpectedVersion = 'v0.4.14' } |
| 586 | + @{ EventName = 'workflow_dispatch'; Label = ''; ExpectedVersion = 'v0.4.14' } |
| 587 | + @{ EventName = 'push'; Label = 'major'; ExpectedVersion = 'v1.0.0' } |
| 588 | + @{ EventName = 'push'; Label = 'minor'; ExpectedVersion = 'v0.5.0' } |
| 589 | + @{ EventName = 'push'; Label = 'patch'; ExpectedVersion = 'v0.4.14' } |
| 590 | + @{ EventName = 'push'; Label = ''; ExpectedVersion = 'v0.4.14' } |
| 591 | + ) { |
| 592 | + $associatedPullRequests = if ($Label) { |
| 593 | + @([pscustomobject]@{ |
| 594 | + Number = 64 |
| 595 | + Base = [pscustomobject]@{ Ref = 'main' } |
| 596 | + Head = [pscustomobject]@{ Ref = 'feature/recovered-release' } |
| 597 | + merged_at = '2026-09-02T09:02:24Z' |
| 598 | + merge_commit_sha = 'released-sha' |
| 599 | + Labels = @([pscustomobject]@{ Name = $Label }) |
| 600 | + }) |
| 601 | + } else { |
| 602 | + @() |
| 603 | + } |
| 604 | + $parameters = @{ |
| 605 | + EventName = $EventName |
| 606 | + CommitSha = 'released-sha' |
600 | 607 | DefaultBranch = 'main' |
| 608 | + IsPushToDefaultBranch = $EventName -eq 'push' |
| 609 | + IsManualDispatchToDefaultBranch = $EventName -eq 'workflow_dispatch' |
| 610 | + GetAssociatedPullRequest = { $associatedPullRequests }.GetNewClosure() |
| 611 | + } |
| 612 | + $resolution = Resolve-ReleasePullRequest @parameters |
| 613 | + $resolvedPullRequest = $resolution.PullRequest |
| 614 | + $normalizedPullRequest = if ($resolvedPullRequest) { |
| 615 | + @{ |
| 616 | + Number = $resolvedPullRequest.Number |
| 617 | + HeadRef = $resolvedPullRequest.Head.Ref |
| 618 | + Labels = @($resolvedPullRequest.Labels.Name) |
| 619 | + } |
| 620 | + } else { |
| 621 | + $null |
| 622 | + } |
| 623 | + $settingsJson = @{ |
| 624 | + Context = @{ |
| 625 | + IsPushToDefaultBranch = $parameters.IsPushToDefaultBranch |
| 626 | + IsManualDispatchToDefaultBranch = $parameters.IsManualDispatchToDefaultBranch |
| 627 | + DefaultBranch = 'main' |
| 628 | + PullRequest = $normalizedPullRequest |
| 629 | + } |
| 630 | + } | ConvertTo-Json -Depth 5 |
| 631 | + $configuration = Get-TestConfiguration |
| 632 | + $pullRequest = Get-GitHubPullRequest -SettingsJson $settingsJson |
| 633 | + $decision = Resolve-ReleaseDecision -Configuration $configuration -PullRequest $pullRequest |
| 634 | + $versionParameters = @{ |
| 635 | + GitHubVersion = New-PSSemVer -Version '0.4.13' |
| 636 | + PSGalleryVersion = New-PSSemVer -Version '0.4.13' |
| 637 | + Decision = $decision |
| 638 | + Configuration = $configuration |
| 639 | + ModuleName = 'DispatchTestModule' |
| 640 | + } |
| 641 | + $resolvedVersion = Get-ResolvedModuleVersion @versionParameters |
| 642 | + |
| 643 | + $resolution.Resolved | Should -BeTrue |
| 644 | + $decision.ShouldPublish | Should -BeTrue |
| 645 | + $resolvedVersion.ToString() | Should -Be $ExpectedVersion |
| 646 | + if ($Label) { |
| 647 | + $pullRequest.Number | Should -Be 64 |
| 648 | + } else { |
| 649 | + $pullRequest.IsDirectRelease | Should -BeTrue |
601 | 650 | } |
602 | | - |
603 | | - $withoutPullRequest = & $versionFor (@{ |
604 | | - Context = $dispatchContext + @{ PullRequest = $null } |
605 | | - } | ConvertTo-Json -Depth 5) |
606 | | - $withPullRequest = & $versionFor (@{ |
607 | | - Context = $dispatchContext + @{ |
608 | | - PullRequest = @{ Number = 64; HeadRef = 'feature/recovered-release'; Labels = @('minor') } |
609 | | - } |
610 | | - } | ConvertTo-Json -Depth 5) |
611 | | - |
612 | | - # The silent downgrade the defect produced. |
613 | | - $withoutPullRequest | Should -Be 'v0.4.14' |
614 | | - # The version the merged pull request's label asks for. |
615 | | - $withPullRequest | Should -Be 'v0.5.0' |
616 | 651 | } |
617 | 652 |
|
618 | 653 | It 'does not publish an unlabeled prerelease when AutoPatching is disabled' { |
|
0 commit comments