Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 11 additions & 7 deletions scripts/Settings.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -126,9 +126,9 @@
"type": "boolean",
"description": "Skip module publish"
},
"AutoCleanup": {
"CleanupPrereleases": {
"type": "boolean",
"description": "Automatically cleanup after publish"
"description": "When enabled (default: true), automatically cleans up old prerelease tags when merging to main or when a PR is abandoned"
},
"AutoPatching": {
"type": "boolean",
Expand Down Expand Up @@ -177,6 +177,15 @@
"UsePRTitleAsNotesHeading": {
"type": "boolean",
"description": "Add pull request title as H1 heading in release notes"
},
"ReleaseType": {
"type": "string",
"enum": [
"Release",
"Prerelease",
"None"
],
"description": "The type of release to create: Release (stable), Prerelease, or None."
}
}
}
Expand Down Expand Up @@ -332,11 +341,6 @@
"type": "boolean",
"description": "Publish the module"
},
"ReleaseType": {
"type": "string",
"enum": ["Release", "Prerelease", "Cleanup", "None"],
"description": "The type of release to create: Release (stable), Prerelease, Cleanup (delete old prereleases), or None"
},
"BuildDocs": {
"type": "boolean",
"description": "Build documentation"
Expand Down
27 changes: 14 additions & 13 deletions scripts/main.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ $settings = [pscustomobject]@{
Publish = [pscustomobject]@{
Module = [pscustomobject]@{
Skip = $settings.Publish.Module.Skip ?? $false
AutoCleanup = $settings.Publish.Module.AutoCleanup ?? $true
CleanupPrereleases = $settings.Publish.Module.CleanupPrereleases ?? $true
AutoPatching = $settings.Publish.Module.AutoPatching ?? $true
IncrementalPrerelease = $settings.Publish.Module.IncrementalPrerelease ?? $true
DatePrereleaseFormat = $settings.Publish.Module.DatePrereleaseFormat ?? ''
Expand Down Expand Up @@ -232,17 +232,11 @@ LogGroup 'Calculate Job Run Conditions:' {
$isPrereleaseLabeled = $pullRequestAction -eq 'labeled' -and ($prereleaseLabels -contains $labelName)
$shouldPrerelease = $isPR -and (($isOpenOrUpdatedPR -and $hasPrereleaseLabel) -or $isPrereleaseLabeled)

# Determine ReleaseType - single source of truth for what Publish-PSModule should do
# Values: 'Release', 'Prerelease', 'Cleanup', 'None'
# Release only happens when PR is merged into the default branch
$releaseType = if (-not $isPR) {
'None'
} elseif ($isMergedPR -and $isTargetDefaultBranch) {
# Determine ReleaseType - what type of release to create
# Values: 'Release', 'Prerelease', 'None'
# Note: Cleanup is a separate decision handled by CleanupPrereleases
$releaseType = if ($isMergedPR -and $isTargetDefaultBranch) {
'Release'
} elseif ($isMergedPR -and -not $isTargetDefaultBranch) {
'None' # Merged to non-default branch - no release
} elseif ($isAbandonedPR) {
'Cleanup'
} elseif ($shouldPrerelease) {
'Prerelease'
} else {
Expand Down Expand Up @@ -431,6 +425,14 @@ if ($settings.Test.Skip) {

# Calculate job-specific conditions and add to settings
LogGroup 'Calculate Job Run Conditions:' {
# Calculate if prereleases should be cleaned up:
# True if (Release or Abandoned PR) AND user has CleanupPrereleases enabled (defaults to true)
$shouldCleanupPrereleases = (($releaseType -eq 'Release') -or $isAbandonedPR) -and ($settings.Publish.Module.CleanupPrereleases -eq $true)

# Update Publish.Module with computed release values
$settings.Publish.Module | Add-Member -MemberType NoteProperty -Name ReleaseType -Value $releaseType -Force
$settings.Publish.Module.CleanupPrereleases = $shouldCleanupPrereleases

# Create Run object with all job-specific conditions
$run = [pscustomobject]@{
LintRepository = $isOpenOrUpdatedPR -and (-not $settings.Linter.Skip)
Expand All @@ -447,8 +449,7 @@ LogGroup 'Calculate Job Run Conditions:' {
GetCodeCoverage = $isNotAbandonedPR -and (-not $settings.Test.CodeCoverage.Skip) -and (
($null -ne $settings.TestSuites.PSModule) -or ($null -ne $settings.TestSuites.Module)
)
PublishModule = $releaseType -ne 'None'
ReleaseType = $releaseType # 'Release', 'Prerelease', 'Cleanup', or 'None'
PublishModule = ($releaseType -ne 'None') -or $shouldCleanupPrereleases
BuildDocs = $isNotAbandonedPR -and (-not $settings.Build.Docs.Skip)
BuildSite = $isNotAbandonedPR -and (-not $settings.Build.Site.Skip)
PublishSite = $isMergedPR -and $isTargetDefaultBranch
Expand Down
3 changes: 2 additions & 1 deletion tests/scenarios/invalid-percent-target/PSModule.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ Test:
CodeCoverage:
PercentTarget: 101
Publish:
AutoCleanup: false
Module:
CleanupPrereleases: false
Linter:
env:
VALIDATE_BIOME_FORMAT: false
Expand Down
3 changes: 2 additions & 1 deletion tests/scenarios/valid/PSModule.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ Test:
CodeCoverage:
PercentTarget: 1
Publish:
AutoCleanup: false
Module:
CleanupPrereleases: false
Linter:
env:
VALIDATE_BIOME_FORMAT: false
Expand Down
Loading