Skip to content

Commit f4607e8

Browse files
tablackburnclaude
andcommitted
ci(release): guard empty changelog notes and unreadable CHANGELOG (review)
Addresses Copilot review on #31: - UpdateReleaseNotes: if the matched CHANGELOG entry is empty/whitespace, warn and leave ReleaseNotes unchanged rather than overwriting the built manifest with an empty string. - Create GitHub Release: read CHANGELOG.md defensively (Test-Path + try/catch). A missing or unreadable file now falls back to --generate-notes instead of failing the publish (GitHub's pwsh runs with $ErrorActionPreference = 'Stop'). Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent aadfaea commit f4607e8

2 files changed

Lines changed: 25 additions & 8 deletions

File tree

.github/workflows/PublishModuleToPowerShellGallery.yaml

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -99,16 +99,29 @@ jobs:
9999
# Build release notes from this version's CHANGELOG.md section so the release
100100
# body carries only the curated, user-facing entries (not the full PR list that
101101
# --generate-notes produces, which is dominated by bot/CI/chore PRs).
102-
$headerPattern = '^##\s+\[' + [regex]::Escape($version) + '\]'
103-
$capturing = $false
102+
# Read defensively: a missing/unreadable CHANGELOG.md must fall back to
103+
# --generate-notes (below), never fail the publish.
104+
$changelogLines = $null
105+
if (Test-Path -LiteralPath './CHANGELOG.md') {
106+
try {
107+
$changelogLines = Get-Content -LiteralPath './CHANGELOG.md' -ErrorAction Stop
108+
}
109+
catch {
110+
Write-Host "::warning::Could not read CHANGELOG.md ($($_.Exception.Message)); falling back to auto-generated notes."
111+
}
112+
}
104113
$captured = [System.Collections.Generic.List[string]]::new()
105-
foreach ($line in (Get-Content -LiteralPath './CHANGELOG.md')) {
106-
if (-not $capturing) {
107-
if ($line -match $headerPattern) { $capturing = $true }
108-
continue
114+
if ($changelogLines) {
115+
$headerPattern = '^##\s+\[' + [regex]::Escape($version) + '\]'
116+
$capturing = $false
117+
foreach ($line in $changelogLines) {
118+
if (-not $capturing) {
119+
if ($line -match $headerPattern) { $capturing = $true }
120+
continue
121+
}
122+
if ($line -match '^##\s+\[') { break } # next version header ends the section
123+
$captured.Add($line)
109124
}
110-
if ($line -match '^##\s+\[') { break } # next version header ends the section
111-
$captured.Add($line)
112125
}
113126
$body = ($captured -join "`n").Trim()
114127

build.psake.ps1

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,10 @@ Task -Name 'UpdateReleaseNotes' -Depends 'Build' -Description 'Set built manifes
7777
}
7878

7979
$releaseNotes = $releaseEntry.RawData.Trim()
80+
if ([string]::IsNullOrWhiteSpace($releaseNotes)) {
81+
Write-Warning "CHANGELOG.md entry for version $moduleVersion is empty; leaving ReleaseNotes unchanged."
82+
return
83+
}
8084
$builtManifest = Join-Path -Path $PSBPreference.Build.ModuleOutDir -ChildPath "$($PSBPreference.General.ModuleName).psd1"
8185
Update-ModuleManifest -Path $builtManifest -ReleaseNotes $releaseNotes -ErrorAction Stop
8286
Write-Host " Set ReleaseNotes on built manifest from CHANGELOG [$($releaseEntry.Version)] ($($releaseNotes.Length) chars)" -ForegroundColor Gray

0 commit comments

Comments
 (0)