Skip to content

Commit 9cf3a80

Browse files
🩹 [Patch]: Remove reliance on GitHub (#51)
## 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 <!-- Use the check-boxes [x] on the options that are relevant. --> - [ ] 📖 [Docs] - [ ] 🪲 [Fix] - [x] 🩹 [Patch] - [ ] ⚠️ [Security fix] - [ ] 🚀 [Feature] - [ ] 🌟 [Breaking change] ## Checklist <!-- Use the check-boxes [x] on the options that are relevant. --> - [x] I have performed a self-review of my own code - [x] I have commented my code, particularly in hard-to-understand areas
1 parent caa0ab1 commit 9cf3a80

File tree

4 files changed

+35
-55
lines changed

4 files changed

+35
-55
lines changed

.github/workflows/Action-Test.yml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,6 @@ jobs:
2929
env:
3030
GITHUB_TOKEN: ${{ github.token }}
3131
with:
32-
Verbose: true
33-
Debug: true
3432
Name: PSModuleTest
3533
WorkingDirectory: tests
3634
APIKey: ${{ secrets.APIKEY }}

action.yml

Lines changed: 3 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -56,21 +56,6 @@ inputs:
5656
description: If specified, the action will only log the changes it would make, but will not actually create or delete any releases or tags.
5757
required: false
5858
default: 'false'
59-
Debug:
60-
description: Enable debug output.
61-
required: false
62-
default: 'false'
63-
Verbose:
64-
description: Enable verbose output.
65-
required: false
66-
default: 'false'
67-
Version:
68-
description: Specifies the version of the GitHub module to be installed. The value must be an exact version.
69-
required: false
70-
Prerelease:
71-
description: Allow prerelease versions if available.
72-
required: false
73-
default: 'false'
7459
WorkingDirectory:
7560
description: The working directory where the script will run from.
7661
required: false
@@ -83,7 +68,8 @@ runs:
8368
uses: PSModule/Install-PSModuleHelpers@v1
8469

8570
- name: Run Publish-PSModule
86-
uses: PSModule/GitHub-Script@v1
71+
shell: pwsh
72+
working-directory: ${{ inputs.WorkingDirectory }}
8773
env:
8874
PSMODULE_PUBLISH_PSMODULE_INPUT_Name: ${{ inputs.Name }}
8975
PSMODULE_PUBLISH_PSMODULE_INPUT_ModulePath: ${{ inputs.ModulePath }}
@@ -98,12 +84,4 @@ runs:
9884
PSMODULE_PUBLISH_PSMODULE_INPUT_PatchLabels: ${{ inputs.PatchLabels }}
9985
PSMODULE_PUBLISH_PSMODULE_INPUT_VersionPrefix: ${{ inputs.VersionPrefix }}
10086
PSMODULE_PUBLISH_PSMODULE_INPUT_WhatIf: ${{ inputs.WhatIf }}
101-
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
87+
run: ${{ github.action_path }}/scripts/main.ps1

scripts/helpers/Publish-PSModule.ps1

Lines changed: 30 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
function Publish-PSModule {
22
<#
3-
.SYNOPSIS
4-
Publishes a module to the PowerShell Gallery and GitHub Pages.
3+
.SYNOPSIS
4+
Publishes a module to the PowerShell Gallery and creates a GitHub Release.
55
6-
.DESCRIPTION
7-
Publishes a module to the PowerShell Gallery and GitHub Pages.
6+
.DESCRIPTION
7+
Publishes a module to the PowerShell Gallery and creates a GitHub Release.
88
9-
.EXAMPLE
10-
Publish-PSModule -Name 'PSModule.FX' -APIKey $env:PSGALLERY_API_KEY
9+
.EXAMPLE
10+
Publish-PSModule -Name 'PSModule.FX' -APIKey $env:PSGALLERY_API_KEY
1111
#>
1212
[OutputType([void])]
1313
[CmdletBinding()]
@@ -19,6 +19,10 @@
1919
'PSUseDeclaredVarsMoreThanAssignments', '',
2020
Justification = 'LogGroup - Scoping affects the variables line of sight.'
2121
)]
22+
[Diagnostics.CodeAnalysis.SuppressMessageAttribute(
23+
'PSAvoidUsingWriteHost', '',
24+
Justification = 'Log outputs to GitHub Actions logs.'
25+
)]
2226
param(
2327
# Name of the module to process.
2428
[Parameter()]
@@ -33,7 +37,7 @@
3337
[string] $APIKey
3438
)
3539

