diff --git a/scripts/Settings.schema.json b/scripts/Settings.schema.json index d35a11e..898b5d3 100644 --- a/scripts/Settings.schema.json +++ b/scripts/Settings.schema.json @@ -128,7 +128,7 @@ }, "AutoCleanup": { "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", @@ -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." } } } @@ -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" diff --git a/scripts/main.ps1 b/scripts/main.ps1 index 1b04145..c7bbdb7 100644 --- a/scripts/main.ps1 +++ b/scripts/main.ps1 @@ -224,25 +224,17 @@ LogGroup 'Calculate Job Run Conditions:' { $isMergedPR = $isPR -and $pullRequestAction -eq 'closed' -and $pullRequestIsMerged -eq $true $isNotAbandonedPR = -not $isAbandonedPR - # Check if a prerelease label was added or exists on the PR + # Check if a prerelease label exists on the PR $prereleaseLabels = $settings.Publish.Module.PrereleaseLabels -split ',' | ForEach-Object { $_.Trim() } $prLabels = @($pullRequest.labels.name) $hasPrereleaseLabel = ($prLabels | Where-Object { $prereleaseLabels -contains $_ }).Count -gt 0 - $labelName = $eventData.Label.name - $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) { + $isOpenOrLabeledPR = $isPR -and $pullRequestAction -in @('opened', 'reopened', 'synchronize', 'labeled') + $shouldPrerelease = $isOpenOrLabeledPR -and $hasPrereleaseLabel + + # Determine ReleaseType - what type of release to create + # Values: 'Release', 'Prerelease', 'None' + $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 { @@ -252,10 +244,12 @@ LogGroup 'Calculate Job Run Conditions:' { [pscustomobject]@{ isPR = $isPR isOpenOrUpdatedPR = $isOpenOrUpdatedPR + isOpenOrLabeledPR = $isOpenOrLabeledPR isAbandonedPR = $isAbandonedPR isMergedPR = $isMergedPR isNotAbandonedPR = $isNotAbandonedPR isTargetDefaultBranch = $isTargetDefaultBranch + hasPrereleaseLabel = $hasPrereleaseLabel shouldPrerelease = $shouldPrerelease ReleaseType = $releaseType } | Format-List | Out-String @@ -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 AutoCleanup enabled (defaults to true) + $shouldAutoCleanup = (($releaseType -eq 'Release') -or $isAbandonedPR) -and ($settings.Publish.Module.AutoCleanup -eq $true) + + # Update Publish.Module with computed release values + $settings.Publish.Module | Add-Member -MemberType NoteProperty -Name ReleaseType -Value $releaseType -Force + $settings.Publish.Module.AutoCleanup = $shouldAutoCleanup + # Create Run object with all job-specific conditions $run = [pscustomobject]@{ LintRepository = $isOpenOrUpdatedPR -and (-not $settings.Linter.Skip) @@ -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 $shouldAutoCleanup BuildDocs = $isNotAbandonedPR -and (-not $settings.Build.Docs.Skip) BuildSite = $isNotAbandonedPR -and (-not $settings.Build.Site.Skip) PublishSite = $isMergedPR -and $isTargetDefaultBranch diff --git a/tests/scenarios/invalid-percent-target/PSModule.yml b/tests/scenarios/invalid-percent-target/PSModule.yml index 3349481..e60825a 100644 --- a/tests/scenarios/invalid-percent-target/PSModule.yml +++ b/tests/scenarios/invalid-percent-target/PSModule.yml @@ -10,7 +10,8 @@ Test: CodeCoverage: PercentTarget: 101 Publish: - AutoCleanup: false + Module: + AutoCleanup: false Linter: env: VALIDATE_BIOME_FORMAT: false diff --git a/tests/scenarios/valid/PSModule.yml b/tests/scenarios/valid/PSModule.yml index ceaf2ff..4ecb911 100644 --- a/tests/scenarios/valid/PSModule.yml +++ b/tests/scenarios/valid/PSModule.yml @@ -10,7 +10,8 @@ Test: CodeCoverage: PercentTarget: 1 Publish: - AutoCleanup: false + Module: + AutoCleanup: false Linter: env: VALIDATE_BIOME_FORMAT: false