Skip to content

Commit 5a4fd5d

Browse files
SyncFileContentsSyncFileContents
authored andcommitted
Sync scripts\PSBuild.psm1
1 parent ca933f7 commit 5a4fd5d

1 file changed

Lines changed: 36 additions & 8 deletions

File tree

scripts/PSBuild.psm1

Lines changed: 36 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,8 @@ function Get-BuildConfiguration {
5555
The expected owner/organization of the official repository.
5656
.PARAMETER ChangelogFile
5757
The path to the changelog file.
58+
.PARAMETER LatestChangelogFile
59+
The path to the file containing only the latest version's changelog. Defaults to "LATEST_CHANGELOG.md".
5860
.PARAMETER AssetPatterns
5961
Array of glob patterns for release assets.
6062
.OUTPUTS
@@ -83,6 +85,8 @@ function Get-BuildConfiguration {
8385
[string]$ExpectedOwner,
8486
[Parameter(Mandatory=$true)]
8587
[string]$ChangelogFile,
88+
[Parameter(Mandatory=$false)]
89+
[string]$LatestChangelogFile = "LATEST_CHANGELOG.md",
8690
[Parameter(Mandatory=$true)]
8791
[string[]]$AssetPatterns
8892
)
@@ -158,6 +162,7 @@ function Get-BuildConfiguration {
158162
Version = "1.0.0-pre.0"
159163
ReleaseHash = $GitSha
160164
ChangelogFile = $ChangelogFile
165+
LatestChangelogFile = $LatestChangelogFile
161166
AssetPatterns = $AssetPatterns
162167
}
163168
}
@@ -871,6 +876,8 @@ function New-Changelog {
871876
Optional path to write the changelog file to. Defaults to workspace root.
872877
.PARAMETER IncludeAllVersions
873878
Whether to include all previous versions in the changelog. Defaults to $true.
879+
.PARAMETER LatestChangelogPath
880+
Optional path to write the latest version's changelog to. Defaults to "LATEST_CHANGELOG.md".
874881
#>
875882
[CmdletBinding()]
876883
param (
@@ -879,7 +886,8 @@ function New-Changelog {
879886
[Parameter(Mandatory=$true)]
880887
[string]$CommitHash,
881888
[string]$OutputPath = "",
882-
[bool]$IncludeAllVersions = $true
889+
[bool]$IncludeAllVersions = $true,
890+
[string]$LatestChangelogPath = "LATEST_CHANGELOG.md"
883891
)
884892

885893
# Configure git versionsort to correctly handle prereleases
@@ -914,13 +922,20 @@ function New-Changelog {
914922
Write-Information "Generating changelog from $previousTag to $currentTag (commit: $CommitHash)" -Tags "New-Changelog"
915923
$versionNotes = Get-VersionNotes -Tags $tags -FromTag $previousTag -ToTag $currentTag -ToSha $CommitHash
916924

925+
# Store the latest version's notes for later use in GitHub releases
926+
$latestVersionNotes = ""
927+
917928
# If we have changes, add them to the changelog
918929
if (-not [string]::IsNullOrWhiteSpace($versionNotes)) {
919930
$changelog += $versionNotes
931+
$latestVersionNotes = $versionNotes
920932
} else {
921933
# Handle no changes detected case - add a minimal entry
922-
$changelog += "## $currentTag$script:lineEnding$script:lineEnding"
923-
$changelog += "Initial release or no significant changes since $previousTag.$script:lineEnding$script:lineEnding"
934+
$minimalEntry = "## $currentTag$script:lineEnding$script:lineEnding"
935+
$minimalEntry += "Initial release or no significant changes since $previousTag.$script:lineEnding$script:lineEnding"
936+
937+
$changelog += $minimalEntry
938+
$latestVersionNotes = $minimalEntry
924939
}
925940

926941
# Add entries for all previous versions if requested
@@ -953,6 +968,12 @@ function New-Changelog {
953968

954969
[System.IO.File]::WriteAllText($filePath, $changelog, [System.Text.UTF8Encoding]::new($false)) | Write-InformationStream -Tags "New-Changelog"
955970

971+
# Write latest version's changelog to separate file for GitHub releases
972+
$latestPath = if ($OutputPath) { Join-Path $OutputPath $LatestChangelogPath } else { $LatestChangelogPath }
973+
$latestVersionNotes = $latestVersionNotes.ReplaceLineEndings($script:lineEnding)
974+
[System.IO.File]::WriteAllText($latestPath, $latestVersionNotes, [System.Text.UTF8Encoding]::new($false)) | Write-InformationStream -Tags "New-Changelog"
975+
Write-Information "Latest version changelog saved to: $latestPath" -Tags "New-Changelog"
976+
956977
$versionCount = if ($hasTags) { @($tags).Count + 1 } else { 1 }
957978
Write-Information "Changelog generated with entries for $versionCount versions" -Tags "New-Changelog"
958979
}
@@ -1005,8 +1026,8 @@ function Update-ProjectMetadata {
10051026
New-License -ServerUrl $BuildConfiguration.ServerUrl -Owner $BuildConfiguration.GitHubOwner -Repository $BuildConfiguration.GitHubRepo | Write-InformationStream -Tags "Update-ProjectMetadata"
10061027

10071028
Write-Information "Generating changelog..." -Tags "Update-ProjectMetadata"
1008-
# Fixed: Now properly includes latest changes
1009-
New-Changelog -Version $version -CommitHash $BuildConfiguration.ReleaseHash | Write-InformationStream -Tags "Update-ProjectMetadata"
1029+
# Generate both full changelog and latest version changelog
1030+
New-Changelog -Version $version -CommitHash $BuildConfiguration.ReleaseHash -LatestChangelogPath $BuildConfiguration.LatestChangelogFile | Write-InformationStream -Tags "Update-ProjectMetadata"
10101031

10111032
# Create AUTHORS.md if authors are provided
10121033
if ($Authors.Count -gt 0) {
@@ -1445,9 +1466,16 @@ function New-GitHubRelease {
14451466
# Add notes generation
14461467
$releaseArgs += "--generate-notes"
14471468

1448-
# Handle changelog content if file exists
1449-
if (Test-Path $BuildConfiguration.ChangelogFile) {
1450-
Write-Information "Using changelog from $($BuildConfiguration.ChangelogFile)" -Tags "New-GitHubRelease"
1469+
# First check for latest changelog file (preferred for releases)
1470+
$latestChangelogPath = "LATEST_CHANGELOG.md"
1471+
if (Test-Path $latestChangelogPath) {
1472+
Write-Information "Using latest version changelog from $latestChangelogPath" -Tags "New-GitHubRelease"
1473+
$releaseArgs += "--notes-file"
1474+
$releaseArgs += $latestChangelogPath
1475+
}
1476+
# Fall back to full changelog if specified in config and latest not found
1477+
elseif (Test-Path $BuildConfiguration.ChangelogFile) {
1478+
Write-Information "Using full changelog from $($BuildConfiguration.ChangelogFile)" -Tags "New-GitHubRelease"
14511479
$releaseArgs += "--notes-file"
14521480
$releaseArgs += $BuildConfiguration.ChangelogFile
14531481
}

0 commit comments

Comments
 (0)