Skip to content

Commit aadfaea

Browse files
tablackburnclaude
andcommitted
ci(release): populate PSData.ReleaseNotes from CHANGELOG at publish time
So a scaffolded module's PowerShell Gallery release-notes panel shows the curated, user-facing notes for each version (matching the GitHub release body) instead of a static CHANGELOG link. - build.depend.psd1: add ChangelogManagement 3.1.0 (Keep a Changelog parser). - build.psake.ps1: new UpdateReleaseNotes task (Depends Build) that reads the entry matching the module version via Get-ChangelogData and sets the built manifest's PrivateData.PSData.ReleaseNotes via Update-ModuleManifest. Wired in via $PSBPublishDependency so it runs before Publish-PSBuildModule. Non-fatal if the changelog can't be read or has no entry for the version. Mirrors the DSC Community Sampler pattern. Scaffolded modules use SemVer Keep a Changelog (CHANGELOG.template.md), the format this was validated against in ScheduledTasksManager. The template repo itself never runs this path (its publish is guarded against the un-initialized placeholder). Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent 341f921 commit aadfaea

2 files changed

Lines changed: 46 additions & 0 deletions

File tree

build.depend.psd1

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,4 +25,9 @@
2525
'PSScriptAnalyzer' = @{
2626
Version = '1.25.0'
2727
}
28+
# Parses CHANGELOG.md (Keep a Changelog format) so the Publish task can populate the
29+
# built manifest's PSData.ReleaseNotes from the matching version's entry.
30+
'ChangelogManagement' = @{
31+
Version = '3.1.0'
32+
}
2833
}

build.psake.ps1

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,5 +45,46 @@ Task -Name 'Init_Integration' -Description 'Load integration test environment va
4545
}
4646
}
4747

48+
# Populate the built manifest's ReleaseNotes from the matching CHANGELOG.md entry so the
49+
# PowerShell Gallery release-notes panel shows the curated, user-facing notes (the same
50+
# content used for the GitHub release) instead of just a link. Depends on Build so the
51+
# staged manifest in ModuleOutDir exists; runs before Publish (see $PSBPublishDependency
52+
# below). Non-fatal if the changelog can't be read or has no entry for the version being
53+
# published, so a release is never blocked.
54+
Task -Name 'UpdateReleaseNotes' -Depends 'Build' -Description 'Set built manifest ReleaseNotes from the matching CHANGELOG.md entry' {
55+
$changelogPath = Join-Path -Path $PSScriptRoot -ChildPath 'CHANGELOG.md'
56+
if (-not (Test-Path -Path $changelogPath)) {
57+
Write-Warning 'CHANGELOG.md not found; leaving ReleaseNotes unchanged.'
58+
return
59+
}
60+
61+
$moduleVersion = $PSBPreference.General.ModuleVersion
62+
try {
63+
Import-Module -Name 'ChangelogManagement' -ErrorAction Stop
64+
$changelogData = Get-ChangelogData -Path $changelogPath -ErrorAction Stop
65+
}
66+
catch {
67+
Write-Warning "Could not read CHANGELOG.md ($($_.Exception.Message)); leaving ReleaseNotes unchanged."
68+
return
69+
}
70+
71+
$releaseEntry = $changelogData.Released |
72+
Where-Object { [string]$_.Version -eq [string]$moduleVersion } |
73+
Select-Object -First 1
74+
if (-not $releaseEntry) {
75+
Write-Warning "No CHANGELOG.md entry found for version $moduleVersion; leaving ReleaseNotes unchanged."
76+
return
77+
}
78+
79+
$releaseNotes = $releaseEntry.RawData.Trim()
80+
$builtManifest = Join-Path -Path $PSBPreference.Build.ModuleOutDir -ChildPath "$($PSBPreference.General.ModuleName).psd1"
81+
Update-ModuleManifest -Path $builtManifest -ReleaseNotes $releaseNotes -ErrorAction Stop
82+
Write-Host " Set ReleaseNotes on built manifest from CHANGELOG [$($releaseEntry.Version)] ($($releaseNotes.Length) chars)" -ForegroundColor Gray
83+
}
84+
85+
# Inject ReleaseNotes into the built manifest before publishing (PowerShellBuild's Publish
86+
# defaults to depending only on 'Test').
87+
$PSBPublishDependency = @('Test', 'UpdateReleaseNotes')
88+
4889
# Note: -Depends replaces PowerShellBuild's default dependencies, so we must include Pester and Analyze explicitly
4990
Task -Name 'Test' -FromModule 'PowerShellBuild' -MinimumVersion '0.7.3' -Depends 'Init_Integration', 'Pester', 'Analyze'

0 commit comments

Comments
 (0)