Skip to content

Commit 51de598

Browse files
Honor module publication skip and validate all publication schema keys
1 parent 8e007ff commit 51de598

6 files changed

Lines changed: 94 additions & 5 deletions

File tree

‎.github/actions/Get-PSModuleSettings/src/Settings.schema.json‎

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,7 @@
129129
"Module": {
130130
"type": "object",
131131
"description": "Module publish configuration",
132+
"additionalProperties": false,
132133
"not": {
133134
"required": [
134135
"AutoPatching"
@@ -210,6 +211,49 @@
210211
"None"
211212
],
212213
"description": "The type of release to create: Release (stable), Prerelease, or None."
214+
},
215+
"DefaultBumpSource": {
216+
"type": "string",
217+
"enum": [
218+
"SharedDefault",
219+
"Publish.Module.DefaultBump"
220+
],
221+
"description": "Derived runtime provenance; not an authorable setting."
222+
},
223+
"Desired": {
224+
"type": "boolean",
225+
"description": "Derived runtime publication intent."
226+
},
227+
"Enabled": {
228+
"type": "boolean",
229+
"description": "Derived runtime publication execution state."
230+
},
231+
"Resolution": {
232+
"type": "object",
233+
"additionalProperties": false,
234+
"description": "Derived version-resolution output, not authorable settings.",
235+
"properties": {
236+
"Version": {
237+
"type": "string"
238+
},
239+
"Prerelease": {
240+
"type": "string"
241+
},
242+
"FullVersion": {
243+
"type": "string"
244+
},
245+
"ReleaseType": {
246+
"type": "string",
247+
"enum": [
248+
"Release",
249+
"Prerelease",
250+
"None"
251+
]
252+
},
253+
"CreateRelease": {
254+
"type": "boolean"
255+
}
256+
}
213257
}
214258
}
215259
},

‎.github/actions/Get-PSModuleSettings/src/main.ps1‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -715,8 +715,9 @@ Set-GitHubLogGroup 'Calculate Job Run Conditions:' {
715715
)
716716
) -Force
717717

718-
$settings.Publish.Module | Add-Member -MemberType NoteProperty -Name Desired -Value (($releaseType -ne 'None') -or $shouldAutoCleanup) -Force
719-
$settings.Publish.Module | Add-Member -MemberType NoteProperty -Name Enabled -Value (($releaseType -ne 'None') -or $shouldAutoCleanup) -Force
718+
$modulePublicationEnabled = -not $settings.Publish.Module.Skip -and (($releaseType -ne 'None') -or $shouldAutoCleanup)
719+
$settings.Publish.Module | Add-Member -MemberType NoteProperty -Name Desired -Value $modulePublicationEnabled -Force
720+
$settings.Publish.Module | Add-Member -MemberType NoteProperty -Name Enabled -Value $modulePublicationEnabled -Force
720721
$settings.Publish.Site | Add-Member -MemberType NoteProperty -Name Desired -Value ($releaseType -eq 'Release') -Force
721722
$settings.Publish.Site | Add-Member -MemberType NoteProperty -Name Enabled -Value (
722723
$releaseType -eq 'Release' -and -not $settings.Publish.Site.Skip

‎.github/actions/Get-PSModuleSettings/tests/Get-PSModuleSettings.Helpers.Tests.ps1‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,14 @@ Describe 'Resolve-PSModulePublishSetting' {
196196

197197
Test-Json -Json $json -SchemaFile $schemaPath -ErrorAction Stop | Should -BeFalse
198198
}
199+
200+
It 'rejects unknown publication keys in schema validation as well as normalization' {
201+
$schemaPath = Join-Path -Path $PSScriptRoot -ChildPath '../src/Settings.schema.json'
202+
$json = @{ Publish = @{ Module = @{ DefaultBump = 'patch'; DefautBump = 'minor' } } } |
203+
ConvertTo-Json -Depth 5
204+
205+
Test-Json -Json $json -SchemaFile $schemaPath -ErrorAction Stop | Should -BeFalse
206+
}
199207
}
200208

