Skip to content

Commit 06b4714

Browse files
Apply the configured version prefix to the created release tag
The Plan job resolves Publish.Module.VersionPrefix, but the publish action never received it, so the tag was built from the manifest's Major.Minor.Patch alone and repositories on the default 'v' prefix lost it. The prefix now flows from Settings through the action input into the tag. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
1 parent d0f8f7a commit 06b4714

4 files changed

Lines changed: 43 additions & 13 deletions

File tree

.github/actions/Publish-PSModule/action.yml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,13 @@ inputs:
3737
description: Name of the uploaded artifact to download. Must match the name used in the upstream upload-artifact step.
3838
required: false
3939
default: module
40+
VersionPrefix:
41+
description: |
42+
Prefix put in front of the version in the git tag of the GitHub release, for example 'v'.
43+
Comes from Settings.Publish.Module.VersionPrefix, which the Plan job resolves. The compiled manifest carries the module version as
44+
Major.Minor.Patch and cannot carry the prefix, so it is supplied here. An empty value tags the release without a prefix.
45+
required: false
46+
default: ''
4047

4148
runs:
4249
using: composite
@@ -65,4 +72,5 @@ runs:
6572
PSMODULE_PUBLISH_PSMODULE_INPUT_UsePRBodyAsReleaseNotes: ${{ inputs.UsePRBodyAsReleaseNotes }}
6673
PSMODULE_PUBLISH_PSMODULE_INPUT_UsePRTitleAsReleaseName: ${{ inputs.UsePRTitleAsReleaseName }}
6774
PSMODULE_PUBLISH_PSMODULE_INPUT_UsePRTitleAsNotesHeading: ${{ inputs.UsePRTitleAsNotesHeading }}
75+
PSMODULE_PUBLISH_PSMODULE_INPUT_VersionPrefix: ${{ inputs.VersionPrefix }}
6876
run: ${{ github.action_path }}/src/publish.ps1

.github/actions/Publish-PSModule/src/Publish-PSModule.Helpers.psm1

Lines changed: 25 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,22 +4,30 @@
44
Builds the git tag used for the GitHub release.
55
66
.DESCRIPTION
7-
Composes the release tag from the module version and, when present, the prerelease label.
8-
The version comes from the compiled manifest, which is the artifact that is published, so the
9-
tag always names the exact bytes that were tested and pushed to the PowerShell Gallery.
7+
Composes the release tag from the configured version prefix, the module version, and the
8+
prerelease label when there is one. The version comes from the compiled manifest, which is the
9+
artifact that is published, so the tag always names the exact bytes that were tested and pushed
10+
to the PowerShell Gallery. The manifest's ModuleVersion is Major.Minor.Patch by definition and
11+
cannot carry the prefix, so the prefix is supplied from the resolved settings
12+
(Publish.Module.VersionPrefix) instead. An empty prefix produces an unprefixed tag.
1013
1114
.OUTPUTS
1215
String with the release tag.
1316
1417
.EXAMPLE
15-
Get-ReleaseTag -ModuleVersion '1.1.10'
18+
Get-ReleaseTag -VersionPrefix 'v' -ModuleVersion '1.1.10'
1619
17-
Returns '1.1.10'.
20+
Returns 'v1.1.10'.
1821
1922
.EXAMPLE
20-
Get-ReleaseTag -ModuleVersion '1.1.10' -Prerelease 'mybranch001'
23+
Get-ReleaseTag -VersionPrefix 'v' -ModuleVersion '1.1.10' -Prerelease 'mybranch001'
24+
25+
Returns 'v1.1.10-mybranch001'.
2126
22-
Returns '1.1.10-mybranch001'.
27+
.EXAMPLE
28+
Get-ReleaseTag -VersionPrefix '' -ModuleVersion '1.1.10'
29+
30+
Returns '1.1.10'.
2331
#>
2432
[CmdletBinding()]
2533
[OutputType([string])]
@@ -29,16 +37,24 @@
2937
[ValidateNotNullOrEmpty()]
3038
[string] $ModuleVersion,
3139

