Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
d4480f9
feat: always emit version regardless of publish decision
MariusStorhaug May 27, 2026
ac4f7b1
fix: correct formatting of documentation comments in helper functions
MariusStorhaug May 27, 2026
0888d1f
refactor: remove Get-DevVersion, reuse Get-NextModuleVersion with syn…
MariusStorhaug May 27, 2026
eec8d46
refactor: move prerelease fallback into Resolve-ReleaseDecision
MariusStorhaug May 27, 2026
42c7d3f
feat: ensure a prerelease patch version is always produced in Resolve…
MariusStorhaug May 27, 2026
8110486
fix: add GH_TOKEN env var for gh CLI authentication
MariusStorhaug May 27, 2026
9d8dc69
fix: remove GH_TOKEN environment variable from Resolve-PSModuleVersio…
MariusStorhaug May 27, 2026
9be29fb
test: update None release type expectations to verify emitted version
MariusStorhaug May 27, 2026
c66bad1
fix: remove GH_TOKEN environment variable from Resolve-PSModuleVersio…
MariusStorhaug May 27, 2026
8f88432
fix: always append incremental prerelease counter for non-publishable…
MariusStorhaug May 27, 2026
26a6466
refactor: replace inline workflow tests with data-driven Pester tests…
MariusStorhaug May 27, 2026
fa528c1
refactor: extract test data into separate Helpers.Tests.Data.psd1 file
MariusStorhaug May 27, 2026
39fd8e0
chore: remove obsolete tests README.md file
MariusStorhaug May 27, 2026
05fc952
ci: set Output_Verbosity to Detailed for Pester test output
MariusStorhaug May 27, 2026
66452f0
ci: pin PSModule/Invoke-Pester to SHA
MariusStorhaug May 27, 2026
07fc879
style: fix PSScriptAnalyzer alignment and suppression warnings
MariusStorhaug May 27, 2026
49b4694
Address review feedback: fix help typo, rename test field, correct co…
MariusStorhaug May 27, 2026
930390d
test: mock Find-PSResource to eliminate PSGallery network dependency
MariusStorhaug May 27, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
639 changes: 22 additions & 617 deletions .github/workflows/Action-Test.yml

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ runs:
shell: pwsh
working-directory: ${{ inputs.WorkingDirectory }}
env:
GH_TOKEN: ${{ github.token }}
PSMODULE_RESOLVE_PSMODULEVERSION_INPUT_Settings: ${{ inputs.Settings }}
PSMODULE_RESOLVE_PSMODULEVERSION_INPUT_Name: ${{ inputs.Name }}
PSMODULE_RESOLVE_PSMODULEVERSION_INPUT_EventJson: ${{ inputs.EventJson }}
Expand Down
239 changes: 120 additions & 119 deletions scripts/Helpers.psm1
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
function Split-CommaSeparatedList {
<#
.SYNOPSIS
Splits a comma-separated string into a trimmed, non-empty array.
.SYNOPSIS
Splits a comma-separated string into a trimmed, non-empty array.

.EXAMPLE
Split-CommaSeparatedList -Value 'Major, Minor, Patch'
.EXAMPLE
Split-CommaSeparatedList -Value 'Major, Minor, Patch'

Returns @('Major', 'Minor', 'Patch').
#>
Returns @('Major', 'Minor', 'Patch').
#>
[CmdletBinding()]
[OutputType([string[]])]
param(
Expand All @@ -21,19 +21,19 @@

function Read-ActionInput {
<#
.SYNOPSIS
Reads and validates action inputs from environment variables.
.SYNOPSIS
Reads and validates action inputs from environment variables.

.DESCRIPTION
Reads the module name and settings JSON from GitHub Actions environment variables.
Falls back to the repository name when the module name input is not provided.
.DESCRIPTION
Reads the module name and settings JSON from GitHub Actions environment variables.
Falls back to the repository name when the module name input is not provided.

.OUTPUTS
PSCustomObject with Name and SettingsJson properties.
.OUTPUTS
PSCustomObject with Name and SettingsJson properties.

.EXAMPLE
$actionInput = Read-ActionInput
#>
.EXAMPLE
$actionInput = Read-ActionInput
#>
[CmdletBinding()]
[OutputType([PSCustomObject])]
param()
Expand Down Expand Up @@ -62,19 +62,19 @@ function Read-ActionInput {

function Get-PublishConfiguration {
<#
.SYNOPSIS
Parses the settings JSON into a publish configuration object.
.SYNOPSIS
Parses the settings JSON into a publish configuration object.

.DESCRIPTION
Extracts publish module settings including auto-patching flags, version prefix,
release type, and label classification arrays.
.DESCRIPTION
Extracts publish module settings including auto-patching flags, version prefix,
release type, and label classification arrays.

.OUTPUTS
PSCustomObject with publish configuration properties.
.OUTPUTS
PSCustomObject with publish configuration properties.

.EXAMPLE
$config = Get-PublishConfiguration -SettingsJson $actionInput.SettingsJson
#>
.EXAMPLE
$config = Get-PublishConfiguration -SettingsJson $actionInput.SettingsJson
#>
[Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSReviewUnusedParameter', '',
Justification = 'Parameter is used inside LogGroup script block.')]
[CmdletBinding()]
Expand Down Expand Up @@ -122,19 +122,19 @@ function Get-PublishConfiguration {

function Get-GitHubPullRequest {
<#
.SYNOPSIS
Reads and validates the GitHub pull request from the event payload.
.SYNOPSIS
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.
.DESCRIPTION
Loads the GitHub event from the input override or from the event path file,
then validates and extracts pull request data.

.OUTPUTS
PSCustomObject with HeadRef and Labels properties.
.OUTPUTS
PSCustomObject with HeadRef and Labels properties.

.EXAMPLE
$pullRequest = Get-GitHubPullRequest
#>
.EXAMPLE
$pullRequest = Get-GitHubPullRequest
#>
[CmdletBinding()]
[OutputType([PSCustomObject])]
param()
Expand Down Expand Up @@ -171,20 +171,20 @@ function Get-GitHubPullRequest {

function Resolve-ReleaseDecision {
<#
.SYNOPSIS
Determines whether to publish a release and what kind of version bump to apply.
.SYNOPSIS
Determines whether to publish a release and what kind of version bump to apply.

.DESCRIPTION
Evaluates the PR labels against the configured label categories and release type
to produce a complete release decision.
.DESCRIPTION
Evaluates the PR labels against the configured label categories and release type
to produce a complete release decision.

.OUTPUTS
PSCustomObject with ShouldPublish, CreateRelease, CreatePrerelease, MajorRelease,
MinorRelease, PatchRelease, HasVersionBump, and PrereleaseName properties.
.OUTPUTS
PSCustomObject with ShouldPublish, CreateRelease, CreatePrerelease, MajorRelease,
MinorRelease, PatchRelease, HasVersionBump, and PrereleaseName properties.

.EXAMPLE
$decision = Resolve-ReleaseDecision -Configuration $config -PullRequest $pullRequest
#>
.EXAMPLE
$decision = Resolve-ReleaseDecision -Configuration $config -PullRequest $pullRequest
#>
[Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSReviewUnusedParameter', '',
Justification = 'Parameter is used inside LogGroup script block.')]
[CmdletBinding()]
Expand Down Expand Up @@ -222,10 +222,14 @@ function Resolve-ReleaseDecision {
$shouldPublish = $false
}

# Defaults: always produce a prerelease patch version.
$majorRelease = $false
$minorRelease = $false
$patchRelease = $false
$hasVersionBump = $false
$patchRelease = $true
$hasVersionBump = $true
if (-not $shouldPublish) {
$createPrerelease = $true
}

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

Expand Down Expand Up @@ -268,15 +275,15 @@ function Resolve-ReleaseDecision {

function Get-GitHubRelease {
<#
.SYNOPSIS
Retrieves all releases from the current GitHub repository.
.SYNOPSIS
Retrieves all releases from the current GitHub repository.

.OUTPUTS
Array of release objects.
.OUTPUTS
Array of release objects.

.EXAMPLE
$releases = Get-GitHubReleases
#>
.EXAMPLE
$releases = Get-GitHubRelease
#>
[CmdletBinding()]
[OutputType([array])]
param()
Expand All @@ -300,15 +307,15 @@ function Get-GitHubRelease {

function Get-LatestGitHubVersion {
<#
.SYNOPSIS
Extracts the latest stable version from a GitHub releases list.
.SYNOPSIS
Extracts the latest stable version from a GitHub releases list.

.OUTPUTS
PSSemVer representing the latest GitHub release version.
.OUTPUTS
PSSemVer representing the latest GitHub release version.

.EXAMPLE
$ghVersion = Get-LatestGitHubVersion -Releases $releases
#>
.EXAMPLE
$ghVersion = Get-LatestGitHubVersion -Releases $releases
#>
[Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSReviewUnusedParameter', '',
Justification = 'Parameter is used inside LogGroup script block.')]
[CmdletBinding()]
Expand Down Expand Up @@ -337,19 +344,19 @@ function Get-LatestGitHubVersion {

function Get-LatestPSGalleryVersion {
<#
.SYNOPSIS
Finds the latest stable version of a module in the PowerShell Gallery.
.SYNOPSIS
Finds the latest stable version of a module in the PowerShell Gallery.

.DESCRIPTION
Queries the PowerShell Gallery for the latest published version of the module.
Retries up to five times with a ten-second delay between attempts.
.DESCRIPTION
Queries the PowerShell Gallery for the latest published version of the module.
Retries up to five times with a ten-second delay between attempts.

.OUTPUTS
PSSemVer representing the latest PSGallery version.
.OUTPUTS
PSSemVer representing the latest PSGallery version.

.EXAMPLE
$psGalleryVersion = Get-LatestPSGalleryVersion -ModuleName 'MyModule'
#>
.EXAMPLE
$psGalleryVersion = Get-LatestPSGalleryVersion -ModuleName 'MyModule'
#>
[Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSReviewUnusedParameter', '',
Justification = 'Parameter is used inside LogGroup script block.')]
[CmdletBinding()]
Expand Down Expand Up @@ -395,15 +402,15 @@ function Get-LatestPSGalleryVersion {

function Get-LatestPublishedVersion {
<#
.SYNOPSIS
Returns the highest version between GitHub and the PowerShell Gallery.
.SYNOPSIS
Returns the highest version between GitHub and the PowerShell Gallery.

.OUTPUTS
PSSemVer representing the highest known published version.
.OUTPUTS
PSSemVer representing the highest known published version.

.EXAMPLE
$latestVersion = Get-LatestPublishedVersion -GitHubVersion $ghVersion -PSGalleryVersion $psGalleryVersion
#>
.EXAMPLE
$latestVersion = Get-LatestPublishedVersion -GitHubVersion $ghVersion -PSGalleryVersion $psGalleryVersion
#>
[Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSReviewUnusedParameter', '',
Justification = 'Parameter is used inside LogGroup script block.')]
[CmdletBinding()]
Expand All @@ -429,20 +436,20 @@ function Get-LatestPublishedVersion {

function Get-NextPrereleaseNumber {
<#
.SYNOPSIS
Calculates the next incremental prerelease number across GitHub and PSGallery.
.SYNOPSIS
Calculates the next incremental prerelease number across GitHub and PSGallery.

.DESCRIPTION
Queries both GitHub releases and the PowerShell Gallery for existing prereleases
matching the base version and prerelease name, then returns the next number
zero-padded to three digits.
.DESCRIPTION
Queries both GitHub releases and the PowerShell Gallery for existing prereleases
matching the base version and prerelease name, then returns the next number
zero-padded to three digits.

.OUTPUTS
String. A zero-padded three-digit number (e.g. '001').
.OUTPUTS
String. A zero-padded three-digit number (e.g. '001').

.EXAMPLE
$number = Get-NextPrereleaseNumber -ModuleName 'MyModule' -BaseVersion '1.2.3' -PrereleaseName 'mybranch' -Releases $releases
#>
.EXAMPLE
$number = Get-NextPrereleaseNumber -ModuleName 'MyModule' -BaseVersion '1.2.3' -PrereleaseName 'mybranch' -Releases $releases
#>
[CmdletBinding()]
[OutputType([string])]
param(
Expand Down Expand Up @@ -502,20 +509,20 @@ function Get-NextPrereleaseNumber {

function Get-NextModuleVersion {
<#
.SYNOPSIS
Calculates the next module version based on the release decision.
.SYNOPSIS
Calculates the next module version based on the release decision.

.DESCRIPTION
Increments the current version according to the version bump type (major, minor, or patch),
then optionally appends a prerelease suffix with support for date-based and incremental numbering.
.DESCRIPTION
Increments the current version according to the version bump type (major, minor, or patch),
then optionally appends a prerelease suffix with support for date-based and incremental numbering.

.OUTPUTS
PSSemVer representing the resolved next version.
.OUTPUTS
PSSemVer representing the resolved next version.

.EXAMPLE
$newVersion = Get-NextModuleVersion -LatestVersion $latestVersion -Decision $decision `
-Configuration $config -ModuleName 'MyModule' -Releases $releases
#>
.EXAMPLE
$newVersion = Get-NextModuleVersion -LatestVersion $latestVersion -Decision $decision `
-Configuration $config -ModuleName 'MyModule' -Releases $releases
#>
[Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSReviewUnusedParameter', '',
Justification = 'Parameter is used inside LogGroup script block.')]
[CmdletBinding()]
Expand Down Expand Up @@ -569,7 +576,7 @@ function Get-NextModuleVersion {
$newVersion.Prerelease += "$(Get-Date -Format $Configuration.DatePrereleaseFormat)"
}

if ($Configuration.IncrementalPrerelease) {
if ($Configuration.IncrementalPrerelease -or -not $Decision.ShouldPublish) {
$baseVersionString = "$($newVersion.Major).$($newVersion.Minor).$($newVersion.Patch)"
$params = @{
ModuleName = $ModuleName
Expand All @@ -588,12 +595,12 @@ function Get-NextModuleVersion {

function Write-ActionOutput {
<#
.SYNOPSIS
Emits the resolved version and release type as GitHub Actions step outputs.
.SYNOPSIS
Emits the resolved version and release type as GitHub Actions step outputs.

.EXAMPLE
Write-ActionOutput -Decision $decision -NewVersion $newVersion
#>
.EXAMPLE
Write-ActionOutput -Decision $decision -NewVersion $newVersion
#>
[Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSReviewUnusedParameter', '',
Justification = 'Parameter is used inside LogGroup script block.')]
[CmdletBinding()]
Expand All @@ -602,21 +609,15 @@ function Write-ActionOutput {
[Parameter(Mandatory)]
[PSCustomObject] $Decision,

# The resolved next version, or $null when no release will be created.
[Parameter()]
# The resolved next version.
[Parameter(Mandatory)]
[object] $NewVersion
)

LogGroup 'Emit outputs' {
$versionString = ''
$prereleaseString = ''
$fullVersionString = ''

if ($NewVersion) {
$versionString = "$($NewVersion.Major).$($NewVersion.Minor).$($NewVersion.Patch)"
$prereleaseString = [string]$NewVersion.Prerelease
$fullVersionString = $NewVersion.ToString()
}
$versionString = "$($NewVersion.Major).$($NewVersion.Minor).$($NewVersion.Patch)"
$prereleaseString = [string]$NewVersion.Prerelease
$fullVersionString = $NewVersion.ToString()

$resolvedReleaseType = if ($Decision.ShouldPublish) {
if ($Decision.CreateRelease) { 'Release' } else { 'Prerelease' }
Expand Down
Loading
Loading