Skip to content

Commit 540c769

Browse files
🩹 [Patch]: Refactor logging functions to use Set-GitHubLogGroup for consistency in Publish-PSModule action
1 parent caa0ab1 commit 540c769

3 files changed

Lines changed: 25 additions & 31 deletions

File tree

‎action.yml‎

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,8 @@ runs:
8383
uses: PSModule/Install-PSModuleHelpers@v1
8484

8585
- name: Run Publish-PSModule
86-
uses: PSModule/GitHub-Script@v1
86+
shell: pwsh
87+
working-directory: ${{ inputs.WorkingDirectory }}
8788
env:
8889
PSMODULE_PUBLISH_PSMODULE_INPUT_Name: ${{ inputs.Name }}
8990
PSMODULE_PUBLISH_PSMODULE_INPUT_ModulePath: ${{ inputs.ModulePath }}
@@ -99,11 +100,4 @@ runs:
99100
PSMODULE_PUBLISH_PSMODULE_INPUT_VersionPrefix: ${{ inputs.VersionPrefix }}
100101
PSMODULE_PUBLISH_PSMODULE_INPUT_WhatIf: ${{ inputs.WhatIf }}
101102
PSMODULE_PUBLISH_PSMODULE_INPUT_WorkingDirectory: ${{ inputs.WorkingDirectory }}
102-
with:
103-
Name: Publish-PSModule
104-
Debug: ${{ inputs.Debug }}
105-
Prerelease: ${{ inputs.Prerelease }}
106-
Verbose: ${{ inputs.Verbose }}
107-
Version: ${{ inputs.Version }}
108-
WorkingDirectory: ${{ inputs.WorkingDirectory }}
109-
Script: ${{ github.action_path }}/scripts/main.ps1
103+
run: ${{ github.action_path }}/scripts/main.ps1

‎scripts/helpers/Publish-PSModule.ps1‎

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
function Publish-PSModule {
22
<#
33
.SYNOPSIS
4-
Publishes a module to the PowerShell Gallery and GitHub Pages.
4+
Publishes a module to the PowerShell Gallery.
55
66
.DESCRIPTION
7-
Publishes a module to the PowerShell Gallery and GitHub Pages.
7+
Publishes a module to the PowerShell Gallery.
88
99
.EXAMPLE
1010
Publish-PSModule -Name 'PSModule.FX' -APIKey $env:PSGALLERY_API_KEY
@@ -33,7 +33,7 @@
3333
[string] $APIKey
3434
)
3535

36-
LogGroup 'Set configuration' {
36+
Set-GitHubLogGroup 'Set configuration' {
3737
$autoCleanup = $env:PSMODULE_PUBLISH_PSMODULE_INPUT_AutoCleanup -eq 'true'
3838
$autoPatching = $env:PSMODULE_PUBLISH_PSMODULE_INPUT_AutoPatching -eq 'true'
3939
$incrementalPrerelease = $env:PSMODULE_PUBLISH_PSMODULE_INPUT_IncrementalPrerelease -eq 'true'
@@ -59,18 +59,18 @@
5959
} | Format-List | Out-String
6060
}
6161

