Skip to content

Commit 37ab2dd

Browse files
Refocus Publish-PSModule on Gallery publishing
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
1 parent fb1bdb8 commit 37ab2dd

2 files changed

Lines changed: 3 additions & 135 deletions

File tree

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

Lines changed: 2 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name: Publish-PSModule
2-
description: Publish a pre-versioned PowerShell module artifact to the PowerShell Gallery and GitHub Releases.
2+
description: Publish a pre-versioned PowerShell module artifact to the PowerShell Gallery.
33
author: PSModule
44

55
inputs:
@@ -14,25 +14,13 @@ inputs:
1414
description: PowerShell Gallery API Key.
1515
required: true
1616
WhatIf:
17-
description: If specified, the action will only log the changes it would make, but will not actually create or delete any releases or tags.
17+
description: If specified, the action will only log the changes it would make, but will not publish the module.
1818
required: false
1919
default: 'false'
2020
WorkingDirectory:
2121
description: The working directory where the script will run from.
2222
required: false
2323
default: '.'
24-
UsePRTitleAsReleaseName:
25-
description: When enabled, uses the pull request title as the name for the GitHub release. If not set, the version string is used.
26-
required: false
27-
default: 'false'
28-
UsePRBodyAsReleaseNotes:
29-
description: When enabled, uses the pull request body as the release notes for the GitHub release. If not set, the release notes are auto-generated.
30-
required: false
31-
default: 'true'
32-
UsePRTitleAsNotesHeading:
33-
description: When enabled along with UsePRBodyAsReleaseNotes, the release notes will begin with the pull request title as a H1 heading followed by the pull request body. The title will reference the pull request number.
34-
required: false
35-
default: 'true'
3624
ArtifactName:
3725
description: Name of the uploaded artifact to download. Must match the name used in the upstream upload-artifact step.
3826
required: false
@@ -62,7 +50,4 @@ runs:
6250
PSMODULE_PUBLISH_PSMODULE_INPUT_ModulePath: ${{ inputs.ModulePath }}
6351
PSMODULE_PUBLISH_PSMODULE_INPUT_APIKey: ${{ inputs.APIKey }}
6452
PSMODULE_PUBLISH_PSMODULE_INPUT_WhatIf: ${{ inputs.WhatIf }}
65-
PSMODULE_PUBLISH_PSMODULE_INPUT_UsePRBodyAsReleaseNotes: ${{ inputs.UsePRBodyAsReleaseNotes }}
66-
PSMODULE_PUBLISH_PSMODULE_INPUT_UsePRTitleAsReleaseName: ${{ inputs.UsePRTitleAsReleaseName }}
67-
PSMODULE_PUBLISH_PSMODULE_INPUT_UsePRTitleAsNotesHeading: ${{ inputs.UsePRTitleAsNotesHeading }}
6853
run: ${{ github.action_path }}/src/publish.ps1

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

Lines changed: 1 addition & 118 deletions
Original file line numberDiff line numberDiff line change
@@ -2,26 +2,10 @@
22
'PSUseDeclaredVarsMoreThanAssignments', 'apiKey',
33
Justification = 'Variable is used in script blocks.'
44
)]
5-
[Diagnostics.CodeAnalysis.SuppressMessageAttribute(
6-
'PSUseDeclaredVarsMoreThanAssignments', 'usePRBodyAsReleaseNotes',
7-
Justification = 'Variable is used in script blocks.'
8-
)]
9-
[Diagnostics.CodeAnalysis.SuppressMessageAttribute(
10-
'PSUseDeclaredVarsMoreThanAssignments', 'usePRTitleAsReleaseName',
11-
Justification = 'Variable is used in script blocks.'
12-
)]
13-
[Diagnostics.CodeAnalysis.SuppressMessageAttribute(
14-
'PSUseDeclaredVarsMoreThanAssignments', 'usePRTitleAsNotesHeading',
15-
Justification = 'Variable is used in script blocks.'
16-
)]
175
[Diagnostics.CodeAnalysis.SuppressMessageAttribute(
186
'PSUseDeclaredVarsMoreThanAssignments', 'prNumber',
197
Justification = 'Variable is used in script blocks.'
208
)]
21-
[Diagnostics.CodeAnalysis.SuppressMessageAttribute(
22-
'PSUseDeclaredVarsMoreThanAssignments', 'prHeadRef',
23-
Justification = 'Variable is used in script blocks.'
24-
)]
259
[CmdletBinding()]
2610
param()
2711

