Skip to content

Commit 40ed488

Browse files
test: add prerelease and unstamped version test cases
- Add module-prerelease test fixture with Prerelease = 'preview1' - Add module-unstamped test fixture with placeholder 999.0.0 - Add ActionTestPrerelease job validating prerelease tag/context - Add ActionTestUnstamped job expecting action to reject 999.0.0 - Add 999.0.0 rejection guard in publish.ps1
1 parent 3d50e52 commit 40ed488

6 files changed

Lines changed: 266 additions & 1 deletion

File tree

.github/workflows/Action-Test.yml

Lines changed: 110 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name: Action-Test
22

3-
run-name: "Action-Test - [${{ github.event.pull_request.title }} #${{ github.event.pull_request.number }}] by @${{ github.actor }}"
3+
run-name: 'Action-Test - [${{ github.event.pull_request.title }} #${{ github.event.pull_request.number }}] by @${{ github.actor }}'
44

55
on:
66
workflow_dispatch:
@@ -62,3 +62,112 @@ jobs:
6262
exit 1
6363
}
6464
Write-Host "Version validation passed: [$version] (tag: [$releaseTag])"
65+
66+
ActionTestPrerelease:
67+
name: Action-Test - [Prerelease]
68+
runs-on: ubuntu-latest
69+
steps:
70+
- name: Checkout repo
71+
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
72+
with:
73+
persist-credentials: false
74+
75+
- name: Upload module artifact
76+
uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1
77+
with:
78+
name: module-prerelease
79+
path: tests/outputs/module-prerelease
80+
81+
- name: Action-Test
82+
uses: ./
83+
env:
84+
GITHUB_TOKEN: ${{ github.token }}
85+
with:
86+
Name: PSModuleTest
87+
ModulePath: outputs/module-prerelease
88+
WorkingDirectory: tests
89+
APIKey: ${{ secrets.APIKEY }} # zizmor: ignore[secrets-outside-env] saved in org secrets as an intentional choice
90+
WhatIf: true
91+
92+
- name: Validate prerelease version
93+
shell: pwsh
94+
run: |
95+
$manifestPath = 'tests/outputs/module-prerelease/PSModuleTest/PSModuleTest.psd1'
96+
$manifest = Import-PowerShellDataFile -Path $manifestPath
97+
$version = $manifest.ModuleVersion
98+
$prerelease = $manifest.PrivateData.PSData.Prerelease
99+
$releaseTag = $env:PSMODULE_PUBLISH_PSMODULE_CONTEXT_ReleaseTag
100+
$isPrerelease = $env:PSMODULE_PUBLISH_PSMODULE_CONTEXT_IsPrerelease
101+
102+
Write-Host "Module version in manifest: [$version]"
103+
Write-Host "Prerelease label: [$prerelease]"
104+
Write-Host "Release tag from action: [$releaseTag]"
105+
Write-Host "IsPrerelease: [$isPrerelease]"
106+
107+
if ($version -eq '999.0.0') {
108+
Write-Error "Module version is still the placeholder [999.0.0]. The artifact was not stamped with a real version."
109+
exit 1
110+
}
111+
if ([string]::IsNullOrEmpty($prerelease)) {
112+
Write-Error 'Prerelease label is missing from manifest.'
113+
exit 1
114+
}
115+
if ($releaseTag -ne "$version-$prerelease") {
116+
Write-Error "Release tag [$releaseTag] does not match expected [$version-$prerelease]."
117+
exit 1
118+
}
119+
if ($isPrerelease -ne 'true') {
120+
Write-Error "IsPrerelease context should be 'true' but got [$isPrerelease]."
121+
exit 1
122+
}
123+
Write-Host "Prerelease validation passed: [$version-$prerelease] (tag: [$releaseTag])"
124+
125+
ActionTestUnstamped:
126+
name: Action-Test - [Unstamped - expect failure]
127+
runs-on: ubuntu-latest
128+
steps:
129+
- name: Checkout repo
130+
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
131+
with:
132+
persist-credentials: false
133+
134+
- name: Upload module artifact
135+
uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1
136+
with:
137+
name: module-unstamped
138+
path: tests/outputs/module-unstamped
139+
140+
- name: Action-Test
141+
id: publish
142+
uses: ./
143+
continue-on-error: true
144+
env:
145+
GITHUB_TOKEN: ${{ github.token }}
146+
with:
147+
Name: PSModuleTest
148+
ModulePath: outputs/module-unstamped
149+
WorkingDirectory: tests
150+
APIKey: ${{ secrets.APIKEY }} # zizmor: ignore[secrets-outside-env] saved in org secrets as an intentional choice
151+
WhatIf: true
152+
153+
- name: Validate unstamped artifact is rejected
154+
shell: pwsh
155+
run: |
156+
$manifestPath = 'tests/outputs/module-unstamped/PSModuleTest/PSModuleTest.psd1'
157+
$manifest = Import-PowerShellDataFile -Path $manifestPath
158+
$version = $manifest.ModuleVersion
159+
$releaseTag = $env:PSMODULE_PUBLISH_PSMODULE_CONTEXT_ReleaseTag
160+
161+
Write-Host "Module version in manifest: [$version]"
162+
Write-Host "Release tag from action: [$releaseTag]"
163+
Write-Host "Publish step outcome: [${{ steps.publish.outcome }}]"
164+
165+
if ($version -ne '999.0.0') {
166+
Write-Error "Expected placeholder version [999.0.0] but got [$version]."
167+
exit 1
168+
}
169+
if ('${{ steps.publish.outcome }}' -eq 'success') {
170+
Write-Error 'The publish action should have failed for an unstamped artifact but it succeeded.'
171+
exit 1
172+
}
173+
Write-Host 'Unstamped artifact was correctly rejected by the action.'