62-
LogGroup 'Event information - JSON' {
62+
Set-GitHubLogGroup 'Event information - JSON' {
6363
$githubEventJson = Get-Content $env:GITHUB_EVENT_PATH
6464
$githubEventJson | Format-List | Out-String
6565
}
6666

67-
LogGroup 'Event information - Object' {
67+
Set-GitHubLogGroup 'Event information - Object' {
6868
$githubEvent = $githubEventJson | ConvertFrom-Json
6969
$pull_request = $githubEvent.pull_request
7070
$githubEvent | Format-List | Out-String
7171
}
7272

73-
LogGroup 'Event information - Details' {
73+
Set-GitHubLogGroup 'Event information - Details' {
7474
$defaultBranchName = (gh repo view --json defaultBranchRef | ConvertFrom-Json | Select-Object -ExpandProperty defaultBranchRef).name
7575
$isPullRequest = $githubEvent.PSObject.Properties.Name -Contains 'pull_request'
7676
if (-not ($isPullRequest -or $whatIf)) {
@@ -96,17 +96,17 @@
9696
Write-Output '-------------------------------------------------'
9797
}
9898

99-
LogGroup 'Pull request - details' {
99+
Set-GitHubLogGroup 'Pull request - details' {
100100
$pull_request | Format-List | Out-String
101101
}
102102

103-
LogGroup 'Pull request - Labels' {
103+
Set-GitHubLogGroup 'Pull request - Labels' {
104104
$labels = @()
105105
$labels += $pull_request.labels.name
106106
$labels | Format-List | Out-String
107107
}
108108

109-
LogGroup 'Calculate release type' {
109+
Set-GitHubLogGroup 'Calculate release type' {
110110
$createRelease = $isMerged -and $targetIsDefaultBranch
111111
$closedPullRequest = $prIsClosed -and -not $isMerged
112112
$createPrerelease = $labels -Contains 'prerelease' -and -not $createRelease -and -not $closedPullRequest
@@ -134,7 +134,7 @@
134134
Write-Output '-------------------------------------------------'
135135
}
136136

137-
LogGroup 'Get latest version - GitHub' {
137+
Set-GitHubLogGroup 'Get latest version - GitHub' {
138138
$releases = gh release list --json 'createdAt,isDraft,isLatest,isPrerelease,name,publishedAt,tagName' | ConvertFrom-Json
139139
if ($LASTEXITCODE -ne 0) {
140140
Write-Error 'Failed to list all releases for the repo.'
@@ -157,7 +157,7 @@
157157
Write-Output '-------------------------------------------------'
158158
}
159159

160-
LogGroup 'Get latest version - PSGallery' {
160+
Set-GitHubLogGroup 'Get latest version - PSGallery' {
161161
$count = 5
162162
$delay = 10
163163
for ($i = 1; $i -le $count; $i++) {
@@ -186,7 +186,7 @@
186186
Write-Output '-------------------------------------------------'
187187
}
188188

189-
LogGroup 'Get latest version - Manifest' {
189+
Set-GitHubLogGroup 'Get latest version - Manifest' {
190190
Add-PSModulePath -Path (Split-Path -Path $ModulePath -Parent)
191191
$manifestFilePath = Join-Path $ModulePath "$Name.psd1"
192192
Write-Output "Module manifest file path: [$manifestFilePath]"
@@ -208,7 +208,7 @@
208208
Write-Output '-------------------------------------------------'
209209
}
210210

211-
LogGroup 'Get latest version' {
211+
Set-GitHubLogGroup 'Get latest version' {
212212
Write-Output "GitHub: [$($ghReleaseVersion.ToString())]"
213213
Write-Output "PSGallery: [$($psGalleryVersion.ToString())]"
214214
Write-Output "Manifest: [$($manifestVersion.ToString())] (ignored)"
@@ -220,7 +220,7 @@
220220
Write-Output '-------------------------------------------------'
221221
}
222222

223-
LogGroup 'Calculate new version' {
223+
Set-GitHubLogGroup 'Calculate new version' {
224224
# - Increment based on label on PR
225225
$newVersion = New-PSSemVer -Version $latestVersion
226226
$newVersion.Prefix = $versionPrefix
@@ -302,7 +302,7 @@
302302
}
303303
Write-Output "New version is [$($newVersion.ToString())]"
304304

305-
LogGroup 'Update module manifest' {
305+
Set-GitHubLogGroup 'Update module manifest' {
306306
Write-Output 'Bump module version -> module metadata: Update-ModuleMetadata'
307307
$manifestNewVersion = "$($newVersion.Major).$($newVersion.Minor).$($newVersion.Patch)"
308308
Set-ModuleManifest -Path $manifestFilePath -ModuleVersion $manifestNewVersion -Verbose:$false
@@ -314,12 +314,12 @@
314314
Show-FileContent -Path $manifestFilePath
315315
}
316316

317-
LogGroup 'Install module dependencies' {
317+
Set-GitHubLogGroup 'Install module dependencies' {
318318
Resolve-PSModuleDependency -ManifestFilePath $manifestFilePath
319319
}
320320

321321
if ($createPrerelease -or $createRelease -or $whatIf) {
322-
LogGroup 'Publish-ToPSGallery' {
322+
Set-GitHubLogGroup 'Publish-ToPSGallery' {
323323
if ($createPrerelease) {
324324
$publishPSVersion = "$($newVersion.Major).$($newVersion.Minor).$($newVersion.Patch)-$($newVersion.Prerelease)"
325325
} else {
@@ -352,7 +352,7 @@
352352
}
353353
}
354354

355-
LogGroup 'New-GitHubRelease' {
355+
Set-GitHubLogGroup 'New-GitHubRelease' {
356356
Write-Output 'Create new GitHub release'
357357
if ($createPrerelease) {
358358
if ($whatIf) {
@@ -388,13 +388,13 @@
388388
}
389389
}
390390

391-
LogGroup 'List prereleases using the same name' {
391+
Set-GitHubLogGroup 'List prereleases using the same name' {
392392
$prereleasesToCleanup = $releases | Where-Object { $_.tagName -like "*$prereleaseName*" }
393393
$prereleasesToCleanup | Select-Object -Property name, publishedAt, isPrerelease, isLatest | Format-Table | Out-String
394394
}
395395

396396
if ((($closedPullRequest -or $createRelease) -and $autoCleanup) -or $whatIf) {
397-
LogGroup "Cleanup prereleases for [$prereleaseName]" {
397+
Set-GitHubLogGroup "Cleanup prereleases for [$prereleaseName]" {
398398
foreach ($rel in $prereleasesToCleanup) {
399399
$relTagName = $rel.tagName
400400
Write-Output "Deleting prerelease: [$relTagName]."

‎scripts/main.ps1‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,14 @@ for ($i = 0; $i -lt $retryCount; $i++) {
1818
}
1919

2020
$path = (Join-Path -Path $PSScriptRoot -ChildPath 'helpers')
21-
LogGroup "Loading helper scripts from [$path]" {
21+
Set-GitHubLogGroup "Loading helper scripts from [$path]" {
2222
Get-ChildItem -Path $path -Filter '*.ps1' -Recurse | ForEach-Object {
2323
Write-Verbose "[$($_.FullName)]"
2424
. $_.FullName
2525
}
2626
}
2727

28-
LogGroup 'Loading inputs' {
28+
Set-GitHubLogGroup 'Loading inputs' {
2929
$name = if ([string]::IsNullOrEmpty($env:PSMODULE_PUBLISH_PSMODULE_INPUT_Name)) {
3030
$env:GITHUB_REPOSITORY_NAME
3131
} else {

0 commit comments

Comments
 (0)