Skip to content

Commit 3da88df

Browse files
Split prerelease cleanup into dedicated action
Extract prerelease cleanup from Publish-PSModule into Cleanup-PSModulePrereleases and wire Publish-Module workflow to run publish and cleanup as separate scenario-gated steps. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
1 parent e37c855 commit 3da88df

4 files changed

Lines changed: 48 additions & 26 deletions

File tree

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
name: Cleanup-PSModulePrereleases
2+
description: Cleanup prerelease GitHub releases associated with the current pull request branch.
3+
author: PSModule
4+
5+
inputs:
6+
AutoCleanup:
7+
description: Control whether to automatically delete prerelease tags.
8+
required: false
9+
default: 'true'
10+
WhatIf:
11+
description: If specified, the action will only log the changes it would make.
12+
required: false
13+
default: 'false'
14+
WorkingDirectory:
15+
description: The working directory where the script will run from.
16+
required: false
17+
default: '.'
18+
19+
runs:
20+
using: composite
21+
steps:
22+
- name: Install-PSModule
23+
uses: ./_wf/.github/actions/Install-PSModule
24+
25+
- name: Cleanup Prereleases
26+
if: inputs.AutoCleanup == 'true' || inputs.WhatIf == 'true'
27+
shell: pwsh
28+
working-directory: ${{ inputs.WorkingDirectory }}
29+
env:
30+
PSMODULE_CLEANUP_PSMODULEPRERELEASES_INPUT_WhatIf: ${{ inputs.WhatIf }}
31+
PSMODULE_CLEANUP_PSMODULEPRERELEASES_CONTEXT_ReleaseTag: ${{ env.PSMODULE_PUBLISH_PSMODULE_CONTEXT_ReleaseTag }}
32+
run: |
33+
# Cleanup prerelease tags
34+
${{ github.action_path }}/src/cleanup.ps1

.github/actions/Publish-PSModule/src/cleanup.ps1 renamed to .github/actions/Cleanup-PSModulePrereleases/src/cleanup.ps1

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ Import-Module -Name 'Helpers' -Force
77

