diff --git a/.github/linters/.jscpd.json b/.github/linters/.jscpd.json deleted file mode 100644 index 23970e8..0000000 --- a/.github/linters/.jscpd.json +++ /dev/null @@ -1,10 +0,0 @@ -{ - "threshold": 0, - "reporters": [ - "consoleFull" - ], - "ignore": [ - "**/tests/**" - ], - "absolute": true -} diff --git a/.github/linters/.powershell-psscriptanalyzer.psd1 b/.github/linters/.powershell-psscriptanalyzer.psd1 index 09cc3d0..f79ca2a 100644 --- a/.github/linters/.powershell-psscriptanalyzer.psd1 +++ b/.github/linters/.powershell-psscriptanalyzer.psd1 @@ -50,6 +50,7 @@ } } ExcludeRules = @( + 'PSAvoidUsingWriteHost', # This action runs on GitHub Actions which supports Write-Host. 'PSMissingModuleManifestField', # This rule is not applicable until the module is built. 'PSUseToExportFieldsInManifest' ) diff --git a/.github/release.yml b/.github/release.yml deleted file mode 100644 index 35c6ae8..0000000 --- a/.github/release.yml +++ /dev/null @@ -1,18 +0,0 @@ -# https://docs.github.com/en/repositories/releasing-projects-on-github/automatically-generated-release-notes#configuring-automatically-generated-release-notes - -changelog: - exclude: - labels: - - NoRelease - categories: - - title: 🌟 Breaking Changes - labels: - - Major - - Breaking - - title: 🚀 New Features - labels: - - Minor - - Feature - - title: Other Changes - labels: - - '*' diff --git a/.github/workflows/Linter.yml b/.github/workflows/Linter.yml index 377763a..3a07190 100644 --- a/.github/workflows/Linter.yml +++ b/.github/workflows/Linter.yml @@ -29,6 +29,7 @@ jobs: env: GITHUB_TOKEN: ${{ github.token }} VALIDATE_BIOME_FORMAT: false + VALIDATE_JSCPD: false VALIDATE_JSON_PRETTIER: false VALIDATE_MARKDOWN_PRETTIER: false VALIDATE_YAML_PRETTIER: false diff --git a/.github/workflows/Auto-Release.yml b/.github/workflows/Release.yml similarity index 63% rename from .github/workflows/Auto-Release.yml rename to .github/workflows/Release.yml index 643724c..15ea61e 100644 --- a/.github/workflows/Auto-Release.yml +++ b/.github/workflows/Release.yml @@ -1,6 +1,6 @@ -name: Auto-Release +name: Release -run-name: "Auto-Release - [${{ github.event.pull_request.title }} #${{ github.event.pull_request.number }}] by @${{ github.actor }}" +run-name: "Release - [${{ github.event.pull_request.title }} #${{ github.event.pull_request.number }}] by @${{ github.actor }}" on: pull_request: @@ -12,6 +12,9 @@ on: - reopened - synchronize - labeled + paths: + - 'action.yml' + - 'src/**' concurrency: group: ${{ github.workflow }}-${{ github.ref }} @@ -22,7 +25,7 @@ permissions: pull-requests: write jobs: - Auto-Release: + Release: runs-on: ubuntu-latest steps: - name: Checkout Code @@ -30,7 +33,7 @@ jobs: with: persist-credentials: false - - name: Auto-Release - uses: PSModule/Auto-Release@eabd533035e2cb9822160f26f2eda584bd012356 # v1.9.5 + - name: Release + uses: PSModule/Release-GHRepository@88c70461c8f16cc09682005bcf3b7fca4dd8dc1a # v2.0.1 with: IncrementalPrerelease: false diff --git a/action.yml b/action.yml index 9e70917..65b04cc 100644 --- a/action.yml +++ b/action.yml @@ -22,7 +22,7 @@ inputs: required: false default: 'true' IncrementalPrerelease: - description: Control wether to automatically increment the prerelease number. If disabled, the action will ensure only one prerelease exists for a given branch. + description: Control whether to automatically increment the prerelease number. If disabled, the action will ensure only one prerelease exists for a given branch. required: false default: 'true' DatePrereleaseFormat: @@ -102,7 +102,7 @@ runs: PSMODULE_PUBLISH_PSMODULE_INPUT_PatchLabels: ${{ inputs.PatchLabels }} PSMODULE_PUBLISH_PSMODULE_INPUT_VersionPrefix: ${{ inputs.VersionPrefix }} PSMODULE_PUBLISH_PSMODULE_INPUT_WhatIf: ${{ inputs.WhatIf }} - run: ${{ github.action_path }}/scripts/init.ps1 + run: ${{ github.action_path }}/src/init.ps1 - name: Download module artifact if: env.PUBLISH_CONTEXT_ShouldPublish == 'true' || inputs.WhatIf == 'true' @@ -123,7 +123,7 @@ runs: PSMODULE_PUBLISH_PSMODULE_INPUT_UsePRBodyAsReleaseNotes: ${{ inputs.UsePRBodyAsReleaseNotes }} PSMODULE_PUBLISH_PSMODULE_INPUT_UsePRTitleAsReleaseName: ${{ inputs.UsePRTitleAsReleaseName }} PSMODULE_PUBLISH_PSMODULE_INPUT_UsePRTitleAsNotesHeading: ${{ inputs.UsePRTitleAsNotesHeading }} - run: ${{ github.action_path }}/scripts/publish.ps1 + run: ${{ github.action_path }}/src/publish.ps1 - name: Cleanup Prereleases if: env.PUBLISH_CONTEXT_ShouldCleanup == 'true' || inputs.WhatIf == 'true' @@ -131,4 +131,4 @@ runs: working-directory: ${{ inputs.WorkingDirectory }} env: PSMODULE_PUBLISH_PSMODULE_INPUT_WhatIf: ${{ inputs.WhatIf }} - run: ${{ github.action_path }}/scripts/cleanup.ps1 + run: ${{ github.action_path }}/src/cleanup.ps1 diff --git a/scripts/cleanup.ps1 b/src/cleanup.ps1 similarity index 68% rename from scripts/cleanup.ps1 rename to src/cleanup.ps1 index 2363894..cc2fc6e 100644 --- a/scripts/cleanup.ps1 +++ b/src/cleanup.ps1 @@ -1,6 +1,8 @@ [CmdletBinding()] param() +$PSStyle.OutputRendering = 'Ansi' + Import-Module -Name 'Helpers' -Force $prereleaseName = $env:PUBLISH_CONTEXT_PrereleaseName @@ -14,32 +16,32 @@ if ([string]::IsNullOrWhiteSpace($prereleaseName)) { LogGroup "Cleanup prereleases for [$prereleaseName]" { if ([string]::IsNullOrWhiteSpace($prereleaseTagsToCleanup)) { - Write-Output "No prereleases found to cleanup for [$prereleaseName]." + Write-Host "No prereleases found to cleanup for [$prereleaseName]." return } $tagsToDelete = $prereleaseTagsToCleanup -split ',' | Where-Object { -not [string]::IsNullOrWhiteSpace($_) } if ($tagsToDelete.Count -eq 0) { - Write-Output "No prereleases found to cleanup for [$prereleaseName]." + Write-Host "No prereleases found to cleanup for [$prereleaseName]." return } - Write-Output "Found $($tagsToDelete.Count) prereleases to cleanup:" - $tagsToDelete | ForEach-Object { Write-Output " - $_" } - Write-Output '' + Write-Host "Found $($tagsToDelete.Count) prereleases to cleanup:" + $tagsToDelete | ForEach-Object { Write-Host " - $_" } + Write-Host '' foreach ($tag in $tagsToDelete) { - Write-Output "Deleting prerelease: [$tag]" + Write-Host "Deleting prerelease: [$tag]" if ($whatIf) { - Write-Output "WhatIf: gh release delete $tag --cleanup-tag --yes" + Write-Host "WhatIf: gh release delete $tag --cleanup-tag --yes" } else { gh release delete $tag --cleanup-tag --yes if ($LASTEXITCODE -ne 0) { Write-Error "Failed to delete release [$tag]." exit $LASTEXITCODE } - Write-Output "Successfully deleted release [$tag]." + Write-Host "Successfully deleted release [$tag]." } } diff --git a/scripts/init.ps1 b/src/init.ps1 similarity index 72% rename from scripts/init.ps1 rename to src/init.ps1 index d562d48..aec82f3 100644 --- a/scripts/init.ps1 +++ b/src/init.ps1 @@ -1,6 +1,16 @@ -[CmdletBinding()] +[Diagnostics.CodeAnalysis.SuppressMessageAttribute( + 'PSUseDeclaredVarsMoreThanAssignments', 'pull_request', + Justification = 'Variable is used in script blocks.' +)] +[Diagnostics.CodeAnalysis.SuppressMessageAttribute( + 'PSUseDeclaredVarsMoreThanAssignments', 'prereleaseName', + Justification = 'Variable is used in script blocks.' +)] +[CmdletBinding()] param() +$PSStyle.OutputRendering = 'Ansi' + Import-Module -Name 'Helpers' -Force LogGroup 'Install dependencies' { @@ -29,7 +39,7 @@ LogGroup 'Load inputs' { } else { $env:PSMODULE_PUBLISH_PSMODULE_INPUT_Name } - Write-Output "Module name: [$name]" + Write-Host "Module name: [$name]" } LogGroup 'Set configuration' { @@ -51,6 +61,7 @@ LogGroup 'Set configuration' { Write-Host "::warning::$message" } + Write-Host '-------------------------------------------------' [pscustomobject]@{ AutoCleanup = $autoCleanup AutoPatching = $autoPatching @@ -64,17 +75,22 @@ LogGroup 'Set configuration' { MinorLabels = $minorLabels PatchLabels = $patchLabels } | Format-List | Out-String + Write-Host '-------------------------------------------------' } LogGroup 'Event information - JSON' { $githubEventJson = Get-Content $env:GITHUB_EVENT_PATH + Write-Host '-------------------------------------------------' $githubEventJson | Format-List | Out-String + Write-Host '-------------------------------------------------' } LogGroup 'Event information - Object' { $githubEvent = $githubEventJson | ConvertFrom-Json $pull_request = $githubEvent.pull_request + Write-Host '-------------------------------------------------' $githubEvent | Format-List | Out-String + Write-Host '-------------------------------------------------' } LogGroup 'Event information - Details' { @@ -83,20 +99,26 @@ LogGroup 'Event information - Details' { } $prHeadRef = $pull_request.head.ref - Write-Output '-------------------------------------------------' - Write-Output "PR Head Ref: [$prHeadRef]" - Write-Output "ReleaseType: [$releaseType]" - Write-Output '-------------------------------------------------' + Write-Host '-------------------------------------------------' + [PSCustomObject]@{ + PRHeadRef = $prHeadRef + ReleaseType = $releaseType + } | Format-List | Out-String + Write-Host '-------------------------------------------------' } LogGroup 'Pull request - details' { + Write-Host '-------------------------------------------------' $pull_request | Format-List | Out-String + Write-Host '-------------------------------------------------' } LogGroup 'Pull request - Labels' { $labels = @() $labels += $pull_request.labels.name + Write-Host '-------------------------------------------------' $labels | Format-List | Out-String + Write-Host '-------------------------------------------------' } LogGroup 'Determine release configuration' { @@ -122,7 +144,7 @@ LogGroup 'Determine release configuration' { # Check for ignore labels that override the release type $ignoreRelease = ($labels | Where-Object { $ignoreLabels -contains $_ }).Count -gt 0 if ($ignoreRelease -and $shouldPublish) { - Write-Output 'Ignoring release creation due to ignore label.' + Write-Host 'Ignoring release creation due to ignore label.' $shouldPublish = $false } @@ -141,23 +163,25 @@ LogGroup 'Determine release configuration' { $hasVersionBump = $majorRelease -or $minorRelease -or $patchRelease if (-not $hasVersionBump) { - Write-Output 'No version bump label found and AutoPatching is disabled. Skipping publish.' + Write-Host 'No version bump label found and AutoPatching is disabled. Skipping publish.' $shouldPublish = $false } } elseif (-not $ignoreRelease) { - Write-Output "ReleaseType is [$releaseType]. No publishing required." + Write-Host "ReleaseType is [$releaseType]. No publishing required." } - Write-Output '-------------------------------------------------' - Write-Output "ReleaseType: [$releaseType]" - Write-Output "AutoCleanup: [$autoCleanup]" - Write-Output "Should publish: [$shouldPublish]" - Write-Output "Create a release: [$createRelease]" - Write-Output "Create a prerelease: [$createPrerelease]" - Write-Output "Create a major release: [$majorRelease]" - Write-Output "Create a minor release: [$minorRelease]" - Write-Output "Create a patch release: [$patchRelease]" - Write-Output '-------------------------------------------------' + Write-Host '-------------------------------------------------' + [PSCustomObject]@{ + ReleaseType = $releaseType + AutoCleanup = $autoCleanup + ShouldPublish = $shouldPublish + CreateRelease = $createRelease + CreatePrerelease = $createPrerelease + CreateMajor = $majorRelease + CreateMinor = $minorRelease + CreatePatch = $patchRelease + } | Format-List | Out-String + Write-Host '-------------------------------------------------' } #endregion Calculate release type @@ -175,7 +199,9 @@ if ($shouldPublish -or $autoCleanup) { Write-Error 'Failed to list all releases for the repo.' exit $LASTEXITCODE } + Write-Host '-------------------------------------------------' $releases | Select-Object -Property name, isPrerelease, isLatest, publishedAt | Format-Table | Out-String + Write-Host '-------------------------------------------------' } #endregion Get releases } @@ -185,6 +211,7 @@ if ($shouldPublish) { #region Get versions LogGroup 'Get latest version - GitHub' { $latestRelease = $releases | Where-Object { $_.isLatest -eq $true } + Write-Host '-------------------------------------------------' $latestRelease | Format-List | Out-String $ghReleaseVersionString = $latestRelease.tagName if (-not [string]::IsNullOrEmpty($ghReleaseVersionString)) { @@ -193,10 +220,10 @@ if ($shouldPublish) { Write-Warning 'Could not find the latest release version. Using ''0.0.0'' as the version.' $ghReleaseVersion = New-PSSemVer -Version '0.0.0' } - Write-Output '-------------------------------------------------' - Write-Output 'GitHub version:' - Write-Output $ghReleaseVersion.ToString() - Write-Output '-------------------------------------------------' + Write-Host '-------------------------------------------------' + Write-Host 'GitHub version:' + Write-Host $ghReleaseVersion.ToString() + Write-Host '-------------------------------------------------' } LogGroup 'Get latest version - PSGallery' { @@ -204,9 +231,9 @@ if ($shouldPublish) { $delay = 10 for ($i = 1; $i -le $count; $i++) { try { - Write-Output "Finding module [$name] in the PowerShell Gallery." + Write-Host "Finding module [$name] in the PowerShell Gallery." $latest = Find-PSResource -Name $name -Repository PSGallery -Verbose:$false - Write-Output "$($latest | Format-Table | Out-String)" + Write-Host "$($latest | Format-Table | Out-String)" break } catch { if ($i -eq $count) { @@ -222,21 +249,21 @@ if ($shouldPublish) { Write-Warning 'Could not find module online. Using ''0.0.0'' as the version.' $psGalleryVersion = New-PSSemVer -Version '0.0.0' } - Write-Output '-------------------------------------------------' - Write-Output 'PSGallery version:' - Write-Output $psGalleryVersion.ToString() - Write-Output '-------------------------------------------------' + Write-Host '-------------------------------------------------' + Write-Host 'PSGallery version:' + Write-Host $psGalleryVersion.ToString() + Write-Host '-------------------------------------------------' } LogGroup 'Get latest version' { - Write-Output "GitHub: [$($ghReleaseVersion.ToString())]" - Write-Output "PSGallery: [$($psGalleryVersion.ToString())]" + Write-Host "GitHub: [$($ghReleaseVersion.ToString())]" + Write-Host "PSGallery: [$($psGalleryVersion.ToString())]" $latestVersion = New-PSSemVer -Version ($psGalleryVersion, $ghReleaseVersion | Sort-Object -Descending | Select-Object -First 1) - Write-Output '-------------------------------------------------' - Write-Output 'Latest version:' - Write-Output ($latestVersion | Format-Table | Out-String) - Write-Output $latestVersion.ToString() - Write-Output '-------------------------------------------------' + Write-Host '-------------------------------------------------' + Write-Host 'Latest version:' + Write-Host ($latestVersion | Format-Table | Out-String) + Write-Host $latestVersion.ToString() + Write-Host '-------------------------------------------------' } LogGroup 'Calculate new version' { @@ -244,32 +271,32 @@ if ($shouldPublish) { $newVersion = New-PSSemVer -Version $latestVersion $newVersion.Prefix = $versionPrefix if ($majorRelease) { - Write-Output 'Incrementing major version.' + Write-Host 'Incrementing major version.' $newVersion.BumpMajor() } elseif ($minorRelease) { - Write-Output 'Incrementing minor version.' + Write-Host 'Incrementing minor version.' $newVersion.BumpMinor() } elseif ($patchRelease) { - Write-Output 'Incrementing patch version.' + Write-Host 'Incrementing patch version.' $newVersion.BumpPatch() } else { - Write-Output 'No version bump required.' + Write-Host 'No version bump required.' } - Write-Output "Partial new version: [$newVersion]" + Write-Host "Partial new version: [$newVersion]" if ($createPrerelease -and $hasVersionBump) { - Write-Output "Adding a prerelease tag to the version using the branch name [$prereleaseName]." - Write-Output ($releases | Where-Object { $_.tagName -like "*$prereleaseName*" } | + Write-Host "Adding a prerelease tag to the version using the branch name [$prereleaseName]." + Write-Host ($releases | Where-Object { $_.tagName -like "*$prereleaseName*" } | Select-Object -Property name, isPrerelease, isLatest, publishedAt | Format-Table -AutoSize | Out-String) $newVersion.Prerelease = $prereleaseName - Write-Output "Partial new version: [$newVersion]" + Write-Host "Partial new version: [$newVersion]" if (-not [string]::IsNullOrEmpty($datePrereleaseFormat)) { - Write-Output "Using date-based prerelease: [$datePrereleaseFormat]." + Write-Host "Using date-based prerelease: [$datePrereleaseFormat]." $newVersion.Prerelease += "$(Get-Date -Format $datePrereleaseFormat)" - Write-Output "Partial new version: [$newVersion]" + Write-Host "Partial new version: [$newVersion]" } if ($incrementalPrerelease) { @@ -285,15 +312,15 @@ if ($shouldPublish) { Verbose = $false ErrorAction = 'SilentlyContinue' } - Write-Output 'Finding the latest prerelease version in the PowerShell Gallery.' - Write-Output ($params | Format-Table | Out-String) + Write-Host 'Finding the latest prerelease version in the PowerShell Gallery.' + Write-Host ($params | Format-Table | Out-String) $psGalleryPrereleases = Find-PSResource @params $psGalleryPrereleases = $psGalleryPrereleases | Where-Object { $_.Version -like "$newVersionString" } $psGalleryPrereleases = $psGalleryPrereleases | Where-Object { $_.Prerelease -like "$prereleaseName*" } $latestPSGalleryPrerelease = $psGalleryPrereleases.Prerelease | ForEach-Object { [int]($_ -replace $prereleaseName) } | Sort-Object | Select-Object -Last 1 - Write-Output "PSGallery prerelease: [$latestPSGalleryPrerelease]" + Write-Host "PSGallery prerelease: [$latestPSGalleryPrerelease]" # GitHub $ghPrereleases = $releases | Where-Object { $_.tagName -like "*$newVersionString*" } @@ -304,7 +331,7 @@ if ($shouldPublish) { $number = ($number -split $prereleaseName, 2)[-1] [int]$number } | Sort-Object | Select-Object -Last 1 - Write-Output "GitHub prerelease: [$latestGHPrereleases]" + Write-Host "GitHub prerelease: [$latestGHPrereleases]" # Handle null values explicitly to ensure Math.Max works correctly if ($null -eq $latestPSGalleryPrerelease) { $latestPSGalleryPrerelease = 0 } @@ -316,11 +343,12 @@ if ($shouldPublish) { $newVersion.Prerelease += $latestPrereleaseNumber } } - Write-Output '-------------------------------------------------' - Write-Output 'New version:' - Write-Output ($newVersion | Format-Table | Out-String) - Write-Output $newVersion.ToString() - Write-Output '-------------------------------------------------' + Write-Host '-------------------------------------------------' + Write-Host 'New version:' + $newVersion | Format-Table | Out-String + Write-Host '-------------------------------------------------' + Write-Host $newVersion.ToString() + Write-Host '-------------------------------------------------' } #endregion Calculate new version } @@ -330,9 +358,11 @@ if ($shouldPublish) { if ($autoCleanup) { LogGroup 'Find prereleases to cleanup' { $prereleasesToCleanup = $releases | Where-Object { $_.tagName -like "*$prereleaseName*" } + Write-Host '-------------------------------------------------' $prereleasesToCleanup | Select-Object -Property name, publishedAt, isPrerelease, isLatest | Format-Table | Out-String + Write-Host '-------------------------------------------------' $prereleaseTagsToCleanup = ($prereleasesToCleanup | ForEach-Object { $_.tagName }) -join ',' - Write-Output "Prereleases to cleanup: [$prereleaseTagsToCleanup]" + Write-Host "Prereleases to cleanup: [$prereleaseTagsToCleanup]" } } #endregion Find prereleases to cleanup @@ -354,8 +384,8 @@ LogGroup 'Store context in environment variables' { Add-Content -Path $env:GITHUB_ENV -Value "PUBLISH_CONTEXT_PRNumber=$($pull_request.number.ToString())" Add-Content -Path $env:GITHUB_ENV -Value "PUBLISH_CONTEXT_PRHeadRef=$prHeadRef" - Write-Output '-------------------------------------------------' - Write-Output 'Stored environment variables:' + Write-Host '-------------------------------------------------' + Write-Host 'Stored environment variables:' [PSCustomObject]@{ ShouldPublish = $shouldPublish ShouldCleanup = $autoCleanup @@ -370,7 +400,7 @@ LogGroup 'Store context in environment variables' { PRNumber = $pull_request.number PRHeadRef = $prHeadRef } | Format-List | Out-String - Write-Output '-------------------------------------------------' + Write-Host '-------------------------------------------------' } -Write-Output "Context initialization complete. ShouldPublish=[$shouldPublish], ShouldCleanup=[$autoCleanup]" +Write-Host "Context initialization complete. ShouldPublish=[$shouldPublish], ShouldCleanup=[$autoCleanup]" diff --git a/scripts/publish.ps1 b/src/publish.ps1 similarity index 68% rename from scripts/publish.ps1 rename to src/publish.ps1 index 6f074ce..7e4afc3 100644 --- a/scripts/publish.ps1 +++ b/src/publish.ps1 @@ -1,6 +1,24 @@ -[CmdletBinding()] +[Diagnostics.CodeAnalysis.SuppressMessageAttribute( + 'PSUseDeclaredVarsMoreThanAssignments', 'apiKey', + Justification = 'Variable is used in script blocks.' +)] +[Diagnostics.CodeAnalysis.SuppressMessageAttribute( + 'PSUseDeclaredVarsMoreThanAssignments', 'usePRBodyAsReleaseNotes', + Justification = 'Variable is used in script blocks.' +)] +[Diagnostics.CodeAnalysis.SuppressMessageAttribute( + 'PSUseDeclaredVarsMoreThanAssignments', 'usePRTitleAsReleaseName', + Justification = 'Variable is used in script blocks.' +)] +[Diagnostics.CodeAnalysis.SuppressMessageAttribute( + 'PSUseDeclaredVarsMoreThanAssignments', 'usePRTitleAsNotesHeading', + Justification = 'Variable is used in script blocks.' +)] +[CmdletBinding()] param() +$PSStyle.OutputRendering = 'Ansi' + Import-Module -Name 'Helpers' -Force LogGroup 'Load inputs' { @@ -14,8 +32,8 @@ LogGroup 'Load inputs' { $modulePath = Resolve-Path -Path "$env:PSMODULE_PUBLISH_PSMODULE_INPUT_ModulePath/$name" | Select-Object -ExpandProperty Path $apiKey = $env:PSMODULE_PUBLISH_PSMODULE_INPUT_APIKey - Write-Output "Module name: [$name]" - Write-Output "Module path: [$modulePath]" + Write-Host "Module name: [$name]" + Write-Host "Module path: [$modulePath]" } LogGroup 'Load publish context from environment' { @@ -36,15 +54,16 @@ LogGroup 'Load publish context from environment' { $newVersion = New-PSSemVer -Version $newVersionString - Write-Output '-------------------------------------------------' - Write-Output 'Publish context:' - Write-Output " CreateRelease: [$createRelease]" - Write-Output " CreatePrerelease: [$createPrerelease]" - Write-Output " NewVersion: [$($newVersion.ToString())]" - Write-Output " PRNumber: [$prNumber]" - Write-Output " PRHeadRef: [$prHeadRef]" - Write-Output " WhatIf: [$whatIf]" - Write-Output '-------------------------------------------------' + Write-Host '-------------------------------------------------' + [PSCustomObject]@{ + CreateRelease = $createRelease + CreatePrerelease = $createPrerelease + NewVersion = $newVersion.ToString() + PRNumber = $prNumber + PRHeadRef = $prHeadRef + WhatIf = $whatIf + } | Format-List | Out-String + Write-Host '-------------------------------------------------' } LogGroup 'Load PR information' { @@ -59,7 +78,7 @@ LogGroup 'Load PR information' { LogGroup 'Validate manifest and set module path' { Add-PSModulePath -Path (Split-Path -Path $modulePath -Parent) $manifestFilePath = Join-Path $modulePath "$name.psd1" - Write-Output "Module manifest file path: [$manifestFilePath]" + Write-Host "Module manifest file path: [$manifestFilePath]" if (-not (Test-Path -Path $manifestFilePath)) { Write-Error "Module manifest file not found at [$manifestFilePath]" exit 1 @@ -67,11 +86,11 @@ LogGroup 'Validate manifest and set module path' { } LogGroup 'Update module manifest' { - Write-Output 'Bump module version -> module metadata: Update-ModuleMetadata' + Write-Host 'Bump module version -> module metadata: Update-ModuleMetadata' $manifestNewVersion = "$($newVersion.Major).$($newVersion.Minor).$($newVersion.Patch)" Set-ModuleManifest -Path $manifestFilePath -ModuleVersion $manifestNewVersion -Verbose:$false if ($createPrerelease) { - Write-Output "Prerelease is: [$($newVersion.Prerelease)]" + Write-Host "Prerelease is: [$($newVersion.Prerelease)]" Set-ModuleManifest -Path $manifestFilePath -Prerelease $($newVersion.Prerelease) -Verbose:$false } @@ -83,15 +102,16 @@ LogGroup 'Install module dependencies' { } LogGroup 'Publish-ToPSGallery' { + $releaseType = if ($createPrerelease) { 'New prerelease' } else { 'New release' } if ($createPrerelease) { $publishPSVersion = "$($newVersion.Major).$($newVersion.Minor).$($newVersion.Patch)-$($newVersion.Prerelease)" } else { $publishPSVersion = "$($newVersion.Major).$($newVersion.Minor).$($newVersion.Patch)" } $psGalleryReleaseLink = "https://www.powershellgallery.com/packages/$name/$publishPSVersion" - Write-Output "Publish module to PowerShell Gallery using API key from environment." + Write-Host 'Publish module to PowerShell Gallery using API key from environment.' if ($whatIf) { - Write-Output "Publish-PSResource -Path $modulePath -Repository PSGallery -ApiKey ***" + Write-Host "Publish-PSResource -Path $modulePath -Repository PSGallery -ApiKey ***" } else { try { Publish-PSResource -Path $modulePath -Repository PSGallery -ApiKey $apiKey @@ -101,13 +121,13 @@ LogGroup 'Publish-ToPSGallery' { } } if ($whatIf) { - Write-Output ( + Write-Host ( "gh pr comment $prNumber -b " + - "'Module [$name - $publishPSVersion]($psGalleryReleaseLink) published to the PowerShell Gallery.'" + "'✅ $releaseType`: PowerShell Gallery - [$name $publishPSVersion]($psGalleryReleaseLink)'" ) } else { - Write-Host "::notice::Module [$name - $publishPSVersion] published to the PowerShell Gallery." - gh pr comment $prNumber -b "Module [$name - $publishPSVersion]($psGalleryReleaseLink) published to the PowerShell Gallery." + Write-Host "::notice title=✅ $releaseType`: PowerShell Gallery - $name $publishPSVersion::$psGalleryReleaseLink" + gh pr comment $prNumber -b "✅ $releaseType`: PowerShell Gallery - [$name $publishPSVersion]($psGalleryReleaseLink)" if ($LASTEXITCODE -ne 0) { Write-Error 'Failed to comment on the pull request.' exit $LASTEXITCODE @@ -116,7 +136,7 @@ LogGroup 'Publish-ToPSGallery' { } LogGroup 'New-GitHubRelease' { - Write-Output 'Create new GitHub release' + Write-Host 'Create new GitHub release' $releaseCreateCommand = @('release', 'create', $newVersion.ToString()) $notesFilePath = $null @@ -124,7 +144,7 @@ LogGroup 'New-GitHubRelease' { if ($usePRTitleAsReleaseName -and $pull_request.title) { $prTitle = $pull_request.title $releaseCreateCommand += @('--title', $prTitle) - Write-Output "Using PR title as release name: [$prTitle]" + Write-Host "Using PR title as release name: [$prTitle]" } else { $releaseCreateCommand += @('--title', $newVersion.ToString()) } @@ -144,14 +164,14 @@ LogGroup 'New-GitHubRelease' { $notesFilePath = [System.IO.Path]::GetTempFileName() Set-Content -Path $notesFilePath -Value $notes -Encoding utf8 $releaseCreateCommand += @('--notes-file', $notesFilePath) - Write-Output 'Using PR title as H1 heading with link and body as release notes' + Write-Host 'Using PR title as H1 heading with link and body as release notes' } elseif ($usePRBodyAsReleaseNotes -and $pull_request.body) { # Path 2: PR body only - no heading, just the body content $prBody = $pull_request.body $notesFilePath = [System.IO.Path]::GetTempFileName() Set-Content -Path $notesFilePath -Value $prBody -Encoding utf8 $releaseCreateCommand += @('--notes-file', $notesFilePath) - Write-Output 'Using PR body as release notes' + Write-Host 'Using PR body as release notes' } else { # Path 3: Fallback to GitHub's auto-generated release notes $releaseCreateCommand += @('--generate-notes') @@ -163,7 +183,7 @@ LogGroup 'New-GitHubRelease' { } if ($whatIf) { - Write-Output "WhatIf: gh $($releaseCreateCommand -join ' ')" + Write-Host "WhatIf: gh $($releaseCreateCommand -join ' ')" } else { $releaseURL = gh @releaseCreateCommand if ($LASTEXITCODE -ne 0) { @@ -177,19 +197,20 @@ LogGroup 'New-GitHubRelease' { Remove-Item -Path $notesFilePath -Force } + $releaseType = if ($createPrerelease) { 'New prerelease' } else { 'New release' } if ($whatIf) { - Write-Output ( + Write-Host ( "gh pr comment $prNumber -b " + - "'GitHub release for $name $newVersion has been created.'" + "'✅ $releaseType`: GitHub - $name $newVersion'" ) } else { - gh pr comment $prNumber -b "GitHub release for $name [$newVersion]($releaseURL) has been created." + gh pr comment $prNumber -b "✅ $releaseType`: GitHub - [$name $newVersion]($releaseURL)" if ($LASTEXITCODE -ne 0) { Write-Error 'Failed to comment on the pull request.' exit $LASTEXITCODE } } - Write-Host "::notice::Release created: [$newVersion]" + Write-Host "::notice title=✅ $releaseType`: GitHub - $name $newVersion::$releaseURL" } -Write-Output "Publishing complete. Version: [$($newVersion.ToString())]" +Write-Host "Publishing complete. Version: [$($newVersion.ToString())]"