36-
LogGroup 'Set configuration' {
40+
Set-GitHubLogGroup 'Set configuration' {
3741
$autoCleanup = $env:PSMODULE_PUBLISH_PSMODULE_INPUT_AutoCleanup -eq 'true'
3842
$autoPatching = $env:PSMODULE_PUBLISH_PSMODULE_INPUT_AutoPatching -eq 'true'
3943
$incrementalPrerelease = $env:PSMODULE_PUBLISH_PSMODULE_INPUT_IncrementalPrerelease -eq 'true'
@@ -59,18 +63,18 @@
5963
} | Format-List | Out-String
6064
}
6165

62-
LogGroup 'Event information - JSON' {
66+
Set-GitHubLogGroup 'Event information - JSON' {
6367
$githubEventJson = Get-Content $env:GITHUB_EVENT_PATH
6468
$githubEventJson | Format-List | Out-String
6569
}
6670

67-
LogGroup 'Event information - Object' {
71+
Set-GitHubLogGroup 'Event information - Object' {
6872
$githubEvent = $githubEventJson | ConvertFrom-Json
6973
$pull_request = $githubEvent.pull_request
7074
$githubEvent | Format-List | Out-String
7175
}
7276

73-
LogGroup 'Event information - Details' {
77+
Set-GitHubLogGroup 'Event information - Details' {
7478
$defaultBranchName = (gh repo view --json defaultBranchRef | ConvertFrom-Json | Select-Object -ExpandProperty defaultBranchRef).name
7579
$isPullRequest = $githubEvent.PSObject.Properties.Name -Contains 'pull_request'
7680
if (-not ($isPullRequest -or $whatIf)) {
@@ -96,17 +100,17 @@
96100
Write-Output '-------------------------------------------------'
97101
}
98102

99-
LogGroup 'Pull request - details' {
103+
Set-GitHubLogGroup 'Pull request - details' {
100104
$pull_request | Format-List | Out-String
101105
}
102106

103-
LogGroup 'Pull request - Labels' {
107+
Set-GitHubLogGroup 'Pull request - Labels' {
104108
$labels = @()
105109
$labels += $pull_request.labels.name
106110
$labels | Format-List | Out-String
107111
}
108112

109-
LogGroup 'Calculate release type' {
113+
Set-GitHubLogGroup 'Calculate release type' {
110114
$createRelease = $isMerged -and $targetIsDefaultBranch
111115
$closedPullRequest = $prIsClosed -and -not $isMerged
112116
$createPrerelease = $labels -Contains 'prerelease' -and -not $createRelease -and -not $closedPullRequest
@@ -134,7 +138,7 @@
134138
Write-Output '-------------------------------------------------'
135139
}
136140

137-
LogGroup 'Get latest version - GitHub' {
141+
Set-GitHubLogGroup 'Get latest version - GitHub' {
138142
$releases = gh release list --json 'createdAt,isDraft,isLatest,isPrerelease,name,publishedAt,tagName' | ConvertFrom-Json
139143
if ($LASTEXITCODE -ne 0) {
140144
Write-Error 'Failed to list all releases for the repo.'
@@ -157,7 +161,7 @@
157161
Write-Output '-------------------------------------------------'
158162
}
159163

160-
LogGroup 'Get latest version - PSGallery' {
164+
Set-GitHubLogGroup 'Get latest version - PSGallery' {
161165
$count = 5
162166
$delay = 10
163167
for ($i = 1; $i -le $count; $i++) {
@@ -186,7 +190,7 @@
186190
Write-Output '-------------------------------------------------'
187191
}
188192

189-
LogGroup 'Get latest version - Manifest' {
193+
Set-GitHubLogGroup 'Get latest version - Manifest' {
190194
Add-PSModulePath -Path (Split-Path -Path $ModulePath -Parent)
191195
$manifestFilePath = Join-Path $ModulePath "$Name.psd1"
192196
Write-Output "Module manifest file path: [$manifestFilePath]"
@@ -208,7 +212,7 @@
208212
Write-Output '-------------------------------------------------'
209213
}
210214

211-
LogGroup 'Get latest version' {
215+
Set-GitHubLogGroup 'Get latest version' {
212216
Write-Output "GitHub: [$($ghReleaseVersion.ToString())]"
213217
Write-Output "PSGallery: [$($psGalleryVersion.ToString())]"
214218
Write-Output "Manifest: [$($manifestVersion.ToString())] (ignored)"
@@ -220,7 +224,7 @@
220224
Write-Output '-------------------------------------------------'
221225
}
222226

223-
LogGroup 'Calculate new version' {
227+
Set-GitHubLogGroup 'Calculate new version' {
224228
# - Increment based on label on PR
225229
$newVersion = New-PSSemVer -Version $latestVersion
226230
$newVersion.Prefix = $versionPrefix
@@ -302,7 +306,7 @@
302306
}
303307
Write-Output "New version is [$($newVersion.ToString())]"
304308

305-
LogGroup 'Update module manifest' {
309+
Set-GitHubLogGroup 'Update module manifest' {
306310
Write-Output 'Bump module version -> module metadata: Update-ModuleMetadata'
307311
$manifestNewVersion = "$($newVersion.Major).$($newVersion.Minor).$($newVersion.Patch)"
308312
Set-ModuleManifest -Path $manifestFilePath -ModuleVersion $manifestNewVersion -Verbose:$false
@@ -314,12 +318,12 @@
314318
Show-FileContent -Path $manifestFilePath
315319
}
316320

317-
LogGroup 'Install module dependencies' {
321+
Set-GitHubLogGroup 'Install module dependencies' {
318322
Resolve-PSModuleDependency -ManifestFilePath $manifestFilePath
319323
}
320324

321325
if ($createPrerelease -or $createRelease -or $whatIf) {
322-
LogGroup 'Publish-ToPSGallery' {
326+
Set-GitHubLogGroup 'Publish-ToPSGallery' {
323327
if ($createPrerelease) {
324328
$publishPSVersion = "$($newVersion.Major).$($newVersion.Minor).$($newVersion.Patch)-$($newVersion.Prerelease)"
325329
} else {
@@ -343,7 +347,7 @@
343347
" PowerShell Gallery [$publishPSVersion]($psGalleryReleaseLink) has been created.'"
344348
)
345349
} else {
346-
Write-GitHubNotice "Module [$Name - $publishPSVersion] published to the PowerShell Gallery."
350+
Write-Host "::notice::Module [$Name - $publishPSVersion] published to the PowerShell Gallery."
347351
gh pr comment $pull_request.number -b "Module [$Name - $publishPSVersion]($psGalleryReleaseLink) published to the PowerShell Gallery."
348352
if ($LASTEXITCODE -ne 0) {
349353
Write-Error 'Failed to comment on the pull request.'
@@ -352,7 +356,7 @@
352356
}
353357
}
354358

355-
LogGroup 'New-GitHubRelease' {
359+
Set-GitHubLogGroup 'New-GitHubRelease' {
356360
Write-Output 'Create new GitHub release'
357361
if ($createPrerelease) {
358362
if ($whatIf) {
@@ -384,17 +388,17 @@
384388
exit $LASTEXITCODE
385389
}
386390
}
387-
Write-GitHubNotice "Release created: [$newVersion]"
391+
Write-Host "::notice::Release created: [$newVersion]"
388392
}
389393
}
390394

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

396400
if ((($closedPullRequest -or $createRelease) -and $autoCleanup) -or $whatIf) {
397-
LogGroup "Cleanup prereleases for [$prereleaseName]" {
401+
Set-GitHubLogGroup "Cleanup prereleases for [$prereleaseName]" {
398402
foreach ($rel in $prereleasesToCleanup) {
399403
$relTagName = $rel.tagName
400404
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)