Skip to content
Merged
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
16 changes: 10 additions & 6 deletions scripts/Settings.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
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
35 changes: 18 additions & 17 deletions scripts/main.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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
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 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)
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 $shouldAutoCleanup
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:
AutoCleanup: 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:
AutoCleanup: false
Linter:
env:
VALIDATE_BIOME_FORMAT: false
Expand Down
Loading