Skip to content

Commit 3b93ae6

Browse files
🚀 [Feature]: Add PrereleaseLabels support and ReleaseType calculation (#6)
The workflow now supports configurable prerelease labels and introduces `ReleaseType` as a single source of truth for determining what action the publish workflow should take. Previously, the `prerelease` label check was hardcoded while all other labels were configurable, and adding a prerelease label to a PR did not trigger the publish workflow. ## PrereleaseLabels Configuration You can now customize which labels trigger a prerelease build via the `PSModule.yml` settings file: ```yaml Publish: Module: PrereleaseLabels: prerelease, beta, alpha ``` The default value is `prerelease`, maintaining backward compatibility. ## ReleaseType - Single Source of Truth A new `ReleaseType` property is now calculated and included in the `Run` object with these values: | Value | Trigger | Action | |-------|---------|--------| | `Release` | PR merged to default branch | Create stable release | | `Prerelease` | PR has prerelease label OR prerelease label just added | Create prerelease | | `Cleanup` | PR closed without merge (abandoned) | Delete old prereleases | | `None` | Any other scenario | Skip publishing | This simplifies the publish logic and makes debugging easier since `ReleaseType` is visible in the Get-Settings logs. ## Changes - Added `PrereleaseLabels` setting with default value `prerelease` - Added detection for when a prerelease label is added via the `labeled` action - Introduced `ReleaseType` calculation as the single source of truth - Updated `PublishModule` condition to use `$releaseType -ne 'None'` - Added `ReleaseType` to the `Run` object for downstream consumption - Updated JSON schema with `PrereleaseLabels` and `ReleaseType` definitions
1 parent ce4aac7 commit 3b93ae6

File tree

2 files changed

+36
-1
lines changed

2 files changed

+36
-1
lines changed

‎scripts/Settings.schema.json‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,10 @@
162162
"type": "string",
163163
"description": "Comma-separated labels that prevent release"
164164
},
165+
"PrereleaseLabels": {
166+
"type": "string",
167+
"description": "Comma-separated labels that trigger a prerelease"
168+
},
165169
"UsePRTitleAsReleaseName": {
166170
"type": "boolean",
167171
"description": "Use pull request title as the GitHub release name"
@@ -328,6 +332,11 @@
328332
"type": "boolean",
329333
"description": "Publish the module"
330334
},
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+
},
331340
"BuildDocs": {
332341
"type": "boolean",
333342
"description": "Build documentation"

‎scripts/main.ps1‎

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,7 @@ $settings = [pscustomobject]@{
172172
MinorLabels = $settings.Publish.Module.MinorLabels ?? 'minor, feature'
173173
PatchLabels = $settings.Publish.Module.PatchLabels ?? 'patch, fix'
174174
IgnoreLabels = $settings.Publish.Module.IgnoreLabels ?? 'NoRelease'
175+
PrereleaseLabels = $settings.Publish.Module.PrereleaseLabels ?? 'prerelease'
175176
UsePRTitleAsReleaseName = $settings.Publish.Module.UsePRTitleAsReleaseName ?? $false
176177
UsePRBodyAsReleaseNotes = $settings.Publish.Module.UsePRBodyAsReleaseNotes ?? $true
177178
UsePRTitleAsNotesHeading = $settings.Publish.Module.UsePRTitleAsNotesHeading ?? $true
@@ -243,12 +244,36 @@ LogGroup 'Calculate Job Run Conditions:' {
243244
$isMergedPR = $isPR -and $pullRequestAction -eq 'closed' -and $pullRequestIsMerged -eq $true
244245
$isNotAbandonedPR = -not $isAbandonedPR
245246

247+
# Check if a prerelease label was added or exists on the PR
248+
$prereleaseLabels = $settings.Publish.Module.PrereleaseLabels -split ',' | ForEach-Object { $_.Trim() }
249+
$prLabels = @($pullRequest.labels.name)
250+
$hasPrereleaseLabel = ($prLabels | Where-Object { $prereleaseLabels -contains $_ }).Count -gt 0
251+
$labelName = $eventData.Label.name
252+
$isPrereleaseLabeled = $pullRequestAction -eq 'labeled' -and ($prereleaseLabels -contains $labelName)
253+
$shouldPrerelease = $isPR -and (($isOpenOrUpdatedPR -and $hasPrereleaseLabel) -or $isPrereleaseLabeled)
254+
255+
# Determine ReleaseType - single source of truth for what Publish-PSModule should do
256+
# Values: 'Release', 'Prerelease', 'Cleanup', 'None'
257+
$releaseType = if (-not $isPR) {
258+
'None'
259+
} elseif ($isMergedPR) {
260+
'Release'
261+
} elseif ($isAbandonedPR) {
262+
'Cleanup'
263+
} elseif ($shouldPrerelease) {
264+
'Prerelease'
265+
} else {
266+
'None'
267+
}
268+
246269
[pscustomobject]@{
247270
isPR = $isPR
248271
isOpenOrUpdatedPR = $isOpenOrUpdatedPR
249272
isAbandonedPR = $isAbandonedPR
250273
isMergedPR = $isMergedPR
251274
isNotAbandonedPR = $isNotAbandonedPR
275+
shouldPrerelease = $shouldPrerelease
276+
ReleaseType = $releaseType
252277
} | Format-List | Out-String
253278
}
254279

@@ -438,7 +463,8 @@ LogGroup 'Calculate Job Run Conditions:' {
438463
GetCodeCoverage = $isNotAbandonedPR -and (-not $settings.Test.CodeCoverage.Skip) -and (
439464
($null -ne $settings.TestSuites.PSModule) -or ($null -ne $settings.TestSuites.Module)
440465
)
441-
PublishModule = $isPR -and ($isAbandonedPR -or ($isOpenOrUpdatedPR -or $isMergedPR))
466+
PublishModule = $releaseType -ne 'None'
467+
ReleaseType = $releaseType # 'Release', 'Prerelease', 'Cleanup', or 'None'
442468
BuildDocs = $isNotAbandonedPR -and (-not $settings.Build.Docs.Skip)
443469
BuildSite = $isNotAbandonedPR -and (-not $settings.Build.Site.Skip)
444470
PublishSite = $isMergedPR

0 commit comments

Comments
 (0)