Skip to content

Commit c32a535

Browse files
Add Version and Prerelease inputs to stamp manifest at build time (PSModule/Process-PSModule#326)
1 parent d97391a commit c32a535

5 files changed

Lines changed: 86 additions & 6 deletions

File tree

README.md

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,31 @@
11
# Build-PSModule
22

33
This GitHub Action is a part of the [PSModule framework](https://github.com/PSModule).
4+
5+
It compiles a PowerShell module from a `src/` folder and produces an artifact that is ready to test and ship.
6+
7+
## What's new
8+
9+
`Build-PSModule` now accepts `Version` and `Prerelease` inputs that are stamped directly into the built manifest, so
10+
the artifact uploaded for the test stages is the same artifact that ultimately gets published. When `Version` is not
11+
provided, the placeholder `999.0.0` is used so local builds still produce a valid manifest.
12+
13+
This pairs with [`PSModule/Resolve-PSModuleVersion`](https://github.com/PSModule/Resolve-PSModuleVersion) and the
14+
v3.x rewrite of [`PSModule/Publish-PSModule`](https://github.com/PSModule/Publish-PSModule). See
15+
[PSModule/Process-PSModule#326](https://github.com/PSModule/Process-PSModule/issues/326) for context.
16+
17+
## Inputs
18+
19+
| Name | Description | Required | Default |
20+
| ------------------ | -------------------------------------------------------------------------------------------------------------------- | -------- | -------- |
21+
| `Name` | Name of the module to build. Defaults to the repository name. | No | |
22+
| `Version` | `Major.Minor.Patch` version to stamp into the built manifest. When empty, `999.0.0` is used as a local-build placeholder. | No | `''` |
23+
| `Prerelease` | Optional prerelease tag (for example `feature001`). When set, it is written to `PrivateData.PSData.Prerelease`. | No | `''` |
24+
| `ArtifactName` | Name of the artifact uploaded by the action. | No | `module` |
25+
| `WorkingDirectory` | The working directory where the script will run from. | No | `.` |
26+
27+
## Outputs
28+
29+
| Name | Description |
30+
| ------------------------ | ---------------------------------------- |
31+
| `ModuleOutputFolderPath` | Local path to the built module folder. |

action.yml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,18 @@ inputs:
66
Name:
77
description: Name of the module to process.
88
required: false
9+
Version:
10+
description: |
11+
The Major.Minor.Patch version to stamp into the built module manifest. When empty, the placeholder '999.0.0'
12+
is used so local builds still produce a valid manifest.
13+
required: false
14+
default: ''
15+
Prerelease:
16+
description: |
17+
Optional prerelease tag (for example 'feature001'). When set, the value is written to PrivateData.PSData.Prerelease
18+
so the built artifact is a complete prerelease package without any post-build mutation.
19+
required: false
20+
default: ''
921
ArtifactName:
1022
description: Name of the artifact to upload.
1123
required: false
@@ -27,6 +39,8 @@ runs:
2739
working-directory: ${{ inputs.WorkingDirectory }}
2840
env:
2941
PSMODULE_BUILD_PSMODULE_INPUT_Name: ${{ inputs.Name }}
42+
PSMODULE_BUILD_PSMODULE_INPUT_Version: ${{ inputs.Version }}
43+
PSMODULE_BUILD_PSMODULE_INPUT_Prerelease: ${{ inputs.Prerelease }}
3044
run: |
3145
# Build-PSModule
3246
${{ 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+
# The Major.Minor.Patch version to stamp into the built manifest. Defaults to '999.0.0' for local builds.
33+
[Parameter()]
34+
[string] $ModuleVersion = '999.0.0',
35+
36+
# Optional prerelease tag to stamp into the built manifest.
37+
[Parameter()]
38+
[string] $Prerelease = ''
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 -Prerelease $Prerelease
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: 20 additions & 4 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+
# The Major.Minor.Patch version to stamp into the manifest. Defaults to '999.0.0' for local builds.
36+
[Parameter()]
37+
[string] $ModuleVersion = '999.0.0',
38+
39+
# Optional prerelease tag (without the leading hyphen).
40+
[Parameter()]
41+
[string] $Prerelease = ''
3442
)
3543

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

58-
$manifest.ModuleVersion = '999.0.0'
66+
if ([string]::IsNullOrWhiteSpace($ModuleVersion)) {
67+
$ModuleVersion = '999.0.0'
68+
}
69+
$manifest.ModuleVersion = $ModuleVersion
5970
Write-Host "[ModuleVersion] - [$($manifest.ModuleVersion)]"
6071

72+
if (-not [string]::IsNullOrWhiteSpace($Prerelease)) {
73+
$manifest.Prerelease = $Prerelease
74+
Write-Host "[Prerelease] - [$Prerelease]"
75+
}
76+
6177
$manifest.Author = $manifest.Keys -contains 'Author' ? (-not [string]::IsNullOrEmpty($manifest.Author)) ? $manifest.Author : $env:GITHUB_REPOSITORY_OWNER : $env:GITHUB_REPOSITORY_OWNER
6278
Write-Host "[Author] - [$($manifest.Author)]"
6379

@@ -418,8 +434,8 @@
418434
}
419435

420436
Write-Host '[PreRelease]'
421-
# $manifest.PreRelease = ""
422-
# Is managed by the publish action
437+
# PreRelease is stamped earlier in this function when a value is provided via the Prerelease parameter.
438+
# No mutation happens after the manifest is built; the resulting artifact is the one that ships.
423439

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

src/main.ps1

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,22 @@ Set-GitHubLogGroup 'Loading inputs' {
2323
}
2424
$sourceFolderPath = Resolve-Path -Path 'src' | Select-Object -ExpandProperty Path
2525
$moduleOutputFolderPath = Join-Path $pwd -ChildPath 'outputs/module'
26+
$moduleVersion = if ([string]::IsNullOrWhiteSpace($env:PSMODULE_BUILD_PSMODULE_INPUT_Version)) {
27+
'999.0.0'
28+
} else {
29+
$env:PSMODULE_BUILD_PSMODULE_INPUT_Version
30+
}
31+
$modulePrerelease = if ([string]::IsNullOrWhiteSpace($env:PSMODULE_BUILD_PSMODULE_INPUT_Prerelease)) {
32+
''
33+
} else {
34+
$env:PSMODULE_BUILD_PSMODULE_INPUT_Prerelease
35+
}
2636
[pscustomobject]@{
2737
moduleName = $moduleName
2838
sourceFolderPath = $sourceFolderPath
2939
moduleOutputFolderPath = $moduleOutputFolderPath
40+
moduleVersion = $moduleVersion
41+
modulePrerelease = $modulePrerelease
3042
} | Format-List | Out-String
3143
}
3244

@@ -47,6 +59,8 @@ $params = @{
4759
ModuleName = $moduleName
4860
ModuleSourceFolderPath = $sourceFolderPath
4961
ModuleOutputFolderPath = $moduleOutputFolderPath
62+
ModuleVersion = $moduleVersion
63+
Prerelease = $modulePrerelease
5064
}
5165
Build-PSModule @params
5266

0 commit comments

Comments
 (0)