88
#region Load inputs
99
LogGroup 'Load inputs' {
10-
$whatIf = $env:PSMODULE_PUBLISH_PSMODULE_INPUT_WhatIf -eq 'true'
10+
$whatIf = $env:PSMODULE_CLEANUP_PSMODULEPRERELEASES_INPUT_WhatIf -eq 'true'
1111

1212
$githubEventJson = Get-Content -Raw $env:GITHUB_EVENT_PATH
1313
$githubEvent = $githubEventJson | ConvertFrom-Json
@@ -27,7 +27,7 @@ LogGroup 'Load inputs' {
2727
Write-Host "Prerelease name: [$prereleaseName]"
2828
Write-Host "WhatIf: [$whatIf]"
2929

30-
$publishedReleaseTag = $env:PSMODULE_PUBLISH_PSMODULE_CONTEXT_ReleaseTag
30+
$publishedReleaseTag = $env:PSMODULE_CLEANUP_PSMODULEPRERELEASES_CONTEXT_ReleaseTag
3131
if (-not [string]::IsNullOrWhiteSpace($publishedReleaseTag)) {
3232
Write-Host "Published tag: [$publishedReleaseTag] (excluded from cleanup)"
3333
}

.github/actions/Publish-PSModule/action.yml

Lines changed: 1 addition & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -7,20 +7,12 @@ inputs:
77
description: Name of the module to publish.
88
required: false
99
ModulePath:
10-
description: Path to the folder containing the <Name>/ module subdirectory from Build-PSModule. Required only when ReleaseType is not None.
10+
description: Path to the folder containing the <Name>/ module subdirectory from Build-PSModule.
1111
required: false
1212
default: outputs/module
13-
ReleaseType:
14-
description: Resolved release type from settings (Release, Prerelease, None). Used to control prerelease cleanup behavior.
15-
required: false
16-
default: None
1713
APIKey:
1814
description: PowerShell Gallery API Key.
1915
required: true
20-
AutoCleanup:
21-
description: Control whether to automatically delete the prerelease tags after the stable release is created.
22-
required: false
23-
default: 'true'
2416
WhatIf:
2517
description: If specified, the action will only log the changes it would make, but will not actually create or delete any releases or tags.
2618
required: false
@@ -58,14 +50,12 @@ runs:
5850
Install-PSResource -Name Microsoft.PowerShell.PSResourceGet -Repository PSGallery -TrustRepository
5951
6052
- name: Download module artifact
61-
if: inputs.ReleaseType != 'None'
6253
uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v8.0.1
6354
with:
6455
name: ${{ inputs.ArtifactName }}
6556
path: ${{ inputs.ModulePath }}
6657

6758
- name: Publish Module
68-
if: inputs.ReleaseType != 'None'
6959
shell: pwsh
7060
working-directory: ${{ inputs.WorkingDirectory }}
7161
env:
@@ -77,14 +67,3 @@ runs:
7767
PSMODULE_PUBLISH_PSMODULE_INPUT_UsePRTitleAsReleaseName: ${{ inputs.UsePRTitleAsReleaseName }}
7868
PSMODULE_PUBLISH_PSMODULE_INPUT_UsePRTitleAsNotesHeading: ${{ inputs.UsePRTitleAsNotesHeading }}
7969
run: ${{ github.action_path }}/src/publish.ps1
80-
81-
- name: Cleanup Prereleases
82-
if: inputs.ReleaseType != 'Prerelease' && (inputs.AutoCleanup == 'true' || inputs.WhatIf == 'true')
83-
shell: pwsh
84-
working-directory: ${{ inputs.WorkingDirectory }}
85-
env:
86-
PSMODULE_PUBLISH_PSMODULE_INPUT_WhatIf: ${{ inputs.WhatIf }}
87-
PSMODULE_PUBLISH_PSMODULE_CONTEXT_ReleaseTag: ${{ env.PSMODULE_PUBLISH_PSMODULE_CONTEXT_ReleaseTag }}
88-
run: |
89-
# Cleanup prerelease tags
90-
${{ github.action_path }}/src/cleanup.ps1

.github/workflows/Publish-Module.yml

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,17 +38,26 @@ jobs:
3838
persist-credentials: false
3939

4040
- name: Publish module
41+
if: fromJson(inputs.Settings).Module.ReleaseType != 'None'
4142
uses: ./_wf/.github/actions/Publish-PSModule
4243
env:
4344
GH_TOKEN: ${{ github.token }}
4445
with:
4546
Name: ${{ fromJson(inputs.Settings).Name }}
4647
ModulePath: outputs/module
47-
ReleaseType: ${{ fromJson(inputs.Settings).Module.ReleaseType }}
4848
APIKey: ${{ secrets.APIKey }}
4949
WhatIf: ${{ github.repository == 'PSModule/Process-PSModule' }}
50-
AutoCleanup: ${{ fromJson(inputs.Settings).Publish.Module.AutoCleanup }}
5150
UsePRTitleAsReleaseName: ${{ fromJson(inputs.Settings).Publish.Module.UsePRTitleAsReleaseName }}
5251
UsePRBodyAsReleaseNotes: ${{ fromJson(inputs.Settings).Publish.Module.UsePRBodyAsReleaseNotes }}
5352
UsePRTitleAsNotesHeading: ${{ fromJson(inputs.Settings).Publish.Module.UsePRTitleAsNotesHeading }}
5453
WorkingDirectory: ${{ fromJson(inputs.Settings).WorkingDirectory }}
54+
55+
- name: Cleanup prereleases
56+
if: fromJson(inputs.Settings).Module.ReleaseType != 'Prerelease'
57+
uses: ./_wf/.github/actions/Cleanup-PSModulePrereleases
58+
env:
59+
GH_TOKEN: ${{ github.token }}
60+
with:
61+
WhatIf: ${{ github.repository == 'PSModule/Process-PSModule' }}
62+
AutoCleanup: ${{ fromJson(inputs.Settings).Publish.Module.AutoCleanup }}
63+
WorkingDirectory: ${{ fromJson(inputs.Settings).WorkingDirectory }}

0 commit comments

Comments
 (0)