40+
# The prefix put in front of the version, for example 'v'. Empty for an unprefixed repository.
41+
[Parameter()]
42+
[AllowEmptyString()]
43+
[AllowNull()]
44+
[string] $VersionPrefix,
45+
3246
# The prerelease label from the compiled manifest. Empty for a stable release.
3347
[Parameter()]
3448
[AllowEmptyString()]
3549
[AllowNull()]
3650
[string] $Prerelease
3751
)
3852

53+
$tag = "$($VersionPrefix.Trim())$ModuleVersion"
54+
3955
if ([string]::IsNullOrWhiteSpace($Prerelease)) {
40-
return $ModuleVersion
56+
return $tag
4157
}
4258

43-
"$ModuleVersion-$($Prerelease.Trim())"
59+
"$tag-$($Prerelease.Trim())"
4460
}

.github/actions/Publish-PSModule/src/publish.ps1

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -59,10 +59,14 @@ LogGroup 'Load inputs' {
5959
$usePRBodyAsReleaseNotes = $env:PSMODULE_PUBLISH_PSMODULE_INPUT_UsePRBodyAsReleaseNotes -eq 'true'
6060
$usePRTitleAsReleaseName = $env:PSMODULE_PUBLISH_PSMODULE_INPUT_UsePRTitleAsReleaseName -eq 'true'
6161
$usePRTitleAsNotesHeading = $env:PSMODULE_PUBLISH_PSMODULE_INPUT_UsePRTitleAsNotesHeading -eq 'true'
62+
# The prefix the repository tags releases with, resolved by the Plan job from
63+
# Settings.Publish.Module.VersionPrefix. Empty means the repository tags without a prefix.
64+
$versionPrefix = $env:PSMODULE_PUBLISH_PSMODULE_INPUT_VersionPrefix
6265

63-
Write-Host "Module name: [$name]"
64-
Write-Host "Module path: [$modulePath]"
65-
Write-Host "WhatIf: [$whatIf]"
66+
Write-Host "Module name: [$name]"
67+
Write-Host "Module path: [$modulePath]"
68+
Write-Host "Version prefix: [$versionPrefix]"
69+
Write-Host "WhatIf: [$whatIf]"
6670
}
6771
#endregion Load inputs
6872

@@ -130,10 +134,11 @@ LogGroup 'Resolve version from manifest' {
130134
$createPrerelease = $true
131135
}
132136

133-
$releaseTag = Get-ReleaseTag -ModuleVersion $moduleVersion -Prerelease $prerelease
137+
$releaseTag = Get-ReleaseTag -VersionPrefix $versionPrefix -ModuleVersion $moduleVersion -Prerelease $prerelease
134138

135139
[PSCustomObject]@{
136140
ModuleVersion = $moduleVersion
141+
VersionPrefix = $versionPrefix
137142
Prerelease = $prerelease
138143
CreatePrerelease = $createPrerelease
139144
ReleaseTag = $releaseTag

.github/workflows/Publish-Module.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ jobs:
5050
UsePRTitleAsReleaseName: ${{ fromJson(inputs.Settings).Publish.Module.UsePRTitleAsReleaseName }}
5151
UsePRBodyAsReleaseNotes: ${{ fromJson(inputs.Settings).Publish.Module.UsePRBodyAsReleaseNotes }}
5252
UsePRTitleAsNotesHeading: ${{ fromJson(inputs.Settings).Publish.Module.UsePRTitleAsNotesHeading }}
53+
VersionPrefix: ${{ fromJson(inputs.Settings).Publish.Module.VersionPrefix }}
5354
WorkingDirectory: ${{ fromJson(inputs.Settings).WorkingDirectory }}
5455

5556
- name: Cleanup prereleases

0 commit comments

Comments
 (0)