Skip to content

Commit 0307c0d

Browse files
🩹 [Patch]: Prerelease cleanup no longer depends on module artifact (#400)
Prerelease cleanup now runs as an independent workflow action, so publish logic and cleanup logic can execute in the right scenarios without being coupled to module artifact download. ## Changed: Publish and cleanup are now separate actions `Publish-PSModule` now only performs artifact download and publish/release work, while cleanup moved into a dedicated `Cleanup-PSModulePrereleases` action. ## Fixed: No-build cleanup paths no longer depend on publish action internals `Publish-Module.yml` now runs publish only when `ReleaseType != 'None'`, and runs cleanup independently when `ReleaseType != 'Prerelease'` with existing AutoCleanup and WhatIf controls. ## Technical Details - Removed cleanup inputs and cleanup step from `.github/actions/Publish-PSModule/action.yml`. - Added `.github/actions/Cleanup-PSModulePrereleases/` with its own composite action and cleanup script. - Updated `.github/workflows/Publish-Module.yml` to call the two actions as separate, scenario-gated steps. - Preserved release-tag exclusion by passing `PSMODULE_PUBLISH_PSMODULE_CONTEXT_ReleaseTag` into the cleanup action when publish ran earlier in the job. - Implementation plan progress: completed the decoupling requested in issue #376 by separating cleanup from publish artifact flow. <details> <summary>Related issues</summary> - Fixes #376 </details> --------- Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
1 parent 5998e39 commit 0307c0d

5 files changed

Lines changed: 49 additions & 22 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 & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -7,16 +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. A module artifact must exist before invoking this action.
10+
description: Path to the folder containing the <Name>/ module subdirectory from Build-PSModule.
1111
required: false
1212
default: outputs/module
1313
APIKey:
1414
description: PowerShell Gallery API Key.
1515
required: true
16-
AutoCleanup:
17-
description: Control whether to automatically delete the prerelease tags after the stable release is created.
18-
required: false
19-
default: 'true'
2016
WhatIf:
2117
description: If specified, the action will only log the changes it would make, but will not actually create or delete any releases or tags.
2218
required: false
@@ -71,14 +67,3 @@ runs:
7167
PSMODULE_PUBLISH_PSMODULE_INPUT_UsePRTitleAsReleaseName: ${{ inputs.UsePRTitleAsReleaseName }}
7268
PSMODULE_PUBLISH_PSMODULE_INPUT_UsePRTitleAsNotesHeading: ${{ inputs.UsePRTitleAsNotesHeading }}
7369
run: ${{ github.action_path }}/src/publish.ps1
74-
75-
- name: Cleanup Prereleases
76-
if: env.PSMODULE_PUBLISH_PSMODULE_CONTEXT_IsPrerelease != 'true' && (inputs.AutoCleanup == 'true' || inputs.WhatIf == 'true')
77-
shell: pwsh
78-
working-directory: ${{ inputs.WorkingDirectory }}
79-
env:
80-
PSMODULE_PUBLISH_PSMODULE_INPUT_WhatIf: ${{ inputs.WhatIf }}
81-
PSMODULE_PUBLISH_PSMODULE_CONTEXT_ReleaseTag: ${{ env.PSMODULE_PUBLISH_PSMODULE_CONTEXT_ReleaseTag }}
82-
run: |
83-
# Cleanup prerelease tags
84-
${{ github.action_path }}/src/cleanup.ps1

‎.github/actions/Publish-PSModule/src/publish.ps1‎

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -140,9 +140,7 @@ LogGroup 'Resolve version from manifest' {
140140
PRHeadRef = $prHeadRef
141141
} | Format-List | Out-String
142142

143-
# Expose publish context to subsequent steps so the cleanup step can gate on release type.
144-
$envLine = "PSMODULE_PUBLISH_PSMODULE_CONTEXT_IsPrerelease=$($createPrerelease.ToString().ToLower())"
145-
$envLine | Out-File -Path $env:GITHUB_ENV -Append -Encoding utf8NoBOM
143+
# Expose release tag to subsequent steps so cleanup can exclude the just-published tag.
146144
"PSMODULE_PUBLISH_PSMODULE_CONTEXT_ReleaseTag=$releaseTag" | Out-File -Path $env:GITHUB_ENV -Append -Encoding utf8NoBOM
147145
}
148146
#endregion Resolve version from manifest

‎.github/workflows/Publish-Module.yml‎

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ jobs:
3838
persist-credentials: false
3939

4040
- name: Publish module
41+
if: fromJson(inputs.Settings).Publish.Module.Resolution.ReleaseType != 'None'
4142
uses: ./_wf/.github/actions/Publish-PSModule
4243
env:
4344
GH_TOKEN: ${{ github.token }}
@@ -46,8 +47,17 @@ jobs:
4647
ModulePath: outputs/module
4748
APIKey: ${{ secrets.APIKey }}
4849
WhatIf: ${{ github.repository == 'PSModule/Process-PSModule' }}
49-
AutoCleanup: ${{ fromJson(inputs.Settings).Publish.Module.AutoCleanup }}
5050
UsePRTitleAsReleaseName: ${{ fromJson(inputs.Settings).Publish.Module.UsePRTitleAsReleaseName }}
5151
UsePRBodyAsReleaseNotes: ${{ fromJson(inputs.Settings).Publish.Module.UsePRBodyAsReleaseNotes }}
5252
UsePRTitleAsNotesHeading: ${{ fromJson(inputs.Settings).Publish.Module.UsePRTitleAsNotesHeading }}
5353
WorkingDirectory: ${{ fromJson(inputs.Settings).WorkingDirectory }}
54+
55+
- name: Cleanup prereleases
56+
if: fromJson(inputs.Settings).Publish.Module.Resolution.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)