Skip to content

Commit f897a03

Browse files
Stamp module version and prerelease into manifest from inputs
1 parent d97391a commit f897a03

4 files changed

Lines changed: 39 additions & 7 deletions

File tree

action.yml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,12 @@ inputs:
66
Name:
77
description: Name of the module to process.
88
required: false
9+
Version:
10+
description: Module version to stamp into the manifest. When empty, the manifest version defaults to `999.0.0`.
11+
required: false
12+
Prerelease:
13+
description: Prerelease tag to stamp into the manifest's `PrivateData.PSData.Prerelease`. When empty, no prerelease tag is written.
14+
required: false
915
ArtifactName:
1016
description: Name of the artifact to upload.
1117
required: false
@@ -27,6 +33,8 @@ runs:
2733
working-directory: ${{ inputs.WorkingDirectory }}
2834
env:
2935
PSMODULE_BUILD_PSMODULE_INPUT_Name: ${{ inputs.Name }}
36+
PSMODULE_BUILD_PSMODULE_INPUT_Version: ${{ inputs.Version }}
37+
PSMODULE_BUILD_PSMODULE_INPUT_Prerelease: ${{ inputs.Prerelease }}
3038
run: |
3139
# Build-PSModule
3240
${{ github.action_path }}/src/main.ps1

src/helpers/Build-PSModule.ps1

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,15 @@
2727

2828
# Path to the folder where the built modules are outputted.
2929
[Parameter(Mandatory)]
30-
[string] $ModuleOutputFolderPath
30+
[string] $ModuleOutputFolderPath,
31+
32+
# Module version to stamp into the manifest. When empty, defaults to '999.0.0'.
33+
[Parameter()]
34+
[string] $ModuleVersion,
35+
36+
# Prerelease tag to stamp into the manifest. When empty, no prerelease tag is written.
37+
[Parameter()]
38+
[string] $ModulePrerelease
3139
)
3240

3341
Set-GitHubLogGroup "Building module [$ModuleName]" {
@@ -40,7 +48,7 @@
4048
}
4149

4250
Build-PSModuleBase -ModuleName $ModuleName -ModuleSourceFolder $moduleSourceFolder -ModuleOutputFolder $moduleOutputFolder
43-
Build-PSModuleManifest -ModuleName $ModuleName -ModuleOutputFolder $moduleOutputFolder
51+
Build-PSModuleManifest -ModuleName $ModuleName -ModuleOutputFolder $moduleOutputFolder -ModuleVersion $ModuleVersion -ModulePrerelease $ModulePrerelease
4452
Build-PSModuleRootModule -ModuleName $ModuleName -ModuleOutputFolder $moduleOutputFolder
4553
Update-PSModuleManifestAliasesToExport -ModuleName $ModuleName -ModuleSourceFolder $moduleSourceFolder -ModuleOutputFolder $moduleOutputFolder
4654

src/helpers/Build/Build-PSModuleManifest.ps1

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,15 @@
3030

3131
# Folder where the built modules are outputted. 'outputs/modules/MyModule'
3232
[Parameter(Mandatory)]
33-
[System.IO.DirectoryInfo] $ModuleOutputFolder
33+
[System.IO.DirectoryInfo] $ModuleOutputFolder,
34+
35+
# Module version to stamp into the manifest. When empty, defaults to '999.0.0'.
36+
[Parameter()]
37+
[string] $ModuleVersion,
38+
39+
# Prerelease tag to stamp into the manifest's `PrivateData.PSData.Prerelease`.
40+
[Parameter()]
41+
[string] $ModulePrerelease
3442
)
3543

3644
Set-GitHubLogGroup 'Build manifest file' {
@@ -55,7 +63,7 @@
5563
$manifest.RootModule = $rootModule
5664
Write-Host "[RootModule] - [$($manifest.RootModule)]"
5765

58-
$manifest.ModuleVersion = '999.0.0'
66+
$manifest.ModuleVersion = if ([string]::IsNullOrWhiteSpace($ModuleVersion)) { '999.0.0' } else { $ModuleVersion }
5967
Write-Host "[ModuleVersion] - [$($manifest.ModuleVersion)]"
6068

6169
$manifest.Author = $manifest.Keys -contains 'Author' ? (-not [string]::IsNullOrEmpty($manifest.Author)) ? $manifest.Author : $env:GITHUB_REPOSITORY_OWNER : $env:GITHUB_REPOSITORY_OWNER
@@ -417,9 +425,11 @@
417425
$manifest.Remove('ReleaseNotes')
418426
}
419427

420-
Write-Host '[PreRelease]'
421-
# $manifest.PreRelease = ""
422-
# Is managed by the publish action
428+
Write-Host '[Prerelease]'
429+
if (-not [string]::IsNullOrWhiteSpace($ModulePrerelease)) {
430+
$manifest.Prerelease = $ModulePrerelease
431+
Write-Host "[Prerelease] - [$($manifest.Prerelease)]"
432+
}
423433

424434
Write-Host '[RequireLicenseAcceptance]'
425435
$manifest.RequireLicenseAcceptance = $PSData.Keys -contains 'RequireLicenseAcceptance' ? $null -ne $PSData.RequireLicenseAcceptance ? $PSData.RequireLicenseAcceptance : $false : $false

src/main.ps1

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,14 @@ Set-GitHubLogGroup 'Loading inputs' {
2121
} else {
2222
$env:PSMODULE_BUILD_PSMODULE_INPUT_Name
2323
}
24+
$moduleVersion = $env:PSMODULE_BUILD_PSMODULE_INPUT_Version
25+
$modulePrerelease = $env:PSMODULE_BUILD_PSMODULE_INPUT_Prerelease
2426
$sourceFolderPath = Resolve-Path -Path 'src' | Select-Object -ExpandProperty Path
2527
$moduleOutputFolderPath = Join-Path $pwd -ChildPath 'outputs/module'
2628
[pscustomobject]@{
2729
moduleName = $moduleName
30+
moduleVersion = $moduleVersion
31+
modulePrerelease = $modulePrerelease
2832
sourceFolderPath = $sourceFolderPath
2933
moduleOutputFolderPath = $moduleOutputFolderPath
3034
} | Format-List | Out-String
@@ -47,6 +51,8 @@ $params = @{
4751
ModuleName = $moduleName
4852
ModuleSourceFolderPath = $sourceFolderPath
4953
ModuleOutputFolderPath = $moduleOutputFolderPath
54+
ModuleVersion = $moduleVersion
55+
ModulePrerelease = $modulePrerelease
5056
}
5157
Build-PSModule @params
5258

0 commit comments

Comments
 (0)