@@ -55,9 +39,6 @@ LogGroup 'Load inputs' {
5539
$modulePath = Resolve-Path -Path $modulePathCandidate | Select-Object -ExpandProperty Path
5640
$apiKey = $env:PSMODULE_PUBLISH_PSMODULE_INPUT_APIKey
5741
$whatIf = $env:PSMODULE_PUBLISH_PSMODULE_INPUT_WhatIf -eq 'true'
58-
$usePRBodyAsReleaseNotes = $env:PSMODULE_PUBLISH_PSMODULE_INPUT_UsePRBodyAsReleaseNotes -eq 'true'
59-
$usePRTitleAsReleaseName = $env:PSMODULE_PUBLISH_PSMODULE_INPUT_UsePRTitleAsReleaseName -eq 'true'
60-
$usePRTitleAsNotesHeading = $env:PSMODULE_PUBLISH_PSMODULE_INPUT_UsePRTitleAsNotesHeading -eq 'true'
6142

6243
Write-Host "Module name: [$name]"
6344
Write-Host "Module path: [$modulePath]"
@@ -74,7 +55,6 @@ LogGroup 'Load PR information' {
7455
throw 'GitHub event does not contain pull_request data. This script must be run from a pull_request event.'
7556
}
7657
$prNumber = $pull_request.number
77-
$prHeadRef = $pull_request.head.ref
7858
}
7959
#endregion Load PR information
8060

@@ -137,7 +117,6 @@ LogGroup 'Resolve version from manifest' {
137117
CreatePrerelease = $createPrerelease
138118
ReleaseTag = $releaseTag
139119
PRNumber = $prNumber
140-
PRHeadRef = $prHeadRef
141120
} | Format-List | Out-String
142121

