|
1 | 1 | function Publish-PSModule {
|
2 | 2 | <#
|
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. |
5 | 5 |
|
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. |
8 | 8 |
|
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 |
11 | 11 | #>
|
12 | 12 | [OutputType([void])]
|
13 | 13 | [CmdletBinding()]
|
|
19 | 19 | 'PSUseDeclaredVarsMoreThanAssignments', '',
|
20 | 20 | Justification = 'LogGroup - Scoping affects the variables line of sight.'
|
21 | 21 | )]
|
| 22 | + [Diagnostics.CodeAnalysis.SuppressMessageAttribute( |
| 23 | + 'PSAvoidUsingWriteHost', '', |
| 24 | + Justification = 'Log outputs to GitHub Actions logs.' |
| 25 | + )] |
22 | 26 | param(
|
23 | 27 | # Name of the module to process.
|
24 | 28 | [Parameter()]
|
|
33 | 37 | [string] $APIKey
|
34 | 38 | )
|
35 | 39 |
|
36 |
| - LogGroup 'Set configuration' { |
| 40 | + Set-GitHubLogGroup 'Set configuration' { |
37 | 41 | $autoCleanup = $env:PSMODULE_PUBLISH_PSMODULE_INPUT_AutoCleanup -eq 'true'
|
38 | 42 | $autoPatching = $env:PSMODULE_PUBLISH_PSMODULE_INPUT_AutoPatching -eq 'true'
|
39 | 43 | $incrementalPrerelease = $env:PSMODULE_PUBLISH_PSMODULE_INPUT_IncrementalPrerelease -eq 'true'
|
|
59 | 63 | } | Format-List | Out-String
|
60 | 64 | }
|
61 | 65 |
|
62 |
| - LogGroup 'Event information - JSON' { |
| 66 | + Set-GitHubLogGroup 'Event information - JSON' { |
63 | 67 | $githubEventJson = Get-Content $env:GITHUB_EVENT_PATH
|
64 | 68 | $githubEventJson | Format-List | Out-String
|
65 | 69 | }
|
66 | 70 |
|
67 |
| - LogGroup 'Event information - Object' { |
| 71 | + Set-GitHubLogGroup 'Event information - Object' { |
68 | 72 | $githubEvent = $githubEventJson | ConvertFrom-Json
|
69 | 73 | $pull_request = $githubEvent.pull_request
|
70 | 74 | $githubEvent | Format-List | Out-String
|
71 | 75 | }
|
72 | 76 |
|
73 |
| - LogGroup 'Event information - Details' { |
| 77 | + Set-GitHubLogGroup 'Event information - Details' { |
74 | 78 | $defaultBranchName = (gh repo view --json defaultBranchRef | ConvertFrom-Json | Select-Object -ExpandProperty defaultBranchRef).name
|
75 | 79 | $isPullRequest = $githubEvent.PSObject.Properties.Name -Contains 'pull_request'
|
76 | 80 | if (-not ($isPullRequest -or $whatIf)) {
|
|
96 | 100 | Write-Output '-------------------------------------------------'
|
97 | 101 | }
|
98 | 102 |
|
99 |
| - LogGroup 'Pull request - details' { |
| 103 | + Set-GitHubLogGroup 'Pull request - details' { |
100 | 104 | $pull_request | Format-List | Out-String
|
101 | 105 | }
|
102 | 106 |
|
103 |
| - LogGroup 'Pull request - Labels' { |
| 107 | + Set-GitHubLogGroup 'Pull request - Labels' { |
104 | 108 | $labels = @()
|
105 | 109 | $labels += $pull_request.labels.name
|
106 | 110 | $labels | Format-List | Out-String
|
107 | 111 | }
|
108 | 112 |
|
109 |
| - LogGroup 'Calculate release type' { |
| 113 | + Set-GitHubLogGroup 'Calculate release type' { |
110 | 114 | $createRelease = $isMerged -and $targetIsDefaultBranch
|
111 | 115 | $closedPullRequest = $prIsClosed -and -not $isMerged
|
112 | 116 | $createPrerelease = $labels -Contains 'prerelease' -and -not $createRelease -and -not $closedPullRequest
|
|
134 | 138 | Write-Output '-------------------------------------------------'
|
135 | 139 | }
|
136 | 140 |
|
137 |
| - LogGroup 'Get latest version - GitHub' { |
| 141 | + Set-GitHubLogGroup 'Get latest version - GitHub' { |
138 | 142 | $releases = gh release list --json 'createdAt,isDraft,isLatest,isPrerelease,name,publishedAt,tagName' | ConvertFrom-Json
|
139 | 143 | if ($LASTEXITCODE -ne 0) {
|
140 | 144 | Write-Error 'Failed to list all releases for the repo.'
|
|
157 | 161 | Write-Output '-------------------------------------------------'
|
158 | 162 | }
|
159 | 163 |
|
160 |
| - LogGroup 'Get latest version - PSGallery' { |
| 164 | + Set-GitHubLogGroup 'Get latest version - PSGallery' { |
161 | 165 | $count = 5
|
162 | 166 | $delay = 10
|
163 | 167 | for ($i = 1; $i -le $count; $i++) {
|
|
186 | 190 | Write-Output '-------------------------------------------------'
|
187 | 191 | }
|
188 | 192 |
|
189 |
| - LogGroup 'Get latest version - Manifest' { |
| 193 | + Set-GitHubLogGroup 'Get latest version - Manifest' { |
190 | 194 | Add-PSModulePath -Path (Split-Path -Path $ModulePath -Parent)
|
191 | 195 | $manifestFilePath = Join-Path $ModulePath "$Name.psd1"
|
192 | 196 | Write-Output "Module manifest file path: [$manifestFilePath]"
|
|
208 | 212 | Write-Output '-------------------------------------------------'
|
209 | 213 | }
|
210 | 214 |
|
211 |
| - LogGroup 'Get latest version' { |
| 215 | + Set-GitHubLogGroup 'Get latest version' { |
212 | 216 | Write-Output "GitHub: [$($ghReleaseVersion.ToString())]"
|
213 | 217 | Write-Output "PSGallery: [$($psGalleryVersion.ToString())]"
|
214 | 218 | Write-Output "Manifest: [$($manifestVersion.ToString())] (ignored)"
|
|
220 | 224 | Write-Output '-------------------------------------------------'
|
221 | 225 | }
|
222 | 226 |
|
223 |
| - LogGroup 'Calculate new version' { |
| 227 | + Set-GitHubLogGroup 'Calculate new version' { |
224 | 228 | # - Increment based on label on PR
|
225 | 229 | $newVersion = New-PSSemVer -Version $latestVersion
|
226 | 230 | $newVersion.Prefix = $versionPrefix
|
|
302 | 306 | }
|
303 | 307 | Write-Output "New version is [$($newVersion.ToString())]"
|
304 | 308 |
|
305 |
| - LogGroup 'Update module manifest' { |
| 309 | + Set-GitHubLogGroup 'Update module manifest' { |
306 | 310 | Write-Output 'Bump module version -> module metadata: Update-ModuleMetadata'
|
307 | 311 | $manifestNewVersion = "$($newVersion.Major).$($newVersion.Minor).$($newVersion.Patch)"
|
308 | 312 | Set-ModuleManifest -Path $manifestFilePath -ModuleVersion $manifestNewVersion -Verbose:$false
|
|
314 | 318 | Show-FileContent -Path $manifestFilePath
|
315 | 319 | }
|
316 | 320 |
|
317 |
| - LogGroup 'Install module dependencies' { |
| 321 | + Set-GitHubLogGroup 'Install module dependencies' { |
318 | 322 | Resolve-PSModuleDependency -ManifestFilePath $manifestFilePath
|
319 | 323 | }
|
320 | 324 |
|
321 | 325 | if ($createPrerelease -or $createRelease -or $whatIf) {
|
322 |
| - LogGroup 'Publish-ToPSGallery' { |
| 326 | + Set-GitHubLogGroup 'Publish-ToPSGallery' { |
323 | 327 | if ($createPrerelease) {
|
324 | 328 | $publishPSVersion = "$($newVersion.Major).$($newVersion.Minor).$($newVersion.Patch)-$($newVersion.Prerelease)"
|
325 | 329 | } else {
|
|
343 | 347 | " PowerShell Gallery [$publishPSVersion]($psGalleryReleaseLink) has been created.'"
|
344 | 348 | )
|
345 | 349 | } else {
|
346 |
| - Write-GitHubNotice "Module [$Name - $publishPSVersion] published to the PowerShell Gallery." |
| 350 | + Write-Host "::notice::Module [$Name - $publishPSVersion] published to the PowerShell Gallery." |
347 | 351 | gh pr comment $pull_request.number -b "Module [$Name - $publishPSVersion]($psGalleryReleaseLink) published to the PowerShell Gallery."
|
348 | 352 | if ($LASTEXITCODE -ne 0) {
|
349 | 353 | Write-Error 'Failed to comment on the pull request.'
|
|
352 | 356 | }
|
353 | 357 | }
|
354 | 358 |
|
355 |
| - LogGroup 'New-GitHubRelease' { |
| 359 | + Set-GitHubLogGroup 'New-GitHubRelease' { |
356 | 360 | Write-Output 'Create new GitHub release'
|
357 | 361 | if ($createPrerelease) {
|
358 | 362 | if ($whatIf) {
|
|
384 | 388 | exit $LASTEXITCODE
|
385 | 389 | }
|
386 | 390 | }
|
387 |
| - Write-GitHubNotice "Release created: [$newVersion]" |
| 391 | + Write-Host "::notice::Release created: [$newVersion]" |
388 | 392 | }
|
389 | 393 | }
|
390 | 394 |
|
391 |
| - LogGroup 'List prereleases using the same name' { |
| 395 | + Set-GitHubLogGroup 'List prereleases using the same name' { |
392 | 396 | $prereleasesToCleanup = $releases | Where-Object { $_.tagName -like "*$prereleaseName*" }
|
393 | 397 | $prereleasesToCleanup | Select-Object -Property name, publishedAt, isPrerelease, isLatest | Format-Table | Out-String
|
394 | 398 | }
|
395 | 399 |
|
396 | 400 | if ((($closedPullRequest -or $createRelease) -and $autoCleanup) -or $whatIf) {
|
397 |
| - LogGroup "Cleanup prereleases for [$prereleaseName]" { |
| 401 | + Set-GitHubLogGroup "Cleanup prereleases for [$prereleaseName]" { |
398 | 402 | foreach ($rel in $prereleasesToCleanup) {
|
399 | 403 | $relTagName = $rel.tagName
|
400 | 404 | Write-Output "Deleting prerelease: [$relTagName]."
|
|
0 commit comments