201209
Describe 'Select-PullRequestForPush' {

‎.github/actions/Get-PSModuleSettings/tests/Get-PSModuleSettings.Main.Tests.ps1‎

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -208,4 +208,19 @@ Describe 'Get-PSModuleSettings release-bearing push detection' {
208208

209209
$script:state.Outputs.Count | Should -Be 0
210210
}
211+
212+
It 'honors repository-wide module publication skip for an important default-branch push' {
213+
$script:state.Files = @('src/Module.psm1')
214+
$script:state.Associated[0].merge_commit_sha = 'pushed-sha'
215+
@{
216+
Name = 'SettingsFixture'; Test = @{ Skip = $true }; Publish = @{ Module = @{ Skip = $true } }
217+
} | ConvertTo-Json -Depth 5 | Set-Content -LiteralPath $env:PSMODULE_GET_SETTINGS_INPUT_SettingsPath
218+
219+
& $script:settingsScriptPath
220+
$settings = $script:state.Outputs.Settings | ConvertFrom-Json
221+
222+
$settings.HasImportantChanges | Should -BeTrue
223+
$settings.Publish.Module.Skip | Should -BeTrue
224+
$settings.Publish.Module.Enabled | Should -BeFalse
225+
}
211226
}

‎.github/actions/Resolve-PSModuleVersion/src/Resolve-PSModuleVersion.Helpers.psm1‎

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
function Split-CommaSeparatedList {
1+
function Split-CommaSeparatedList {
22
<#
33
.SYNOPSIS
44
Splits a comma-separated string into a trimmed, non-empty array.
@@ -143,6 +143,7 @@ function Get-PublishConfiguration {
143143
)
144144

145145
$config = [PSCustomObject]@{
146+
Skip = [bool]$publishModule.Skip
146147
DefaultBump = $defaultBump
147148
DefaultBumpSource = [string]($publishModule.DefaultBumpSource ?? 'Publish.Module.DefaultBump')
148149
IncrementalPrerelease = [bool]$publishModule.IncrementalPrerelease
@@ -159,6 +160,7 @@ function Get-PublishConfiguration {
159160

160161
Write-Host '-------------------------------------------------'
161162
Write-Host ([PSCustomObject]@{
163+
Skip = $config.Skip
162164
DefaultBump = $config.DefaultBump
163165
DefaultBumpSource = $config.DefaultBumpSource
164166
IncrementalPrerelease = $config.IncrementalPrerelease
@@ -309,7 +311,10 @@ function Resolve-ReleaseDecision {
309311

310312
$createRelease = $releaseType -eq 'Release'
311313
$createPrerelease = $releaseType -eq 'Prerelease'
312-
$shouldPublish = $createRelease -or $createPrerelease
314+
$shouldPublish = ($createRelease -or $createPrerelease) -and $Configuration.Skip -ne $true
315+
if ($Configuration.Skip -eq $true) {
316+
$createRelease = $false
317+
}
313318
$isCleanupOnly = $Configuration.IsCleanupOnly -eq $true
314319

315320
if ($isCleanupOnly) {

‎.github/actions/Resolve-PSModuleVersion/tests/Resolve-PSModuleVersion.Helpers.Tests.ps1‎

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
[Diagnostics.CodeAnalysis.SuppressMessageAttribute(
1+
[Diagnostics.CodeAnalysis.SuppressMessageAttribute(
22
'PSUseDeclaredVarsMoreThanAssignments', '',
33
Justification = 'Variables are assigned in BeforeAll and used inside It blocks.'
44
)]
@@ -42,6 +42,10 @@ BeforeAll {
4242
[Parameter()]
4343
[switch] $CleanupOnly,
4444

45+
# Whether module publication is disabled by repository settings.
46+
[Parameter()]
47+
[switch] $Skip,
48+
4549
# Labels indicating no release.
4650
[Parameter()]
4751
[string[]] $IgnoreLabels = @('release:skip'),
@@ -70,6 +74,7 @@ BeforeAll {
7074
VersionPrefix = $VersionPrefix
7175
ReleaseType = $ReleaseType
7276
IsCleanupOnly = $CleanupOnly.IsPresent
77+
Skip = $Skip.IsPresent
7378
IgnoreLabels = $IgnoreLabels
7479
MajorLabels = $MajorLabels
7580
MinorLabels = $MinorLabels
@@ -901,5 +906,16 @@ Describe 'Resolve-PSModuleVersion' {
901906
{ Resolve-ReleaseDecision -Configuration $configuration -PullRequest $pullRequest } |
902907
Should -Throw '*ignore*prerelease*'
903908
}
909+
910+
It 'keeps a configured preview bump without publishing when module Skip is enabled' {
911+
$configuration = Get-TestConfiguration -DefaultBump minor -Skip
912+
$pullRequest = [pscustomobject]@{ HeadRef = 'feature'; Labels = @() }
913+
914+
$decision = Resolve-ReleaseDecision -Configuration $configuration -PullRequest $pullRequest
915+
916+
$decision.MinorRelease | Should -BeTrue
917+
$decision.ShouldPublish | Should -BeFalse
918+
$decision.CreateRelease | Should -BeFalse
919+
}
904920
}
905921
}

0 commit comments

Comments
 (0)