From a1a469eff54c85f9390e844cdfdf00a061219379 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Sat, 11 Jul 2026 13:36:11 +0200 Subject: [PATCH 1/2] Resolve to the current version on non-PR events instead of throwing --- scripts/Resolve-PSModuleVersion.Helpers.psm1 | 4 +- scripts/main.ps1 | 19 +++++++- .../Resolve-PSModuleVersion.Helpers.Tests.ps1 | 43 +++++++++++++++++++ 3 files changed, 64 insertions(+), 2 deletions(-) diff --git a/scripts/Resolve-PSModuleVersion.Helpers.psm1 b/scripts/Resolve-PSModuleVersion.Helpers.psm1 index 25a3121..54a4491 100644 --- a/scripts/Resolve-PSModuleVersion.Helpers.psm1 +++ b/scripts/Resolve-PSModuleVersion.Helpers.psm1 @@ -149,7 +149,9 @@ function Get-GitHubPullRequest { $pr = $githubEvent.pull_request if (-not $pr) { - throw 'GitHub event does not contain pull_request data. This action must be run from a pull_request event.' + Write-Host 'GitHub event does not contain pull_request data (non-PR event, e.g. workflow_dispatch or schedule).' + Write-Host 'No pull request context is available; the caller keeps the current version without a bump.' + return $null } $labels = @() diff --git a/scripts/main.ps1 b/scripts/main.ps1 index 616a86e..2883767 100644 --- a/scripts/main.ps1 +++ b/scripts/main.ps1 @@ -9,7 +9,24 @@ Import-Module -Name "$PSScriptRoot/Resolve-PSModuleVersion.Helpers.psm1" -Force $actionInput = Read-ActionInput $config = Get-PublishConfiguration -SettingsJson $actionInput.SettingsJson $pullRequest = Get-GitHubPullRequest -$decision = Resolve-ReleaseDecision -Configuration $config -PullRequest $pullRequest + +$decision = if ($null -eq $pullRequest) { + # Non-PR event (for example workflow_dispatch or schedule): there are no pull request + # labels to determine a version bump, so keep the current published version and publish + # nothing. For a module that has never been released this floors at 0.0.0. + [PSCustomObject]@{ + ShouldPublish = $false + CreateRelease = $false + CreatePrerelease = $false + MajorRelease = $false + MinorRelease = $false + PatchRelease = $false + HasVersionBump = $false + PrereleaseName = '' + } +} else { + Resolve-ReleaseDecision -Configuration $config -PullRequest $pullRequest +} $releases = Get-GitHubRelease $ghVersion = Get-LatestGitHubVersion -Releases $releases diff --git a/tests/Resolve-PSModuleVersion.Helpers.Tests.ps1 b/tests/Resolve-PSModuleVersion.Helpers.Tests.ps1 index caebe7e..9130df0 100644 --- a/tests/Resolve-PSModuleVersion.Helpers.Tests.ps1 +++ b/tests/Resolve-PSModuleVersion.Helpers.Tests.ps1 @@ -188,3 +188,46 @@ Describe 'End-to-end: Resolve-ReleaseDecision + Get-NextModuleVersion' { } } } + +Describe 'Non-PR event keeps the current version' { + # main.ps1 builds this decision when the event has no pull_request (for example + # workflow_dispatch or schedule): no bump, no prerelease, no publish. Get-NextModuleVersion + # must then return the current published version unchanged, floored at 0.0.0 when nothing + # has ever been released. + BeforeAll { + Mock -CommandName Find-PSResource -ModuleName 'Resolve-PSModuleVersion.Helpers' -MockWith { @() } + $emptyReleases = @([PSCustomObject]@{ tagName = 'v0.0.0'; isLatest = $false; isPrerelease = $false }) + $config = [PSCustomObject]@{ + AutoPatching = $false + IncrementalPrerelease = $true + DatePrereleaseFormat = '' + VersionPrefix = 'v' + ReleaseType = 'None' + IgnoreLabels = @() + MajorLabels = @('major') + MinorLabels = @('minor') + PatchLabels = @('patch') + } + $noReleaseDecision = [PSCustomObject]@{ + ShouldPublish = $false + CreateRelease = $false + CreatePrerelease = $false + MajorRelease = $false + MinorRelease = $false + PatchRelease = $false + HasVersionBump = $false + PrereleaseName = '' + } + } + + It 'keeps the current version with no bump and no prerelease' -ForEach @( + @{ LatestVersion = '1.2.3' } + @{ LatestVersion = '0.0.0' } + ) { + $latestVer = New-PSSemVer -Version $LatestVersion + $result = Get-NextModuleVersion -LatestVersion $latestVer -Decision $noReleaseDecision ` + -Configuration $config -ModuleName 'TestModule' -Releases $emptyReleases + "$($result.Major).$($result.Minor).$($result.Patch)" | Should -Be $LatestVersion + $result.Prerelease | Should -BeNullOrEmpty + } +} From 2133e2d8c8dc1b0d87e711b48b1e0420bb64b74e Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Sat, 11 Jul 2026 14:30:53 +0200 Subject: [PATCH 2/2] Address Copilot review: document \ return on non-PR; add Get-GitHubPullRequest coverage --- scripts/Resolve-PSModuleVersion.Helpers.psm1 | 9 ++++--- .../Resolve-PSModuleVersion.Helpers.Tests.ps1 | 27 +++++++++++++++++++ 2 files changed, 33 insertions(+), 3 deletions(-) diff --git a/scripts/Resolve-PSModuleVersion.Helpers.psm1 b/scripts/Resolve-PSModuleVersion.Helpers.psm1 index 54a4491..d4f2f45 100644 --- a/scripts/Resolve-PSModuleVersion.Helpers.psm1 +++ b/scripts/Resolve-PSModuleVersion.Helpers.psm1 @@ -126,11 +126,14 @@ function Get-GitHubPullRequest { Reads and validates the GitHub pull request from the event payload. .DESCRIPTION - Loads the GitHub event from the input override or from the event path file, - then validates and extracts pull request data. + Loads the GitHub event from the input override or from the event path file. On a + pull_request event it returns the pull request head ref and labels. On any other + event (for example workflow_dispatch or schedule) there is no pull request, so it + returns $null and the caller resolves the current version without a version bump. .OUTPUTS - PSCustomObject with HeadRef and Labels properties. + PSCustomObject with HeadRef and Labels properties for a pull_request event, or + $null when the event has no pull request (non-PR events). .EXAMPLE $pullRequest = Get-GitHubPullRequest diff --git a/tests/Resolve-PSModuleVersion.Helpers.Tests.ps1 b/tests/Resolve-PSModuleVersion.Helpers.Tests.ps1 index 9130df0..e028ef4 100644 --- a/tests/Resolve-PSModuleVersion.Helpers.Tests.ps1 +++ b/tests/Resolve-PSModuleVersion.Helpers.Tests.ps1 @@ -231,3 +231,30 @@ Describe 'Non-PR event keeps the current version' { $result.Prerelease | Should -BeNullOrEmpty } } + +Describe 'Get-GitHubPullRequest' { + # Covers the non-PR branch: on an event without a pull_request (workflow_dispatch/schedule) + # the function must return $null so the caller keeps the current version, and it must still + # return the head ref + labels on a pull_request event. + AfterEach { + Remove-Item Env:PSMODULE_RESOLVE_PSMODULEVERSION_INPUT_EventJson -ErrorAction SilentlyContinue + } + + It 'returns $null when the event has no pull_request (non-PR event)' { + $env:PSMODULE_RESOLVE_PSMODULEVERSION_INPUT_EventJson = '{ "action": "workflow_dispatch" }' + Get-GitHubPullRequest | Should -BeNullOrEmpty + } + + It 'returns the head ref and labels for a pull_request event' { + $eventJson = @{ + pull_request = @{ + head = @{ ref = 'feat/example' } + labels = @(@{ name = 'patch' }, @{ name = 'prerelease' }) + } + } | ConvertTo-Json -Depth 5 + $env:PSMODULE_RESOLVE_PSMODULEVERSION_INPUT_EventJson = $eventJson + $result = Get-GitHubPullRequest + $result.HeadRef | Should -Be 'feat/example' + ($result.Labels -join ',') | Should -Be 'patch,prerelease' + } +}