Skip to content

Commit 7c9c451

Browse files
Decouple prerelease cleanup from publish artifact
Run prerelease cleanup independently when no module artifact is produced by gating publish-only steps behind CreateRelease and driving cleanup behavior from ReleaseType. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
1 parent 317bcb1 commit 7c9c451

3 files changed

Lines changed: 15 additions & 5 deletions

File tree

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

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,17 @@ 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. Required only when CreateRelease is true.
1111
required: false
1212
default: outputs/module
13+
CreateRelease:
14+
description: When true, downloads the module artifact and runs publish.ps1 (PowerShell Gallery + GitHub Release flow).
15+
required: false
16+
default: 'false'
17+
ReleaseType:
18+
description: Resolved release type from settings (Release, Prerelease, None). Used to control prerelease cleanup behavior.
19+
required: false
20+
default: None
1321
APIKey:
1422
description: PowerShell Gallery API Key.
1523
required: true
@@ -54,12 +62,14 @@ runs:
5462
Install-PSResource -Name Microsoft.PowerShell.PSResourceGet -Repository PSGallery -TrustRepository
5563
5664
- name: Download module artifact
65+
if: inputs.CreateRelease == 'true'
5766
uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v8.0.1
5867
with:
5968
name: ${{ inputs.ArtifactName }}
6069
path: ${{ inputs.ModulePath }}
6170

6271
- name: Publish Module
72+
if: inputs.CreateRelease == 'true'
6373
shell: pwsh
6474
working-directory: ${{ inputs.WorkingDirectory }}
6575
env:
@@ -73,7 +83,7 @@ runs:
7383
run: ${{ github.action_path }}/src/publish.ps1
7484

7585
- name: Cleanup Prereleases
76-
if: env.PSMODULE_PUBLISH_PSMODULE_CONTEXT_IsPrerelease != 'true' && (inputs.AutoCleanup == 'true' || inputs.WhatIf == 'true')
86+
if: inputs.ReleaseType != 'Prerelease' && (inputs.AutoCleanup == 'true' || inputs.WhatIf == 'true')
7787
shell: pwsh
7888
working-directory: ${{ inputs.WorkingDirectory }}
7989
env:

.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: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,8 @@ jobs:
4444
with:
4545
Name: ${{ fromJson(inputs.Settings).Name }}
4646
ModulePath: outputs/module
47+
CreateRelease: ${{ fromJson(inputs.Settings).Module.CreateRelease }}
48+
ReleaseType: ${{ fromJson(inputs.Settings).Module.ReleaseType }}
4749
APIKey: ${{ secrets.APIKey }}
4850
WhatIf: ${{ github.repository == 'PSModule/Process-PSModule' }}
4951
AutoCleanup: ${{ fromJson(inputs.Settings).Publish.Module.AutoCleanup }}

0 commit comments

Comments
 (0)