Skip to content

Commit e1b338d

Browse files
🚀 [Feature]: Add ReleaseType input for explicit release control (#59)
The action now supports explicit control over the release type through the new `ReleaseType` input parameter. You can specify whether to create a stable release, prerelease, or skip releasing entirely—without relying on automatic detection from PR state and labels. The workflow has also been restructured into three phases (initialization, publishing, cleanup) that run conditionally, improving efficiency when only cleanup is needed. - Part of PSModule/Process-PSModule#73 - Part of PSModule/Process-PSModule#265 ## New ReleaseType input parameter A new `ReleaseType` input allows you to explicitly control the release behavior: | Value | Description | |-------|-------------| | `Release` | Create a stable release (default) | | `Prerelease` | Create a prerelease | | `None` | Do not create any release | This input is designed to work with `Get-PSModuleSettings`, which pre-calculates the appropriate release type based on your workflow context: ```yaml - uses: PSModule/Publish-PSModule@v2 with: APIKey: ${{ secrets.PSGALLERY_API_KEY }} ReleaseType: ${{ fromJson(inputs.Settings).Publish.Module.ReleaseType }} AutoCleanup: ${{ fromJson(inputs.Settings).Publish.Module.AutoCleanup }} ``` ## Restructured workflow execution The action now runs in three separate phases, each executing only when needed: 1. **Initialize Publish Context** (`init.ps1`) – Calculates version, validates inputs, and stores context in environment variables 2. **Publish Module** (`publish.ps1`) – Downloads artifact, updates manifest, publishes to PSGallery, and creates GitHub release (runs only when `ShouldPublish` is true) 3. **Cleanup Prereleases** (`cleanup.ps1`) – Deletes old prerelease tags (runs only when `ShouldCleanup` is true) This separation means the action skips unnecessary steps. For example, when a PR is closed without merging, the workflow can run cleanup independently without downloading artifacts or attempting to publish. ## Backward compatibility The `ReleaseType` parameter defaults to `Release`, maintaining current behavior for merged PRs targeting the default branch. Existing workflows continue to work without modification. --------- Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
1 parent ebbfeec commit e1b338d

7 files changed

Lines changed: 665 additions & 520 deletions

File tree

.github/workflows/Action-Test.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,12 @@ jobs:
2626
with:
2727
persist-credentials: false
2828

29+
- name: Upload module artifact
30+
uses: actions/upload-artifact@b7c566a772e6b6bfb58ed0dc250532a479d7789f # v6.0.0
31+
with:
32+
name: module
33+
path: tests/outputs/module
34+
2935
- name: Action-Test
3036
uses: ./
3137
env:

action.yml

Lines changed: 41 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,11 @@ inputs:
1414
description: PowerShell Gallery API Key.
1515
required: true
1616
AutoCleanup:
17-
description: Control wether to automatically delete the prerelease tags after the stable release is created.
17+
description: Control whether to automatically delete the prerelease tags after the stable release is created.
1818
required: false
1919
default: 'true'
2020
AutoPatching:
21-
description: Control wether to automatically handle patches. If disabled, the action will only create a patch release if the pull request has a 'patch' label.
21+
description: Control whether to automatically handle patches. If disabled, the action will only create a patch release if the pull request has a 'patch' label.
2222
required: false
2323
default: 'true'
2424
IncrementalPrerelease:
@@ -49,6 +49,10 @@ inputs:
4949
description: A comma separated list of labels that do not trigger a release.
5050
required: false
5151
default: NoRelease
52+
ReleaseType:
53+
description: The type of release to create. Values are 'Release' (stable), 'Prerelease', or 'None'.
54+
required: false
55+
default: Release
5256
WhatIf:
5357
description: If specified, the action will only log the changes it would make, but will not actually create or delete any releases or tags.
5458
required: false
@@ -76,24 +80,55 @@ runs:
7680
- name: Install-PSModuleHelpers
7781
uses: PSModule/Install-PSModuleHelpers@d60d63e4be477d1ca0c67c6085101fb109bce8f1 # v1.0.6
7882

79-
- name: Run Publish-PSModule
83+
- name: Update Microsoft.PowerShell.PSResourceGet
84+
shell: pwsh
85+
run: |
86+
Install-PSResource -Name Microsoft.PowerShell.PSResourceGet -Repository PSGallery -TrustRepository
87+
88+
- name: Initialize Publish Context
89+
id: init
8090
shell: pwsh
8191
working-directory: ${{ inputs.WorkingDirectory }}
8292
env:
8393
PSMODULE_PUBLISH_PSMODULE_INPUT_Name: ${{ inputs.Name }}
84-
PSMODULE_PUBLISH_PSMODULE_INPUT_ModulePath: ${{ inputs.ModulePath }}
85-
PSMODULE_PUBLISH_PSMODULE_INPUT_APIKey: ${{ inputs.APIKey }}
8694
PSMODULE_PUBLISH_PSMODULE_INPUT_AutoCleanup: ${{ inputs.AutoCleanup }}
8795
PSMODULE_PUBLISH_PSMODULE_INPUT_AutoPatching: ${{ inputs.AutoPatching }}
8896
PSMODULE_PUBLISH_PSMODULE_INPUT_DatePrereleaseFormat: ${{ inputs.DatePrereleaseFormat }}
8997
PSMODULE_PUBLISH_PSMODULE_INPUT_IgnoreLabels: ${{ inputs.IgnoreLabels }}
98+
PSMODULE_PUBLISH_PSMODULE_INPUT_ReleaseType: ${{ inputs.ReleaseType }}
9099
PSMODULE_PUBLISH_PSMODULE_INPUT_IncrementalPrerelease: ${{ inputs.IncrementalPrerelease }}
91100
PSMODULE_PUBLISH_PSMODULE_INPUT_MajorLabels: ${{ inputs.MajorLabels }}
92101
PSMODULE_PUBLISH_PSMODULE_INPUT_MinorLabels: ${{ inputs.MinorLabels }}
93102
PSMODULE_PUBLISH_PSMODULE_INPUT_PatchLabels: ${{ inputs.PatchLabels }}
94103
PSMODULE_PUBLISH_PSMODULE_INPUT_VersionPrefix: ${{ inputs.VersionPrefix }}
95104
PSMODULE_PUBLISH_PSMODULE_INPUT_WhatIf: ${{ inputs.WhatIf }}
105+
run: ${{ github.action_path }}/scripts/init.ps1
106+
107+
- name: Download module artifact
108+
if: env.PUBLISH_CONTEXT_ShouldPublish == 'true' || inputs.WhatIf == 'true'
109+
uses: actions/download-artifact@37930b1c2abaa49bbe596cd826c3c89aef350131 # v7.0.0
110+
with:
111+
name: module
112+
path: ${{ inputs.ModulePath }}
113+
114+
- name: Publish Module
115+
if: env.PUBLISH_CONTEXT_ShouldPublish == 'true' || inputs.WhatIf == 'true'
116+
shell: pwsh
117+
working-directory: ${{ inputs.WorkingDirectory }}
118+
env:
119+
PSMODULE_PUBLISH_PSMODULE_INPUT_Name: ${{ inputs.Name }}
120+
PSMODULE_PUBLISH_PSMODULE_INPUT_ModulePath: ${{ inputs.ModulePath }}
121+
PSMODULE_PUBLISH_PSMODULE_INPUT_APIKey: ${{ inputs.APIKey }}
122+
PSMODULE_PUBLISH_PSMODULE_INPUT_WhatIf: ${{ inputs.WhatIf }}
96123
PSMODULE_PUBLISH_PSMODULE_INPUT_UsePRBodyAsReleaseNotes: ${{ inputs.UsePRBodyAsReleaseNotes }}
97124
PSMODULE_PUBLISH_PSMODULE_INPUT_UsePRTitleAsReleaseName: ${{ inputs.UsePRTitleAsReleaseName }}
98125
PSMODULE_PUBLISH_PSMODULE_INPUT_UsePRTitleAsNotesHeading: ${{ inputs.UsePRTitleAsNotesHeading }}
99-
run: ${{ github.action_path }}/scripts/main.ps1
126+
run: ${{ github.action_path }}/scripts/publish.ps1
127+
128+
- name: Cleanup Prereleases
129+
if: env.PUBLISH_CONTEXT_ShouldCleanup == 'true' || inputs.WhatIf == 'true'
130+
shell: pwsh
131+
working-directory: ${{ inputs.WorkingDirectory }}
132+
env:
133+
PSMODULE_PUBLISH_PSMODULE_INPUT_WhatIf: ${{ inputs.WhatIf }}
134+
run: ${{ github.action_path }}/scripts/cleanup.ps1

scripts/cleanup.ps1

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
[CmdletBinding()]
2+
param()
3+
4+
Import-Module -Name 'Helpers' -Force
5+
6+
$prereleaseName = $env:PUBLISH_CONTEXT_PrereleaseName
7+
$prereleaseTagsToCleanup = $env:PUBLISH_CONTEXT_PrereleaseTagsToCleanup
8+
$whatIf = $env:PSMODULE_PUBLISH_PSMODULE_INPUT_WhatIf -eq 'true'
9+
10+
if ([string]::IsNullOrWhiteSpace($prereleaseName)) {
11+
Write-Error 'PUBLISH_CONTEXT_PrereleaseName is not set. Run init.ps1 first.'
12+
exit 1
13+
}
14+
15+
LogGroup "Cleanup prereleases for [$prereleaseName]" {
16+
if ([string]::IsNullOrWhiteSpace($prereleaseTagsToCleanup)) {
17+
Write-Output "No prereleases found to cleanup for [$prereleaseName]."
18+
return
19+
}
20+
21+
$tagsToDelete = $prereleaseTagsToCleanup -split ',' | Where-Object { -not [string]::IsNullOrWhiteSpace($_) }
22+
23+
if ($tagsToDelete.Count -eq 0) {
24+
Write-Output "No prereleases found to cleanup for [$prereleaseName]."
25+
return
26+
}
27+
28+
Write-Output "Found $($tagsToDelete.Count) prereleases to cleanup:"
29+
$tagsToDelete | ForEach-Object { Write-Output " - $_" }
30+
Write-Output ''
31+
32+
foreach ($tag in $tagsToDelete) {
33+
Write-Output "Deleting prerelease: [$tag]"
34+
if ($whatIf) {
35+
Write-Output "WhatIf: gh release delete $tag --cleanup-tag --yes"
36+
} else {
37+
gh release delete $tag --cleanup-tag --yes
38+
if ($LASTEXITCODE -ne 0) {
39+
Write-Error "Failed to delete release [$tag]."
40+
exit $LASTEXITCODE
41+
}
42+
Write-Output "Successfully deleted release [$tag]."
43+
}
44+
}
45+
46+
Write-Host "::notice::Cleaned up $($tagsToDelete.Count) prerelease(s) for [$prereleaseName]."
47+
}

0 commit comments

Comments
 (0)