143122
# Expose release tag to subsequent steps so cleanup can exclude the just-published tag.
@@ -184,100 +163,4 @@ LogGroup 'Publish to PSGallery' {
184163
}
185164
}
186165
#endregion Publish to PSGallery
187-
188-
#region Create GitHub release with module artifact attached
189-
# A zip of the published module is uploaded so the GitHub Release page exposes the exact bytes
190-
# that were tested and pushed to the PowerShell Gallery.
191-
LogGroup 'Create GitHub release' {
192-
$releaseCreateCommand = @('release', 'create', $releaseTag)
193-
$notesFilePath = $null
194-
195-
if ($usePRTitleAsReleaseName -and $pull_request.title) {
196-
$releaseCreateCommand += @('--title', $pull_request.title)
197-
Write-Host "Using PR title as release name: [$($pull_request.title)]"
198-
} else {
199-
$releaseCreateCommand += @('--title', $releaseTag)
200-
}
201-
202-
# Build release notes content. Uses temp file to avoid escaping issues with special characters.
203-
# Precedence rules for the three UsePR* parameters:
204-
# 1. UsePRTitleAsNotesHeading + UsePRBodyAsReleaseNotes: Creates "# Title (#PR)\n\nBody" format.
205-
# 2. UsePRBodyAsReleaseNotes only: Uses PR body as-is.
206-
# 3. Fallback: Auto-generates notes via GitHub's --generate-notes.
207-
if ($usePRTitleAsNotesHeading -and $usePRBodyAsReleaseNotes -and $pull_request.title -and $pull_request.body) {
208-
$notes = "# $($pull_request.title) (#$prNumber)`n`n$($pull_request.body)"
209-
$notesFilePath = [System.IO.Path]::GetTempFileName()
210-
Set-Content -Path $notesFilePath -Value $notes -Encoding utf8
211-
$releaseCreateCommand += @('--notes-file', $notesFilePath)
212-
Write-Host 'Using PR title as H1 heading with link and body as release notes'
213-
} elseif ($usePRBodyAsReleaseNotes -and $pull_request.body) {
214-
$notesFilePath = [System.IO.Path]::GetTempFileName()
215-
Set-Content -Path $notesFilePath -Value $pull_request.body -Encoding utf8
216-
$releaseCreateCommand += @('--notes-file', $notesFilePath)
217-
Write-Host 'Using PR body as release notes'
218-
} else {
219-
$releaseCreateCommand += @('--generate-notes')
220-
}
221-
222-
if ($createPrerelease) {
223-
$releaseCreateCommand += @('--target', $prHeadRef, '--prerelease')
224-
}
225-
226-
if ($whatIf) {
227-
Write-Host "WhatIf: gh $($releaseCreateCommand -join ' ')"
228-
$releaseURL = "https://github.com/$env:GITHUB_REPOSITORY/releases/tag/$releaseTag"
229-
} else {
230-
try {
231-
$releaseURL = gh @releaseCreateCommand
232-
if ($LASTEXITCODE -ne 0) {
233-
Write-Error "Failed to create the release [$releaseTag]."
234-
exit $LASTEXITCODE
235-
}
236-
} finally {
237-
if ($notesFilePath -and (Test-Path -Path $notesFilePath)) {
238-
Remove-Item -Path $notesFilePath -Force
239-
}
240-
}
241-
}
242-
243-
# Attach the built module as a release artifact so consumers can download the exact
244-
# bytes that were tested and published to the PowerShell Gallery.
245-
$zipFileName = "$name-$publishPSVersion.zip"
246-
$zipPath = Join-Path -Path ([System.IO.Path]::GetTempPath()) -ChildPath $zipFileName
247-
if (Test-Path -Path $zipPath) {
248-
Remove-Item -Path $zipPath -Force
249-
}
250-
if ($whatIf) {
251-
Write-Host "WhatIf: Compress-Archive -Path $modulePath -DestinationPath $zipPath -Force"
252-
Write-Host "WhatIf: gh release upload $releaseTag $zipPath --clobber"
253-
} else {
254-
Write-Host "Compressing module to [$zipPath]"
255-
Compress-Archive -Path $modulePath -DestinationPath $zipPath -Force
256-
try {
257-
gh release upload $releaseTag $zipPath --clobber
258-
if ($LASTEXITCODE -ne 0) {
259-
Write-Error "Failed to upload module artifact to release [$releaseTag]."
260-
exit $LASTEXITCODE
261-
}
262-
Write-Host "::notice title=📦 Attached module artifact to release::$zipFileName"
263-
} finally {
264-
if (Test-Path -Path $zipPath) {
265-
Remove-Item -Path $zipPath -Force
266-
}
267-
}
268-
}
269-
270-
if ($whatIf) {
271-
Write-Host "gh pr comment $prNumber -b '✅ $($releaseType): GitHub - $name $releaseTag'"
272-
} else {
273-
gh pr comment $prNumber -b "$releaseType`: GitHub - [$name $releaseTag]($releaseURL)"
274-
if ($LASTEXITCODE -ne 0) {
275-
Write-Error 'Failed to comment on the pull request.'
276-
exit $LASTEXITCODE
277-
}
278-
}
279-
Write-Host "::notice title=✅ $releaseType`: GitHub - $name $releaseTag::$releaseURL"
280-
}
281-
#endregion Create GitHub release
282-
283-
Write-Host "Publishing complete. Version: [$releaseTag]"
166+
Write-Host "Gallery publishing complete. Version: [$releaseTag]"

0 commit comments

Comments
 (0)