Skip to content

Commit 28c1805

Browse files
🚀 [Feature]: Separate cleanup from release type and move ReleaseType to Publish.Module (#8)
The release type calculation is now separated from cleanup logic, providing clearer control over when prereleases are cleaned up. The `ReleaseType` now only has three values (`Release`, `Prerelease`, or `None`), and cleanup is computed independently based on the `AutoCleanup` setting. - Part of PSModule/Process-PSModule#73 - Part of PSModule/Process-PSModule#265 ## ReleaseType simplified to three values Previously, `ReleaseType` could be set to `Cleanup` to trigger prerelease cleanup. Now, `ReleaseType` only has three values: `Release`, `Prerelease`, or `None`. The cleanup decision is computed separately based on: 1. Whether you're in a cleanup scenario (merging to main or abandoning a PR) 2. Whether `AutoCleanup` is enabled in your settings (defaults to `true`) This separation enables the abandoned PR cleanup scenario where a PR is closed without merging—the workflow can now trigger cleanup independently of whether a release is being created. ## ReleaseType moved to Publish.Module output The computed `ReleaseType` value is now stored in `Publish.Module.ReleaseType` rather than in the `Run` object. This organizes release-related computed values alongside other publish settings. Workflows should now reference: - `fromJson(inputs.Settings).Publish.Module.ReleaseType` for the release type - `fromJson(inputs.Settings).Publish.Module.AutoCleanup` for the cleanup decision (computed boolean) ## AutoCleanup behavior The `AutoCleanup` setting continues to work as before, but the output value is now a computed boolean that indicates whether cleanup should actually occur (based on both the setting and the current context like merged PR or abandoned PR).
1 parent 98ce7ab commit 28c1805

File tree

4 files changed

+32
-25
lines changed

4 files changed

+32
-25
lines changed

‎scripts/Settings.schema.json‎

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@
128128
},
129129
"AutoCleanup": {
130130
"type": "boolean",
131-
"description": "Automatically cleanup after publish"
131+
"description": "When enabled (default: true), automatically cleans up old prerelease tags when merging to main or when a PR is abandoned"
132132
},
133133
"AutoPatching": {
134134
"type": "boolean",
@@ -177,6 +177,15 @@
177177
"UsePRTitleAsNotesHeading": {
178178
"type": "boolean",
179179
"description": "Add pull request title as H1 heading in release notes"
180+
},
181+
"ReleaseType": {
182+
"type": "string",
183+
"enum": [
184+
"Release",
185+
"Prerelease",
186+
"None"
187+
],
188+
"description": "The type of release to create: Release (stable), Prerelease, or None."
180189
}
181190
}
182191
}
@@ -332,11 +341,6 @@
332341
"type": "boolean",
333342
"description": "Publish the module"
334343
},
335-
"ReleaseType": {
336-
"type": "string",
337-
"enum": ["Release", "Prerelease", "Cleanup", "None"],
338-
"description": "The type of release to create: Release (stable), Prerelease, Cleanup (delete old prereleases), or None"
339-
},
340344
"BuildDocs": {
341345
"type": "boolean",
342346
"description": "Build documentation"

‎scripts/main.ps1‎

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -224,25 +224,17 @@ LogGroup 'Calculate Job Run Conditions:' {
224224
$isMergedPR = $isPR -and $pullRequestAction -eq 'closed' -and $pullRequestIsMerged -eq $true
225225
$isNotAbandonedPR = -not $isAbandonedPR
226226

227-
# Check if a prerelease label was added or exists on the PR
227+
# Check if a prerelease label exists on the PR
228228
$prereleaseLabels = $settings.Publish.Module.PrereleaseLabels -split ',' | ForEach-Object { $_.Trim() }
229229
$prLabels = @($pullRequest.labels.name)
230230
$hasPrereleaseLabel = ($prLabels | Where-Object { $prereleaseLabels -contains $_ }).Count -gt 0
231-
$labelName = $eventData.Label.name
232-
$isPrereleaseLabeled = $pullRequestAction -eq 'labeled' -and ($prereleaseLabels -contains $labelName)
233-
$shouldPrerelease = $isPR -and (($isOpenOrUpdatedPR -and $hasPrereleaseLabel) -or $isPrereleaseLabeled)
234-
235-
# Determine ReleaseType - single source of truth for what Publish-PSModule should do
236-
# Values: 'Release', 'Prerelease', 'Cleanup', 'None'
237-
# Release only happens when PR is merged into the default branch
238-
$releaseType = if (-not $isPR) {
239-
'None'
240-
} elseif ($isMergedPR -and $isTargetDefaultBranch) {
231+
$isOpenOrLabeledPR = $isPR -and $pullRequestAction -in @('opened', 'reopened', 'synchronize', 'labeled')
232+
$shouldPrerelease = $isOpenOrLabeledPR -and $hasPrereleaseLabel
233+
234+
# Determine ReleaseType - what type of release to create
235+
# Values: 'Release', 'Prerelease', 'None'
236+
$releaseType = if ($isMergedPR -and $isTargetDefaultBranch) {
241237
'Release'
242-
} elseif ($isMergedPR -and -not $isTargetDefaultBranch) {
243-
'None' # Merged to non-default branch - no release
244-
} elseif ($isAbandonedPR) {
245-
'Cleanup'
246238
} elseif ($shouldPrerelease) {
247239
'Prerelease'
248240
} else {
@@ -252,10 +244,12 @@ LogGroup 'Calculate Job Run Conditions:' {
252244
[pscustomobject]@{
253245
isPR = $isPR
254246
isOpenOrUpdatedPR = $isOpenOrUpdatedPR
247+
isOpenOrLabeledPR = $isOpenOrLabeledPR
255248
isAbandonedPR = $isAbandonedPR
256249
isMergedPR = $isMergedPR
257250
isNotAbandonedPR = $isNotAbandonedPR
258251
isTargetDefaultBranch = $isTargetDefaultBranch
252+
hasPrereleaseLabel = $hasPrereleaseLabel
259253
shouldPrerelease = $shouldPrerelease
260254
ReleaseType = $releaseType
261255
} | Format-List | Out-String
@@ -431,6 +425,14 @@ if ($settings.Test.Skip) {
431425

432426
# Calculate job-specific conditions and add to settings
433427
LogGroup 'Calculate Job Run Conditions:' {
428+
# Calculate if prereleases should be cleaned up:
429+
# True if (Release or Abandoned PR) AND user has AutoCleanup enabled (defaults to true)
430+
$shouldAutoCleanup = (($releaseType -eq 'Release') -or $isAbandonedPR) -and ($settings.Publish.Module.AutoCleanup -eq $true)
431+
432+
# Update Publish.Module with computed release values
433+
$settings.Publish.Module | Add-Member -MemberType NoteProperty -Name ReleaseType -Value $releaseType -Force
434+
$settings.Publish.Module.AutoCleanup = $shouldAutoCleanup
435+
434436
# Create Run object with all job-specific conditions
435437
$run = [pscustomobject]@{
436438
LintRepository = $isOpenOrUpdatedPR -and (-not $settings.Linter.Skip)
@@ -447,8 +449,7 @@ LogGroup 'Calculate Job Run Conditions:' {
447449
GetCodeCoverage = $isNotAbandonedPR -and (-not $settings.Test.CodeCoverage.Skip) -and (
448450
($null -ne $settings.TestSuites.PSModule) -or ($null -ne $settings.TestSuites.Module)
449451
)
450-
PublishModule = $releaseType -ne 'None'
451-
ReleaseType = $releaseType # 'Release', 'Prerelease', 'Cleanup', or 'None'
452+
PublishModule = ($releaseType -ne 'None') -or $shouldAutoCleanup
452453
BuildDocs = $isNotAbandonedPR -and (-not $settings.Build.Docs.Skip)
453454
BuildSite = $isNotAbandonedPR -and (-not $settings.Build.Site.Skip)
454455
PublishSite = $isMergedPR -and $isTargetDefaultBranch

‎tests/scenarios/invalid-percent-target/PSModule.yml‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@ Test:
1010
CodeCoverage:
1111
PercentTarget: 101
1212
Publish:
13-
AutoCleanup: false
13+
Module:
14+
AutoCleanup: false
1415
Linter:
1516
env:
1617
VALIDATE_BIOME_FORMAT: false

‎tests/scenarios/valid/PSModule.yml‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@ Test:
1010
CodeCoverage:
1111
PercentTarget: 1
1212
Publish:
13-
AutoCleanup: false
13+
Module:
14+
AutoCleanup: false
1415
Linter:
1516
env:
1617
VALIDATE_BIOME_FORMAT: false

0 commit comments

Comments
 (0)