From 540c7695eb9da02005bf4c47a922e4401db77289 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Mon, 2 Jun 2025 02:43:36 +0200 Subject: [PATCH 1/4] =?UTF-8?q?=F0=9F=A9=B9=20[Patch]:=20Refactor=20loggin?= =?UTF-8?q?g=20functions=20to=20use=20Set-GitHubLogGroup=20for=20consisten?= =?UTF-8?q?cy=20in=20Publish-PSModule=20action?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- action.yml | 12 +++------ scripts/helpers/Publish-PSModule.ps1 | 40 ++++++++++++++-------------- scripts/main.ps1 | 4 +-- 3 files changed, 25 insertions(+), 31 deletions(-) diff --git a/action.yml b/action.yml index 2b0fac0..0d2ed21 100644 --- a/action.yml +++ b/action.yml @@ -83,7 +83,8 @@ runs: uses: PSModule/Install-PSModuleHelpers@v1 - name: Run Publish-PSModule - uses: PSModule/GitHub-Script@v1 + shell: pwsh + working-directory: ${{ inputs.WorkingDirectory }} env: PSMODULE_PUBLISH_PSMODULE_INPUT_Name: ${{ inputs.Name }} PSMODULE_PUBLISH_PSMODULE_INPUT_ModulePath: ${{ inputs.ModulePath }} @@ -99,11 +100,4 @@ runs: PSMODULE_PUBLISH_PSMODULE_INPUT_VersionPrefix: ${{ inputs.VersionPrefix }} PSMODULE_PUBLISH_PSMODULE_INPUT_WhatIf: ${{ inputs.WhatIf }} PSMODULE_PUBLISH_PSMODULE_INPUT_WorkingDirectory: ${{ inputs.WorkingDirectory }} - with: - Name: Publish-PSModule - Debug: ${{ inputs.Debug }} - Prerelease: ${{ inputs.Prerelease }} - Verbose: ${{ inputs.Verbose }} - Version: ${{ inputs.Version }} - WorkingDirectory: ${{ inputs.WorkingDirectory }} - Script: ${{ github.action_path }}/scripts/main.ps1 + run: ${{ github.action_path }}/scripts/main.ps1 diff --git a/scripts/helpers/Publish-PSModule.ps1 b/scripts/helpers/Publish-PSModule.ps1 index ac26378..3777339 100644 --- a/scripts/helpers/Publish-PSModule.ps1 +++ b/scripts/helpers/Publish-PSModule.ps1 @@ -1,10 +1,10 @@ function Publish-PSModule { <# .SYNOPSIS - Publishes a module to the PowerShell Gallery and GitHub Pages. + Publishes a module to the PowerShell Gallery. .DESCRIPTION - Publishes a module to the PowerShell Gallery and GitHub Pages. + Publishes a module to the PowerShell Gallery. .EXAMPLE Publish-PSModule -Name 'PSModule.FX' -APIKey $env:PSGALLERY_API_KEY @@ -33,7 +33,7 @@ [string] $APIKey ) - LogGroup 'Set configuration' { + Set-GitHubLogGroup 'Set configuration' { $autoCleanup = $env:PSMODULE_PUBLISH_PSMODULE_INPUT_AutoCleanup -eq 'true' $autoPatching = $env:PSMODULE_PUBLISH_PSMODULE_INPUT_AutoPatching -eq 'true' $incrementalPrerelease = $env:PSMODULE_PUBLISH_PSMODULE_INPUT_IncrementalPrerelease -eq 'true' @@ -59,18 +59,18 @@ } | Format-List | Out-String } - LogGroup 'Event information - JSON' { + Set-GitHubLogGroup 'Event information - JSON' { $githubEventJson = Get-Content $env:GITHUB_EVENT_PATH $githubEventJson | Format-List | Out-String } - LogGroup 'Event information - Object' { + Set-GitHubLogGroup 'Event information - Object' { $githubEvent = $githubEventJson | ConvertFrom-Json $pull_request = $githubEvent.pull_request $githubEvent | Format-List | Out-String } - LogGroup 'Event information - Details' { + Set-GitHubLogGroup 'Event information - Details' { $defaultBranchName = (gh repo view --json defaultBranchRef | ConvertFrom-Json | Select-Object -ExpandProperty defaultBranchRef).name $isPullRequest = $githubEvent.PSObject.Properties.Name -Contains 'pull_request' if (-not ($isPullRequest -or $whatIf)) { @@ -96,17 +96,17 @@ Write-Output '-------------------------------------------------' } - LogGroup 'Pull request - details' { + Set-GitHubLogGroup 'Pull request - details' { $pull_request | Format-List | Out-String } - LogGroup 'Pull request - Labels' { + Set-GitHubLogGroup 'Pull request - Labels' { $labels = @() $labels += $pull_request.labels.name $labels | Format-List | Out-String } - LogGroup 'Calculate release type' { + Set-GitHubLogGroup 'Calculate release type' { $createRelease = $isMerged -and $targetIsDefaultBranch $closedPullRequest = $prIsClosed -and -not $isMerged $createPrerelease = $labels -Contains 'prerelease' -and -not $createRelease -and -not $closedPullRequest @@ -134,7 +134,7 @@ Write-Output '-------------------------------------------------' } - LogGroup 'Get latest version - GitHub' { + Set-GitHubLogGroup 'Get latest version - GitHub' { $releases = gh release list --json 'createdAt,isDraft,isLatest,isPrerelease,name,publishedAt,tagName' | ConvertFrom-Json if ($LASTEXITCODE -ne 0) { Write-Error 'Failed to list all releases for the repo.' @@ -157,7 +157,7 @@ Write-Output '-------------------------------------------------' } - LogGroup 'Get latest version - PSGallery' { + Set-GitHubLogGroup 'Get latest version - PSGallery' { $count = 5 $delay = 10 for ($i = 1; $i -le $count; $i++) { @@ -186,7 +186,7 @@ Write-Output '-------------------------------------------------' } - LogGroup 'Get latest version - Manifest' { + Set-GitHubLogGroup 'Get latest version - Manifest' { Add-PSModulePath -Path (Split-Path -Path $ModulePath -Parent) $manifestFilePath = Join-Path $ModulePath "$Name.psd1" Write-Output "Module manifest file path: [$manifestFilePath]" @@ -208,7 +208,7 @@ Write-Output '-------------------------------------------------' } - LogGroup 'Get latest version' { + Set-GitHubLogGroup 'Get latest version' { Write-Output "GitHub: [$($ghReleaseVersion.ToString())]" Write-Output "PSGallery: [$($psGalleryVersion.ToString())]" Write-Output "Manifest: [$($manifestVersion.ToString())] (ignored)" @@ -220,7 +220,7 @@ Write-Output '-------------------------------------------------' } - LogGroup 'Calculate new version' { + Set-GitHubLogGroup 'Calculate new version' { # - Increment based on label on PR $newVersion = New-PSSemVer -Version $latestVersion $newVersion.Prefix = $versionPrefix @@ -302,7 +302,7 @@ } Write-Output "New version is [$($newVersion.ToString())]" - LogGroup 'Update module manifest' { + Set-GitHubLogGroup 'Update module manifest' { Write-Output 'Bump module version -> module metadata: Update-ModuleMetadata' $manifestNewVersion = "$($newVersion.Major).$($newVersion.Minor).$($newVersion.Patch)" Set-ModuleManifest -Path $manifestFilePath -ModuleVersion $manifestNewVersion -Verbose:$false @@ -314,12 +314,12 @@ Show-FileContent -Path $manifestFilePath } - LogGroup 'Install module dependencies' { + Set-GitHubLogGroup 'Install module dependencies' { Resolve-PSModuleDependency -ManifestFilePath $manifestFilePath } if ($createPrerelease -or $createRelease -or $whatIf) { - LogGroup 'Publish-ToPSGallery' { + Set-GitHubLogGroup 'Publish-ToPSGallery' { if ($createPrerelease) { $publishPSVersion = "$($newVersion.Major).$($newVersion.Minor).$($newVersion.Patch)-$($newVersion.Prerelease)" } else { @@ -352,7 +352,7 @@ } } - LogGroup 'New-GitHubRelease' { + Set-GitHubLogGroup 'New-GitHubRelease' { Write-Output 'Create new GitHub release' if ($createPrerelease) { if ($whatIf) { @@ -388,13 +388,13 @@ } } - LogGroup 'List prereleases using the same name' { + Set-GitHubLogGroup 'List prereleases using the same name' { $prereleasesToCleanup = $releases | Where-Object { $_.tagName -like "*$prereleaseName*" } $prereleasesToCleanup | Select-Object -Property name, publishedAt, isPrerelease, isLatest | Format-Table | Out-String } if ((($closedPullRequest -or $createRelease) -and $autoCleanup) -or $whatIf) { - LogGroup "Cleanup prereleases for [$prereleaseName]" { + Set-GitHubLogGroup "Cleanup prereleases for [$prereleaseName]" { foreach ($rel in $prereleasesToCleanup) { $relTagName = $rel.tagName Write-Output "Deleting prerelease: [$relTagName]." diff --git a/scripts/main.ps1 b/scripts/main.ps1 index e7fedc7..33567ee 100644 --- a/scripts/main.ps1 +++ b/scripts/main.ps1 @@ -18,14 +18,14 @@ for ($i = 0; $i -lt $retryCount; $i++) { } $path = (Join-Path -Path $PSScriptRoot -ChildPath 'helpers') -LogGroup "Loading helper scripts from [$path]" { +Set-GitHubLogGroup "Loading helper scripts from [$path]" { Get-ChildItem -Path $path -Filter '*.ps1' -Recurse | ForEach-Object { Write-Verbose "[$($_.FullName)]" . $_.FullName } } -LogGroup 'Loading inputs' { +Set-GitHubLogGroup 'Loading inputs' { $name = if ([string]::IsNullOrEmpty($env:PSMODULE_PUBLISH_PSMODULE_INPUT_Name)) { $env:GITHUB_REPOSITORY_NAME } else { From 54b136c9ea4256b24e2233db47096a0d5e301679 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Mon, 2 Jun 2025 02:50:23 +0200 Subject: [PATCH 2/4] =?UTF-8?q?=F0=9F=A9=B9=20[Patch]:=20Replace=20Write-G?= =?UTF-8?q?itHubNotice=20with=20Write-Host=20for=20improved=20logging=20in?= =?UTF-8?q?=20Publish-PSModule=20script?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- action.yml | 17 +---------------- scripts/helpers/Publish-PSModule.ps1 | 4 ++-- 2 files changed, 3 insertions(+), 18 deletions(-) diff --git a/action.yml b/action.yml index 0d2ed21..d5e28df 100644 --- a/action.yml +++ b/action.yml @@ -56,21 +56,7 @@ inputs: description: If specified, the action will only log the changes it would make, but will not actually create or delete any releases or tags. required: false default: 'false' - Debug: - description: Enable debug output. - required: false - default: 'false' - Verbose: - description: Enable verbose output. - required: false - default: 'false' - Version: - description: Specifies the version of the GitHub module to be installed. The value must be an exact version. - required: false - Prerelease: - description: Allow prerelease versions if available. - required: false - default: 'false' + WorkingDirectory: description: The working directory where the script will run from. required: false @@ -99,5 +85,4 @@ runs: PSMODULE_PUBLISH_PSMODULE_INPUT_PatchLabels: ${{ inputs.PatchLabels }} PSMODULE_PUBLISH_PSMODULE_INPUT_VersionPrefix: ${{ inputs.VersionPrefix }} PSMODULE_PUBLISH_PSMODULE_INPUT_WhatIf: ${{ inputs.WhatIf }} - PSMODULE_PUBLISH_PSMODULE_INPUT_WorkingDirectory: ${{ inputs.WorkingDirectory }} run: ${{ github.action_path }}/scripts/main.ps1 diff --git a/scripts/helpers/Publish-PSModule.ps1 b/scripts/helpers/Publish-PSModule.ps1 index 3777339..6edb374 100644 --- a/scripts/helpers/Publish-PSModule.ps1 +++ b/scripts/helpers/Publish-PSModule.ps1 @@ -343,7 +343,7 @@ " PowerShell Gallery [$publishPSVersion]($psGalleryReleaseLink) has been created.'" ) } else { - Write-GitHubNotice "Module [$Name - $publishPSVersion] published to the PowerShell Gallery." + Write-Host "::notice::Module [$Name - $publishPSVersion] published to the PowerShell Gallery." gh pr comment $pull_request.number -b "Module [$Name - $publishPSVersion]($psGalleryReleaseLink) published to the PowerShell Gallery." if ($LASTEXITCODE -ne 0) { Write-Error 'Failed to comment on the pull request.' @@ -384,7 +384,7 @@ exit $LASTEXITCODE } } - Write-GitHubNotice "Release created: [$newVersion]" + Write-Host "::notice::Release created: [$newVersion]" } } From 1a20f252016ff4e4997771c440168f043ab3b0ed Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Mon, 2 Jun 2025 02:52:57 +0200 Subject: [PATCH 3/4] =?UTF-8?q?=F0=9F=A9=B9=20[Patch]:=20Remove=20Verbose?= =?UTF-8?q?=20and=20Debug=20options=20from=20Action-Test=20workflow=20and?= =?UTF-8?q?=20clean=20up=20action.yml=20inputs?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/Action-Test.yml | 2 -- action.yml | 1 - 2 files changed, 3 deletions(-) diff --git a/.github/workflows/Action-Test.yml b/.github/workflows/Action-Test.yml index 26c698d..1a3c40c 100644 --- a/.github/workflows/Action-Test.yml +++ b/.github/workflows/Action-Test.yml @@ -29,8 +29,6 @@ jobs: env: GITHUB_TOKEN: ${{ github.token }} with: - Verbose: true - Debug: true Name: PSModuleTest WorkingDirectory: tests APIKey: ${{ secrets.APIKEY }} diff --git a/action.yml b/action.yml index d5e28df..540f3b2 100644 --- a/action.yml +++ b/action.yml @@ -56,7 +56,6 @@ inputs: description: If specified, the action will only log the changes it would make, but will not actually create or delete any releases or tags. required: false default: 'false' - WorkingDirectory: description: The working directory where the script will run from. required: false From d2c9be2f8919c47578fbd33f7a99dcacab3bd192 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Mon, 2 Jun 2025 02:55:00 +0200 Subject: [PATCH 4/4] =?UTF-8?q?=F0=9F=A9=B9=20[Patch]:=20Update=20synopsis?= =?UTF-8?q?=20and=20description=20in=20Publish-PSModule=20function=20to=20?= =?UTF-8?q?clarify=20GitHub=20Release=20creation?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- scripts/helpers/Publish-PSModule.ps1 | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/scripts/helpers/Publish-PSModule.ps1 b/scripts/helpers/Publish-PSModule.ps1 index 6edb374..956ffc1 100644 --- a/scripts/helpers/Publish-PSModule.ps1 +++ b/scripts/helpers/Publish-PSModule.ps1 @@ -1,13 +1,13 @@ function Publish-PSModule { <# - .SYNOPSIS - Publishes a module to the PowerShell Gallery. + .SYNOPSIS + Publishes a module to the PowerShell Gallery and creates a GitHub Release. - .DESCRIPTION - Publishes a module to the PowerShell Gallery. + .DESCRIPTION + Publishes a module to the PowerShell Gallery and creates a GitHub Release. - .EXAMPLE - Publish-PSModule -Name 'PSModule.FX' -APIKey $env:PSGALLERY_API_KEY + .EXAMPLE + Publish-PSModule -Name 'PSModule.FX' -APIKey $env:PSGALLERY_API_KEY #> [OutputType([void])] [CmdletBinding()] @@ -19,6 +19,10 @@ 'PSUseDeclaredVarsMoreThanAssignments', '', Justification = 'LogGroup - Scoping affects the variables line of sight.' )] + [Diagnostics.CodeAnalysis.SuppressMessageAttribute( + 'PSAvoidUsingWriteHost', '', + Justification = 'Log outputs to GitHub Actions logs.' + )] param( # Name of the module to process. [Parameter()]