src/publish.ps1

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,11 @@ LogGroup 'Resolve version from manifest' {
9292
'Ensure Build-PSModule has stamped the artifact with a final version.')
9393
exit 1
9494
}
95+
if ($moduleVersion -eq '999.0.0') {
96+
Write-Error ("ModuleVersion is the placeholder [999.0.0]. " +
97+
'The artifact was not stamped with a real version by the build step.')
98+
exit 1
99+
}
95100
$prerelease = $manifestData.PrivateData.PSData.Prerelease
96101
if ([string]::IsNullOrWhiteSpace($prerelease)) {
97102
$prerelease = ''
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
@{
2+
RootModule = 'PSModuleTest.psm1'
3+
ModuleVersion = '2.0.0'
4+
CompatiblePSEditions = @(
5+
'Core'
6+
'Desktop'
7+
)
8+
GUID = '20b37221-db1c-43db-9cca-f22b33123548'
9+
Author = 'PSModule'
10+
CompanyName = 'PSModule'
11+
Copyright = '(c) 2024 PSModule. All rights reserved.'
12+
Description = 'Process a module from source code to published module.'
13+
PowerShellVersion = '5.1'
14+
ProcessorArchitecture = 'None'
15+
RequiredModules = @(
16+
@{
17+
ModuleVersion = '1.0'
18+
ModuleName = 'PSSemVer'
19+
}
20+
'Utilities'
21+
)
22+
RequiredAssemblies = 'assemblies/LsonLib.dll'
23+
ScriptsToProcess = 'scripts/loader.ps1'
24+
TypesToProcess = @(
25+
'types/DirectoryInfo.Types.ps1xml'
26+
'types/FileInfo.Types.ps1xml'
27+
)
28+
FormatsToProcess = @(
29+
'formats/CultureInfo.Format.ps1xml'
30+
'formats/Mygciview.Format.ps1xml'
31+
)
32+
NestedModules = @(
33+
'modules/OtherPSModule.psm1'
34+
)
35+
FunctionsToExport = @(
36+
'Get-PSModuleTest'
37+
'New-PSModuleTest'
38+
'Set-PSModuleTest'
39+
'Test-PSModuleTest'
40+
)
41+
CmdletsToExport = @()
42+
VariablesToExport = @()
43+
AliasesToExport = '*'
44+
ModuleList = @(
45+
'modules/OtherPSModule.psm1'
46+
)
47+
FileList = @(
48+
'PSModuleTest.psd1'
49+
'PSModuleTest.psm1'
50+
'assemblies/LsonLib.dll'
51+
'data/Config.psd1'
52+
'data/Settings.psd1'
53+
'formats/CultureInfo.Format.ps1xml'
54+
'formats/Mygciview.Format.ps1xml'
55+
'modules/OtherPSModule.psm1'
56+
'scripts/loader.ps1'
57+
'types/DirectoryInfo.Types.ps1xml'
58+
'types/FileInfo.Types.ps1xml'
59+
)
60+
PrivateData = @{
61+
PSData = @{
62+
Prerelease = 'preview1'
63+
Tags = @(
64+
'workflow'
65+
'powershell'
66+
'powershell-module'
67+
'PSEdition_Desktop'
68+
'PSEdition_Core'
69+
)
70+
LicenseUri = 'https://github.com/PSModule/Process-PSModule/blob/main/LICENSE'
71+
ProjectUri = 'https://github.com/PSModule/Process-PSModule'
72+
IconUri = 'https://raw.githubusercontent.com/PSModule/Process-PSModule/main/icon/icon.png'
73+
}
74+
}
75+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# Placeholder module file for testing
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
@{
2+
RootModule = 'PSModuleTest.psm1'
3+
ModuleVersion = '999.0.0'
4+
CompatiblePSEditions = @(
5+
'Core'
6+
'Desktop'
7+
)
8+
GUID = '20b37221-db1c-43db-9cca-f22b33123548'
9+
Author = 'PSModule'
10+
CompanyName = 'PSModule'
11+
Copyright = '(c) 2024 PSModule. All rights reserved.'
12+
Description = 'Process a module from source code to published module.'
13+
PowerShellVersion = '5.1'
14+
ProcessorArchitecture = 'None'
15+
RequiredModules = @(
16+
@{
17+
ModuleVersion = '1.0'
18+
ModuleName = 'PSSemVer'
19+
}
20+
'Utilities'
21+
)
22+
RequiredAssemblies = 'assemblies/LsonLib.dll'
23+
ScriptsToProcess = 'scripts/loader.ps1'
24+
TypesToProcess = @(
25+
'types/DirectoryInfo.Types.ps1xml'
26+
'types/FileInfo.Types.ps1xml'
27+
)
28+
FormatsToProcess = @(
29+
'formats/CultureInfo.Format.ps1xml'
30+
'formats/Mygciview.Format.ps1xml'
31+
)
32+
NestedModules = @(
33+
'modules/OtherPSModule.psm1'
34+
)
35+
FunctionsToExport = @(
36+
'Get-PSModuleTest'
37+
'New-PSModuleTest'
38+
'Set-PSModuleTest'
39+
'Test-PSModuleTest'
40+
)
41+
CmdletsToExport = @()
42+
VariablesToExport = @()
43+
AliasesToExport = '*'
44+
ModuleList = @(
45+
'modules/OtherPSModule.psm1'
46+
)
47+
FileList = @(
48+
'PSModuleTest.psd1'
49+
'PSModuleTest.psm1'
50+
'assemblies/LsonLib.dll'
51+
'data/Config.psd1'
52+
'data/Settings.psd1'
53+
'formats/CultureInfo.Format.ps1xml'
54+
'formats/Mygciview.Format.ps1xml'
55+
'modules/OtherPSModule.psm1'
56+
'scripts/loader.ps1'
57+
'types/DirectoryInfo.Types.ps1xml'
58+
'types/FileInfo.Types.ps1xml'
59+
)
60+
PrivateData = @{
61+
PSData = @{
62+
Tags = @(
63+
'workflow'
64+
'powershell'
65+
'powershell-module'
66+
'PSEdition_Desktop'
67+
'PSEdition_Core'
68+
)
69+
LicenseUri = 'https://github.com/PSModule/Process-PSModule/blob/main/LICENSE'
70+
ProjectUri = 'https://github.com/PSModule/Process-PSModule'
71+
IconUri = 'https://raw.githubusercontent.com/PSModule/Process-PSModule/main/icon/icon.png'
72+
}
73+
}
74+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# Placeholder module file for testing

0 commit comments

Comments
 (0)