Skip to content

Commit d53326c

Browse files
feat: always emit a version regardless of publish decision (#4)
Non-publishable builds now receive a development prerelease version so downstream jobs always have a version to stamp into the artifact. CreateRelease remains false to gate publishing. Fixes PSModule/Process-PSModule#348.
1 parent 65b7cb0 commit d53326c

7 files changed

Lines changed: 791 additions & 755 deletions

File tree

.github/workflows/Action-Test.yml

Lines changed: 22 additions & 617 deletions
Large diffs are not rendered by default.

action.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ runs:
6666
shell: pwsh
6767
working-directory: ${{ inputs.WorkingDirectory }}
6868
env:
69+
GH_TOKEN: ${{ github.token }}
6970
PSMODULE_RESOLVE_PSMODULEVERSION_INPUT_Settings: ${{ inputs.Settings }}
7071
PSMODULE_RESOLVE_PSMODULEVERSION_INPUT_Name: ${{ inputs.Name }}
7172
PSMODULE_RESOLVE_PSMODULEVERSION_INPUT_EventJson: ${{ inputs.EventJson }}
Lines changed: 120 additions & 119 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
function Split-CommaSeparatedList {
22
<#
3-
.SYNOPSIS
4-
Splits a comma-separated string into a trimmed, non-empty array.
3+
.SYNOPSIS
4+
Splits a comma-separated string into a trimmed, non-empty array.
55
6-
.EXAMPLE
7-
Split-CommaSeparatedList -Value 'Major, Minor, Patch'
6+
.EXAMPLE
7+
Split-CommaSeparatedList -Value 'Major, Minor, Patch'
88
9-
Returns @('Major', 'Minor', 'Patch').
10-
#>
9+
Returns @('Major', 'Minor', 'Patch').
10+
#>
1111
[CmdletBinding()]
1212
[OutputType([string[]])]
1313
param(
@@ -21,19 +21,19 @@
2121

2222
function Read-ActionInput {
2323
<#
24-
.SYNOPSIS
25-
Reads and validates action inputs from environment variables.
24+
.SYNOPSIS
25+
Reads and validates action inputs from environment variables.
2626
27-
.DESCRIPTION
28-
Reads the module name and settings JSON from GitHub Actions environment variables.
29-
Falls back to the repository name when the module name input is not provided.
27+
.DESCRIPTION
28+
Reads the module name and settings JSON from GitHub Actions environment variables.
29+
Falls back to the repository name when the module name input is not provided.
3030
31-
.OUTPUTS
32-
PSCustomObject with Name and SettingsJson properties.
31+
.OUTPUTS
32+
PSCustomObject with Name and SettingsJson properties.
3333
34-
.EXAMPLE
35-
$actionInput = Read-ActionInput
36-
#>
34+
.EXAMPLE
35+
$actionInput = Read-ActionInput
36+
#>
3737
[CmdletBinding()]
3838
[OutputType([PSCustomObject])]
3939
param()
@@ -62,19 +62,19 @@ function Read-ActionInput {
6262

6363
function Get-PublishConfiguration {
6464
<#
65-
.SYNOPSIS
66-
Parses the settings JSON into a publish configuration object.
65+
.SYNOPSIS
66+
Parses the settings JSON into a publish configuration object.
6767
68-
.DESCRIPTION
69-
Extracts publish module settings including auto-patching flags, version prefix,
70-
release type, and label classification arrays.
68+
.DESCRIPTION
69+
Extracts publish module settings including auto-patching flags, version prefix,
70+
release type, and label classification arrays.
7171
72-
.OUTPUTS
73-
PSCustomObject with publish configuration properties.
72+
.OUTPUTS
73+
PSCustomObject with publish configuration properties.
7474
75-
.EXAMPLE
76-
$config = Get-PublishConfiguration -SettingsJson $actionInput.SettingsJson
77-
#>
75+
.EXAMPLE
76+
$config = Get-PublishConfiguration -SettingsJson $actionInput.SettingsJson
77+
#>
7878
[Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSReviewUnusedParameter', '',
7979
Justification = 'Parameter is used inside LogGroup script block.')]
8080
[CmdletBinding()]
@@ -122,19 +122,19 @@ function Get-PublishConfiguration {
122122

123123
function Get-GitHubPullRequest {
124124
<#
125-
.SYNOPSIS
126-
Reads and validates the GitHub pull request from the event payload.
125+
.SYNOPSIS
126+
Reads and validates the GitHub pull request from the event payload.
127127
128-
.DESCRIPTION
129-
Loads the GitHub event from the input override or from the event path file,
130-
then validates and extracts pull request data.
128+
.DESCRIPTION
129+
Loads the GitHub event from the input override or from the event path file,
130+
then validates and extracts pull request data.
131131
132-
.OUTPUTS
133-
PSCustomObject with HeadRef and Labels properties.
132+
.OUTPUTS
133+
PSCustomObject with HeadRef and Labels properties.
134134
135-
.EXAMPLE
136-
$pullRequest = Get-GitHubPullRequest
137-
#>
135+
.EXAMPLE
136+
$pullRequest = Get-GitHubPullRequest
137+
#>
138138
[CmdletBinding()]
139139
[OutputType([PSCustomObject])]
140140
param()
@@ -171,20 +171,20 @@ function Get-GitHubPullRequest {
171171

172172
function Resolve-ReleaseDecision {
173173
<#
174-
.SYNOPSIS
175-
Determines whether to publish a release and what kind of version bump to apply.
174+
.SYNOPSIS
175+
Determines whether to publish a release and what kind of version bump to apply.
176176
177-
.DESCRIPTION
178-
Evaluates the PR labels against the configured label categories and release type
179-
to produce a complete release decision.
177+
.DESCRIPTION
178+
Evaluates the PR labels against the configured label categories and release type
179+
to produce a complete release decision.
180180
181-
.OUTPUTS
182-
PSCustomObject with ShouldPublish, CreateRelease, CreatePrerelease, MajorRelease,
183-
MinorRelease, PatchRelease, HasVersionBump, and PrereleaseName properties.
181+
.OUTPUTS
182+
PSCustomObject with ShouldPublish, CreateRelease, CreatePrerelease, MajorRelease,
183+
MinorRelease, PatchRelease, HasVersionBump, and PrereleaseName properties.
184184
185-
.EXAMPLE
186-
$decision = Resolve-ReleaseDecision -Configuration $config -PullRequest $pullRequest
187-
#>
185+
.EXAMPLE
186+
$decision = Resolve-ReleaseDecision -Configuration $config -PullRequest $pullRequest
187+
#>
188188
[Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSReviewUnusedParameter', '',
189189
Justification = 'Parameter is used inside LogGroup script block.')]
190190
[CmdletBinding()]
@@ -222,10 +222,14 @@ function Resolve-ReleaseDecision {
222222
$shouldPublish = $false
223223
}
224224

225+
# Defaults: always produce a prerelease patch version.
225226
$majorRelease = $false
226227
$minorRelease = $false
227-
$patchRelease = $false
228-
$hasVersionBump = $false
228+
$patchRelease = $true
229+
$hasVersionBump = $true
230+
if (-not $shouldPublish) {
231+
$createPrerelease = $true
232+
}
229233

230234
if ($shouldPublish) {
231235
$majorRelease = ($labels | Where-Object { $Configuration.MajorLabels -contains $_ }).Count -gt 0
@@ -238,6 +242,9 @@ function Resolve-ReleaseDecision {
238242
if (-not $hasVersionBump) {
239243
Write-Host 'No version bump label found and AutoPatching is disabled. No release will be created.'
240244
$shouldPublish = $false
245+
$createPrerelease = $true
246+
$patchRelease = $true
247+
$hasVersionBump = $true
241248
}
242249
}
243250

@@ -268,15 +275,15 @@ function Resolve-ReleaseDecision {
268275

269276
function Get-GitHubRelease {
270277
<#
271-
.SYNOPSIS
272-
Retrieves all releases from the current GitHub repository.
278+
.SYNOPSIS
279+
Retrieves all releases from the current GitHub repository.
273280
274-
.OUTPUTS
275-
Array of release objects.
281+
.OUTPUTS
282+
Array of release objects.
276283
277-
.EXAMPLE
278-
$releases = Get-GitHubReleases
279-
#>
284+
.EXAMPLE
285+
$releases = Get-GitHubRelease
286+
#>
280287
[CmdletBinding()]
281288
[OutputType([array])]
282289
param()
@@ -300,15 +307,15 @@ function Get-GitHubRelease {
300307

301308
function Get-LatestGitHubVersion {
302309
<#
303-
.SYNOPSIS
304-
Extracts the latest stable version from a GitHub releases list.
310+
.SYNOPSIS
311+
Extracts the latest stable version from a GitHub releases list.
305312
306-
.OUTPUTS
307-
PSSemVer representing the latest GitHub release version.
313+
.OUTPUTS
314+
PSSemVer representing the latest GitHub release version.
308315
309-
.EXAMPLE
310-
$ghVersion = Get-LatestGitHubVersion -Releases $releases
311-
#>
316+
.EXAMPLE
317+
$ghVersion = Get-LatestGitHubVersion -Releases $releases
318+
#>
312319
[Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSReviewUnusedParameter', '',
313320
Justification = 'Parameter is used inside LogGroup script block.')]
314321
[CmdletBinding()]
@@ -337,19 +344,19 @@ function Get-LatestGitHubVersion {
337344

338345
function Get-LatestPSGalleryVersion {
339346
<#
340-
.SYNOPSIS
341-
Finds the latest stable version of a module in the PowerShell Gallery.
347+
.SYNOPSIS
348+
Finds the latest stable version of a module in the PowerShell Gallery.
342349
343-
.DESCRIPTION
344-
Queries the PowerShell Gallery for the latest published version of the module.
345-
Retries up to five times with a ten-second delay between attempts.
350+
.DESCRIPTION
351+
Queries the PowerShell Gallery for the latest published version of the module.
352+
Retries up to five times with a ten-second delay between attempts.
346353
347-
.OUTPUTS
348-
PSSemVer representing the latest PSGallery version.
354+
.OUTPUTS
355+
PSSemVer representing the latest PSGallery version.
349356
350-
.EXAMPLE
351-
$psGalleryVersion = Get-LatestPSGalleryVersion -ModuleName 'MyModule'
352-
#>
357+
.EXAMPLE
358+
$psGalleryVersion = Get-LatestPSGalleryVersion -ModuleName 'MyModule'
359+
#>
353360
[Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSReviewUnusedParameter', '',
354361
Justification = 'Parameter is used inside LogGroup script block.')]
355362
[CmdletBinding()]
@@ -395,15 +402,15 @@ function Get-LatestPSGalleryVersion {
395402

396403
function Get-LatestPublishedVersion {
397404
<#
398-
.SYNOPSIS
399-
Returns the highest version between GitHub and the PowerShell Gallery.
405+
.SYNOPSIS
406+
Returns the highest version between GitHub and the PowerShell Gallery.
400407
401-
.OUTPUTS
402-
PSSemVer representing the highest known published version.
408+
.OUTPUTS
409+
PSSemVer representing the highest known published version.
403410
404-
.EXAMPLE
405-
$latestVersion = Get-LatestPublishedVersion -GitHubVersion $ghVersion -PSGalleryVersion $psGalleryVersion
406-
#>
411+
.EXAMPLE
412+
$latestVersion = Get-LatestPublishedVersion -GitHubVersion $ghVersion -PSGalleryVersion $psGalleryVersion
413+
#>
407414
[Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSReviewUnusedParameter', '',
408415
Justification = 'Parameter is used inside LogGroup script block.')]
409416
[CmdletBinding()]
@@ -429,20 +436,20 @@ function Get-LatestPublishedVersion {
429436

430437
function Get-NextPrereleaseNumber {
431438
<#
432-
.SYNOPSIS
433-
Calculates the next incremental prerelease number across GitHub and PSGallery.
439+
.SYNOPSIS
440+
Calculates the next incremental prerelease number across GitHub and PSGallery.
434441
435-
.DESCRIPTION
436-
Queries both GitHub releases and the PowerShell Gallery for existing prereleases
437-
matching the base version and prerelease name, then returns the next number
438-
zero-padded to three digits.
442+
.DESCRIPTION
443+
Queries both GitHub releases and the PowerShell Gallery for existing prereleases
444+
matching the base version and prerelease name, then returns the next number
445+
zero-padded to three digits.
439446
440-
.OUTPUTS
441-
String. A zero-padded three-digit number (e.g. '001').
447+
.OUTPUTS
448+
String. A zero-padded three-digit number (e.g. '001').
442449
443-
.EXAMPLE
444-
$number = Get-NextPrereleaseNumber -ModuleName 'MyModule' -BaseVersion '1.2.3' -PrereleaseName 'mybranch' -Releases $releases
445-
#>
450+
.EXAMPLE
451+
$number = Get-NextPrereleaseNumber -ModuleName 'MyModule' -BaseVersion '1.2.3' -PrereleaseName 'mybranch' -Releases $releases
452+
#>
446453
[CmdletBinding()]
447454
[OutputType([string])]
448455
param(
@@ -502,20 +509,20 @@ function Get-NextPrereleaseNumber {
502509

503510
function Get-NextModuleVersion {
504511
<#
505-
.SYNOPSIS
506-
Calculates the next module version based on the release decision.
512+
.SYNOPSIS
513+
Calculates the next module version based on the release decision.
507514
508-
.DESCRIPTION
509-
Increments the current version according to the version bump type (major, minor, or patch),
510-
then optionally appends a prerelease suffix with support for date-based and incremental numbering.
515+
.DESCRIPTION
516+
Increments the current version according to the version bump type (major, minor, or patch),
517+
then optionally appends a prerelease suffix with support for date-based and incremental numbering.
511518
512-
.OUTPUTS
513-
PSSemVer representing the resolved next version.
519+
.OUTPUTS
520+
PSSemVer representing the resolved next version.
514521
515-
.EXAMPLE
516-
$newVersion = Get-NextModuleVersion -LatestVersion $latestVersion -Decision $decision `
517-
-Configuration $config -ModuleName 'MyModule' -Releases $releases
518-
#>
522+
.EXAMPLE
523+
$newVersion = Get-NextModuleVersion -LatestVersion $latestVersion -Decision $decision `
524+
-Configuration $config -ModuleName 'MyModule' -Releases $releases
525+
#>
519526
[Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSReviewUnusedParameter', '',
520527
Justification = 'Parameter is used inside LogGroup script block.')]
521528
[CmdletBinding()]
@@ -569,7 +576,7 @@ function Get-NextModuleVersion {
569576
$newVersion.Prerelease += "$(Get-Date -Format $Configuration.DatePrereleaseFormat)"
570577
}
571578

572-
if ($Configuration.IncrementalPrerelease) {
579+
if ($Configuration.IncrementalPrerelease -or -not $Decision.ShouldPublish) {
573580
$baseVersionString = "$($newVersion.Major).$($newVersion.Minor).$($newVersion.Patch)"
574581
$params = @{
575582
ModuleName = $ModuleName
@@ -588,12 +595,12 @@ function Get-NextModuleVersion {
588595

589596
function Write-ActionOutput {
590597
<#
591-
.SYNOPSIS
592-
Emits the resolved version and release type as GitHub Actions step outputs.
598+
.SYNOPSIS
599+
Emits the resolved version and release type as GitHub Actions step outputs.
593600
594-
.EXAMPLE
595-
Write-ActionOutput -Decision $decision -NewVersion $newVersion
596-
#>
601+
.EXAMPLE
602+
Write-ActionOutput -Decision $decision -NewVersion $newVersion
603+
#>
597604
[Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSReviewUnusedParameter', '',
598605
Justification = 'Parameter is used inside LogGroup script block.')]
599606
[CmdletBinding()]
@@ -602,21 +609,15 @@ function Write-ActionOutput {
602609
[Parameter(Mandatory)]
603610
[PSCustomObject] $Decision,
604611

605-
# The resolved next version, or $null when no release will be created.
606-
[Parameter()]
612+
# The resolved next version.
613+
[Parameter(Mandatory)]
607614
[object] $NewVersion
608615
)
609616

610617
LogGroup 'Emit outputs' {
611-
$versionString = ''
612-
$prereleaseString = ''
613-
$fullVersionString = ''
614-
615-
if ($NewVersion) {
616-
$versionString = "$($NewVersion.Major).$($NewVersion.Minor).$($NewVersion.Patch)"
617-
$prereleaseString = [string]$NewVersion.Prerelease
618-
$fullVersionString = $NewVersion.ToString()
619-
}
618+
$versionString = "$($NewVersion.Major).$($NewVersion.Minor).$($NewVersion.Patch)"
619+
$prereleaseString = [string]$NewVersion.Prerelease
620+
$fullVersionString = $NewVersion.ToString()
620621

621622
$resolvedReleaseType = if ($Decision.ShouldPublish) {
622623
if ($Decision.CreateRelease) { 'Release' } else { 'Prerelease' }

0 commit comments

Comments
 (0)