Skip to content
This repository was archived by the owner on Jul 16, 2026. It is now read-only.

Commit 6a59a88

Browse files
🪲 [Fix]: Resolve to the current version on non-PR events (workflow_dispatch, schedule) (#10)
On non–pull-request events (for example `workflow_dispatch` and `schedule`), the action now resolves to the current published version instead of throwing. This is the root-cause fix for the `Plan` failures consumers see on scheduled and manual runs. - Part of the fix for PSModule/Process-PSModule#373 ## Fixed: no more throw on non–pull-request events Previously the action required a `pull_request` payload and threw `"...must be run from a pull_request event"` on any other event. Because Process-PSModule's `Plan` job runs this on every event, that failed the whole run on `schedule` / `workflow_dispatch` for every consumer. Now, when the event has no `pull_request`, `Get-GitHubPullRequest` returns `$null` and the caller resolves a no-op decision: no bump, no prerelease, nothing published — so `Get-NextModuleVersion` returns the **current published version** unchanged. ## New: non-PR runs report the current version There are no PR labels on `workflow_dispatch` / `schedule`, so there's nothing to bump from. The action keeps the latest published version (GitHub Release / PS Gallery), which is what a scheduled or manual re-test should build and test against. For a module that has never been released this floors at `0.0.0`. Pull-request and merge-to-default-branch behavior is unchanged — labels drive the bump, with patch as the default. ## Technical Details - `scripts/Resolve-PSModuleVersion.Helpers.psm1`: `Get-GitHubPullRequest` returns `$null` on a non-PR event instead of throwing. - `scripts/main.ps1`: builds a no-op release decision (all flags `false`, empty prerelease) when there is no pull request, otherwise calls `Resolve-ReleaseDecision` as before. `Get-NextModuleVersion` then returns `LatestVersion` unchanged. - `tests/`: added cases asserting the no-op decision keeps the current version (`1.2.3` and the `0.0.0` floor) with no bump and no prerelease. Full suite: 159 passed, PSScriptAnalyzer clean. - Follow-up: once released, Process-PSModule bumps its `Resolve-Version` pin to this version, which lets its `Plan.yml` gate + `999.0.0` fallback in PR #375 be dropped.
1 parent 8d1dac7 commit 6a59a88

3 files changed

Lines changed: 97 additions & 5 deletions

File tree

‎scripts/Resolve-PSModuleVersion.Helpers.psm1‎

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -126,11 +126,14 @@ function Get-GitHubPullRequest {
126126
Reads and validates the GitHub pull request from the event payload.
127127
128128
.DESCRIPTION
129-
Loads the GitHub event from the input override or from the event path file,
130-
then validates and extracts pull request data.
129+
Loads the GitHub event from the input override or from the event path file. On a
130+
pull_request event it returns the pull request head ref and labels. On any other
131+
event (for example workflow_dispatch or schedule) there is no pull request, so it
132+
returns $null and the caller resolves the current version without a version bump.
131133
132134
.OUTPUTS
133-
PSCustomObject with HeadRef and Labels properties.
135+
PSCustomObject with HeadRef and Labels properties for a pull_request event, or
136+
$null when the event has no pull request (non-PR events).
134137
135138
.EXAMPLE
136139
$pullRequest = Get-GitHubPullRequest
@@ -149,7 +152,9 @@ function Get-GitHubPullRequest {
149152

150153
$pr = $githubEvent.pull_request
151154
if (-not $pr) {
152-
throw 'GitHub event does not contain pull_request data. This action must be run from a pull_request event.'
155+
Write-Host 'GitHub event does not contain pull_request data (non-PR event, e.g. workflow_dispatch or schedule).'
156+
Write-Host 'No pull request context is available; the caller keeps the current version without a bump.'
157+
return $null
153158
}
154159

155160
$labels = @()

‎scripts/main.ps1‎

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,24 @@ Import-Module -Name "$PSScriptRoot/Resolve-PSModuleVersion.Helpers.psm1" -Force
99
$actionInput = Read-ActionInput
1010
$config = Get-PublishConfiguration -SettingsJson $actionInput.SettingsJson
1111
$pullRequest = Get-GitHubPullRequest
12-
$decision = Resolve-ReleaseDecision -Configuration $config -PullRequest $pullRequest
12+
13+
$decision = if ($null -eq $pullRequest) {
14+
# Non-PR event (for example workflow_dispatch or schedule): there are no pull request
15+
# labels to determine a version bump, so keep the current published version and publish
16+
# nothing. For a module that has never been released this floors at 0.0.0.
17+
[PSCustomObject]@{
18+
ShouldPublish = $false
19+
CreateRelease = $false
20+
CreatePrerelease = $false
21+
MajorRelease = $false
22+
MinorRelease = $false
23+
PatchRelease = $false
24+
HasVersionBump = $false
25+
PrereleaseName = ''
26+
}
27+
} else {
28+
Resolve-ReleaseDecision -Configuration $config -PullRequest $pullRequest
29+
}
1330

1431
$releases = Get-GitHubRelease
1532
$ghVersion = Get-LatestGitHubVersion -Releases $releases

‎tests/Resolve-PSModuleVersion.Helpers.Tests.ps1‎

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,3 +188,73 @@ Describe 'End-to-end: Resolve-ReleaseDecision + Get-NextModuleVersion' {
188188
}
189189
}
190190
}
191+
192+
Describe 'Non-PR event keeps the current version' {
193+
# main.ps1 builds this decision when the event has no pull_request (for example
194+
# workflow_dispatch or schedule): no bump, no prerelease, no publish. Get-NextModuleVersion
195+
# must then return the current published version unchanged, floored at 0.0.0 when nothing
196+
# has ever been released.
197+
BeforeAll {
198+
Mock -CommandName Find-PSResource -ModuleName 'Resolve-PSModuleVersion.Helpers' -MockWith { @() }
199+
$emptyReleases = @([PSCustomObject]@{ tagName = 'v0.0.0'; isLatest = $false; isPrerelease = $false })
200+
$config = [PSCustomObject]@{
201+
AutoPatching = $false
202+
IncrementalPrerelease = $true
203+
DatePrereleaseFormat = ''
204+
VersionPrefix = 'v'
205+
ReleaseType = 'None'
206+
IgnoreLabels = @()
207+
MajorLabels = @('major')
208+
MinorLabels = @('minor')
209+
PatchLabels = @('patch')
210+
}
211+
$noReleaseDecision = [PSCustomObject]@{
212+
ShouldPublish = $false
213+
CreateRelease = $false
214+
CreatePrerelease = $false
215+
MajorRelease = $false
216+
MinorRelease = $false
217+
PatchRelease = $false
218+
HasVersionBump = $false
219+
PrereleaseName = ''
220+
}
221+
}
222+
223+
It 'keeps the current version <LatestVersion> with no bump and no prerelease' -ForEach @(
224+
@{ LatestVersion = '1.2.3' }
225+
@{ LatestVersion = '0.0.0' }
226+
) {
227+
$latestVer = New-PSSemVer -Version $LatestVersion
228+
$result = Get-NextModuleVersion -LatestVersion $latestVer -Decision $noReleaseDecision `
229+
-Configuration $config -ModuleName 'TestModule' -Releases $emptyReleases
230+
"$($result.Major).$($result.Minor).$($result.Patch)" | Should -Be $LatestVersion
231+
$result.Prerelease | Should -BeNullOrEmpty
232+
}
233+
}
234+
235+
Describe 'Get-GitHubPullRequest' {
236+
# Covers the non-PR branch: on an event without a pull_request (workflow_dispatch/schedule)
237+
# the function must return $null so the caller keeps the current version, and it must still
238+
# return the head ref + labels on a pull_request event.
239+
AfterEach {
240+
Remove-Item Env:PSMODULE_RESOLVE_PSMODULEVERSION_INPUT_EventJson -ErrorAction SilentlyContinue
241+
}
242+
243+
It 'returns $null when the event has no pull_request (non-PR event)' {
244+
$env:PSMODULE_RESOLVE_PSMODULEVERSION_INPUT_EventJson = '{ "action": "workflow_dispatch" }'
245+
Get-GitHubPullRequest | Should -BeNullOrEmpty
246+
}
247+
248+
It 'returns the head ref and labels for a pull_request event' {
249+
$eventJson = @{
250+
pull_request = @{
251+
head = @{ ref = 'feat/example' }
252+
labels = @(@{ name = 'patch' }, @{ name = 'prerelease' })
253+
}
254+
} | ConvertTo-Json -Depth 5
255+
$env:PSMODULE_RESOLVE_PSMODULEVERSION_INPUT_EventJson = $eventJson
256+
$result = Get-GitHubPullRequest
257+
$result.HeadRef | Should -Be 'feat/example'
258+
($result.Labels -join ',') | Should -Be 'patch,prerelease'
259+
}
260+
}

0 commit comments

Comments
 (0)