From caa0ab145d9441b8917e8f1859641255303dffd8 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Mon, 2 Jun 2025 01:20:58 +0200 Subject: [PATCH 1/3] =?UTF-8?q?=F0=9F=A9=B9=20[Patch]:=20Remove=20initiali?= =?UTF-8?q?zation=20step=20and=20dependency=20on=20`Utilities`=20(#50)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ## Description Remove the initialization step and dependency on `Utilities`, the Install-PSModuleHelpers takes over. ## Type of change - [ ] πŸ“– [Docs] - [ ] πŸͺ² [Fix] - [x] 🩹 [Patch] - [ ] ⚠️ [Security fix] - [ ] πŸš€ [Feature] - [ ] 🌟 [Breaking change] ## Checklist - [x] I have performed a self-review of my own code - [x] I have commented my code, particularly in hard-to-understand areas --- .github/workflows/Action-Test.yml | 3 --- scripts/helpers/Publish-PSModule.ps1 | 7 +++---- scripts/main.ps1 | 16 ++++++++++++++++ 3 files changed, 19 insertions(+), 7 deletions(-) diff --git a/.github/workflows/Action-Test.yml b/.github/workflows/Action-Test.yml index afa6647..26c698d 100644 --- a/.github/workflows/Action-Test.yml +++ b/.github/workflows/Action-Test.yml @@ -24,9 +24,6 @@ jobs: - name: Checkout repo uses: actions/checkout@v4 - - name: Initialize environment - uses: PSModule/Initialize-PSModule@main - - name: Action-Test uses: ./ env: diff --git a/scripts/helpers/Publish-PSModule.ps1 b/scripts/helpers/Publish-PSModule.ps1 index 96ce20d..ac26378 100644 --- a/scripts/helpers/Publish-PSModule.ps1 +++ b/scripts/helpers/Publish-PSModule.ps1 @@ -11,7 +11,6 @@ #> [OutputType([void])] [CmdletBinding()] - #Requires -Modules Utilities, PowerShellGet, Microsoft.PowerShell.PSResourceGet, GitHub, PSSemVer [Diagnostics.CodeAnalysis.SuppressMessageAttribute( 'PSReviewUnusedParameter', '', Scope = 'Function', Justification = 'LogGroup - Scoping affects the variables line of sight.' @@ -146,7 +145,7 @@ $latestRelease = $releases | Where-Object { $_.isLatest -eq $true } $latestRelease | Format-List | Out-String $ghReleaseVersionString = $latestRelease.tagName - if ($ghReleaseVersionString | IsNotNullOrEmpty) { + if (-not [string]::IsNullOrEmpty($ghReleaseVersionString)) { $ghReleaseVersion = New-PSSemVer -Version $ghReleaseVersionString } else { Write-Warning 'Could not find the latest release version. Using ''0.0.0'' as the version.' @@ -198,7 +197,7 @@ try { $manifestVersion = New-PSSemVer -Version (Test-ModuleManifest $manifestFilePath -Verbose:$false).Version } catch { - if ($manifestVersion | IsNullOrEmpty) { + if ([string]::IsNullOrEmpty($manifestVersion)) { Write-Warning 'Could not find the module version in the manifest. Using ''0.0.0'' as the version.' $manifestVersion = New-PSSemVer -Version '0.0.0' } @@ -249,7 +248,7 @@ $newVersion.Prerelease = $prereleaseName Write-Output "Partial new version: [$newVersion]" - if ($datePrereleaseFormat | IsNotNullOrEmpty) { + if (-not [string]::IsNullOrEmpty($datePrereleaseFormat)) { Write-Output "Using date-based prerelease: [$datePrereleaseFormat]." $newVersion.Prerelease += "$(Get-Date -Format $datePrereleaseFormat)" Write-Output "Partial new version: [$newVersion]" diff --git a/scripts/main.ps1 b/scripts/main.ps1 index b946e9c..e7fedc7 100644 --- a/scripts/main.ps1 +++ b/scripts/main.ps1 @@ -1,6 +1,22 @@ [CmdletBinding()] param() +$retryCount = 5 +$retryDelay = 10 +for ($i = 0; $i -lt $retryCount; $i++) { + try { + Install-PSResource -Name 'PSSemVer' -TrustRepository -Repository PSGallery + break + } catch { + Write-Warning "Installation of $($psResourceParams.Name) failed with error: $_" + if ($i -eq $retryCount - 1) { + throw + } + Write-Warning "Retrying in $retryDelay seconds..." + Start-Sleep -Seconds $retryDelay + } +} + $path = (Join-Path -Path $PSScriptRoot -ChildPath 'helpers') LogGroup "Loading helper scripts from [$path]" { Get-ChildItem -Path $path -Filter '*.ps1' -Recurse | ForEach-Object { From 9cf3a80a3e11a9bfa8002e0446bcaaa104e355fe Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Mon, 2 Jun 2025 02:58:10 +0200 Subject: [PATCH 2/3] =?UTF-8?q?=F0=9F=A9=B9=20[Patch]:=20Remove=20reliance?= =?UTF-8?q?=20on=20`GitHub`=20(#51)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ## Description This pull request introduces several updates to streamline the PowerShell module publishing process and enhance logging functionality. Key changes include replacing `LogGroup` with `Set-GitHubLogGroup` for improved GitHub-specific logging, simplifying the `action.yml` configuration, and refining the `Publish-PSModule` script to focus solely on publishing to the PowerShell Gallery. ### Updates to `action.yml` Configuration: * Switched from using `GitHub-Script` to running the script directly with `pwsh` shell, enabling better control over the execution environment. (`[[1]](diffhunk://#diff-1243c5424efaaa19bd8e813c5e6f6da46316e63761421b3e5f5c8ced9a36e6b6L86-R87)`, `[[2]](diffhunk://#diff-1243c5424efaaa19bd8e813c5e6f6da46316e63761421b3e5f5c8ced9a36e6b6L102-R103)`) ### Enhancements to Logging: * Replaced all instances of `LogGroup` with `Set-GitHubLogGroup` in `scripts/helpers/Publish-PSModule.ps1` and `scripts/main.ps1` for improved GitHub-specific structured logging. (`[[1]](diffhunk://#diff-780715ac24c6bbe21b54f3d268778136b79f21a62275bbd494dfa857b4ba40d9L36-R36)`, `[[2]](diffhunk://#diff-780715ac24c6bbe21b54f3d268778136b79f21a62275bbd494dfa857b4ba40d9L62-R73)`, `[[3]](diffhunk://#diff-dc2e5a659836b1b73abb03421c567f5018c2755677c4a0aa764cb26117b68011L21-R28)`, and others) ### Refinements to `Publish-PSModule` Script: * Updated the `.DESCRIPTION` and `.SYNOPSIS` sections to remove references to GitHub Pages, focusing exclusively on publishing modules to the PowerShell Gallery. (`[scripts/helpers/Publish-PSModule.ps1L4-R7](diffhunk://#diff-780715ac24c6bbe21b54f3d268778136b79f21a62275bbd494dfa857b4ba40d9L4-R7)`) * Removed redundant GitHub Pages functionality, simplifying the script logic. (`[scripts/helpers/Publish-PSModule.ps1L4-R7](diffhunk://#diff-780715ac24c6bbe21b54f3d268778136b79f21a62275bbd494dfa857b4ba40d9L4-R7)`) ## Type of change - [ ] πŸ“– [Docs] - [ ] πŸͺ² [Fix] - [x] 🩹 [Patch] - [ ] ⚠️ [Security fix] - [ ] πŸš€ [Feature] - [ ] 🌟 [Breaking change] ## Checklist - [x] I have performed a self-review of my own code - [x] I have commented my code, particularly in hard-to-understand areas --- .github/workflows/Action-Test.yml | 2 - action.yml | 28 ++------------ scripts/helpers/Publish-PSModule.ps1 | 56 +++++++++++++++------------- scripts/main.ps1 | 4 +- 4 files changed, 35 insertions(+), 55 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 2b0fac0..540f3b2 100644 --- a/action.yml +++ b/action.yml @@ -56,21 +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' - 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 @@ -83,7 +68,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 }} @@ -98,12 +84,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 }} - 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..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 and GitHub Pages. + .SYNOPSIS + Publishes a module to the PowerShell Gallery and creates a GitHub Release. - .DESCRIPTION - Publishes a module to the PowerShell Gallery and GitHub Pages. + .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()] @@ -33,7 +37,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 +63,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 +100,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 +138,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 +161,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 +190,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 +212,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 +224,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 +306,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 +318,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 { @@ -343,7 +347,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.' @@ -352,7 +356,7 @@ } } - LogGroup 'New-GitHubRelease' { + Set-GitHubLogGroup 'New-GitHubRelease' { Write-Output 'Create new GitHub release' if ($createPrerelease) { if ($whatIf) { @@ -384,17 +388,17 @@ exit $LASTEXITCODE } } - Write-GitHubNotice "Release created: [$newVersion]" + Write-Host "::notice::Release created: [$newVersion]" } } - 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 23039424486fe3c37495e325b029d0a6709dcbe1 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Mon, 2 Jun 2025 03:29:22 +0200 Subject: [PATCH 3/3] =?UTF-8?q?=F0=9F=93=96=20[Docs]:=20Remove=20unused=20?= =?UTF-8?q?configuration=20options=20from=20README=20(#52)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ## Description This pull request updates the `README.md` file to simplify the list of configurable settings for the action. It removes several less commonly used settings to streamline the documentation and make it easier to read. Documentation cleanup: * [`README.md`](diffhunk://#diff-b335630551682c19a781afebcf4d07bf978fb1f8ac04c6bf87428ed5106870f5L63-L66): Removed the following settings from the configuration list: `Debug`, `Verbose`, `Version`, and `Prerelease`. These settings are no longer included in the documentation to simplify the list and focus on the most relevant options. ## Type of change - [x] πŸ“– [Docs] - [ ] πŸͺ² [Fix] - [ ] 🩹 [Patch] - [ ] ⚠️ [Security fix] - [ ] πŸš€ [Feature] - [ ] 🌟 [Breaking change] ## Checklist - [x] I have performed a self-review of my own code - [x] I have commented my code, particularly in hard-to-understand areas --- README.md | 4 ---- scripts/main.ps1 | 2 ++ 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 83faa3c..17e1969 100644 --- a/README.md +++ b/README.md @@ -60,10 +60,6 @@ The action can be configured using the following settings: | `PatchLabels` | A comma separated list of labels that trigger a patch release. | `false` | `patch, fix` | | `IgnoreLabels` | A comma separated list of labels that do not trigger a release. | `false` | `NoRelease` | | `WhatIf` | Control wether to simulate the action. If enabled, the action will not create any releases. Used for testing. | `false` | `false` | -| `Debug` | Enable debug output. | `'false'` | `false` | -| `Verbose` | Enable verbose output. | `'false'` | `false` | -| `Version` | Specifies the version of the GitHub module to be installed. The value must be an exact version. | | `false` | -| `Prerelease` | Allow prerelease versions if available. | `'false'` | `false` | | `WorkingDirectory` | The working directory where the script runs. | `'false'` | `'.'` | ## Example diff --git a/scripts/main.ps1 b/scripts/main.ps1 index 33567ee..97b0c50 100644 --- a/scripts/main.ps1 +++ b/scripts/main.ps1 @@ -25,6 +25,8 @@ Set-GitHubLogGroup "Loading helper scripts from [$path]" { } } +$env:GITHUB_REPOSITORY_NAME = $env:GITHUB_REPOSITORY -replace '.+/' + Set-GitHubLogGroup 'Loading inputs' { $name = if ([string]::IsNullOrEmpty($env:PSMODULE_PUBLISH_PSMODULE_INPUT_Name)) { $env:GITHUB_REPOSITORY_NAME