Skip to content

Commit 0115b6d

Browse files
SyncFileContentsSyncFileContents
authored andcommitted
Sync scripts\PSBuild.psm1
1 parent 488502c commit 0115b6d

1 file changed

Lines changed: 67 additions & 32 deletions

File tree

scripts/PSBuild.psm1

Lines changed: 67 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,9 @@ function Get-BuildConfiguration {
4848
.PARAMETER GithubToken
4949
The GitHub token for API operations.
5050
.PARAMETER NuGetApiKey
51-
The NuGet API key for package publishing.
51+
The NuGet API key for package publishing. Optional - if not provided or empty, NuGet publishing will be skipped.
52+
.PARAMETER KtsuPackageKey
53+
The Ktsu package key for package publishing. Optional - if not provided or empty, Ktsu publishing will be skipped.
5254
.PARAMETER WorkspacePath
5355
The path to the workspace/repository root.
5456
.PARAMETER ExpectedOwner
@@ -77,8 +79,12 @@ function Get-BuildConfiguration {
7779
[string]$GitHubRepo,
7880
[Parameter(Mandatory=$true)]
7981
[string]$GithubToken,
80-
[Parameter(Mandatory=$true)]
81-
[string]$NuGetApiKey,
82+
[Parameter(Mandatory=$false)]
83+
[AllowEmptyString()]
84+
[string]$NuGetApiKey = "",
85+
[Parameter(Mandatory=$false)]
86+
[AllowEmptyString()]
87+
[string]$KtsuPackageKey = "",
8288
[Parameter(Mandatory=$true)]
8389
[string]$WorkspacePath,
8490
[Parameter(Mandatory=$true)]
@@ -161,6 +167,7 @@ function Get-BuildConfiguration {
161167
GitHubRepo = $GitHubRepo
162168
GithubToken = $GithubToken
163169
NuGetApiKey = $NuGetApiKey
170+
KtsuPackageKey = $KtsuPackageKey
164171
ExpectedOwner = $ExpectedOwner
165172
Version = "1.0.0-pre.0"
166173
ReleaseHash = $GitSha
@@ -1170,6 +1177,25 @@ function New-Changelog {
11701177
# Write latest version's changelog to separate file for GitHub releases
11711178
$latestPath = if ($OutputPath) { Join-Path $OutputPath $LatestChangelogFile } else { $LatestChangelogFile }
11721179
$latestVersionNotes = $latestVersionNotes.ReplaceLineEndings($script:lineEnding)
1180+
1181+
# Truncate release notes if they exceed NuGet's 35,000 character limit
1182+
$maxLength = 35000
1183+
if ($latestVersionNotes.Length -gt $maxLength) {
1184+
Write-Information "Release notes exceed $maxLength characters ($($latestVersionNotes.Length)). Truncating to fit NuGet limit." -Tags "New-Changelog"
1185+
$truncationMessage = "$script:lineEnding$script:lineEnding... (truncated due to NuGet length limits)"
1186+
$targetLength = $maxLength - $truncationMessage.Length - 10 # Extra buffer for safety
1187+
$truncatedNotes = $latestVersionNotes.Substring(0, $targetLength)
1188+
$truncatedNotes += $truncationMessage
1189+
$latestVersionNotes = $truncatedNotes
1190+
Write-Information "Truncated release notes to $($latestVersionNotes.Length) characters" -Tags "New-Changelog"
1191+
1192+
# Final safety check - ensure we never exceed the limit
1193+
if ($latestVersionNotes.Length -gt $maxLength) {
1194+
Write-Warning "Truncated release notes still exceed limit ($($latestVersionNotes.Length) > $maxLength). Further truncating..." -Tags "New-Changelog"
1195+
$latestVersionNotes = $latestVersionNotes.Substring(0, $maxLength - 50) + "... (truncated)"
1196+
}
1197+
}
1198+
11731199
[System.IO.File]::WriteAllText($latestPath, $latestVersionNotes, [System.Text.UTF8Encoding]::new($false)) | Write-InformationStream -Tags "New-Changelog"
11741200
Write-Information "Latest version changelog saved to: $latestPath" -Tags "New-Changelog"
11751201

@@ -1270,7 +1296,7 @@ function Update-ProjectMetadata {
12701296
"PROJECT_URL.url",
12711297
"AUTHORS.url"
12721298
)
1273-
1299+
12741300
# Add latest changelog if it exists
12751301
if (Test-Path $BuildConfiguration.LatestChangelogFile) {
12761302
$filesToAdd += $BuildConfiguration.LatestChangelogFile
@@ -1472,7 +1498,7 @@ function Invoke-DotNetPack {
14721498
.PARAMETER Project
14731499
Optional specific project to package. If not provided, all projects are packaged.
14741500
.PARAMETER LatestChangelogFile
1475-
Optional path to the latest changelog file to use for PackageReleaseNotes. Defaults to "LATEST_CHANGELOG.md".
1501+
Optional path to the latest changelog file to use for PackageReleaseNotesFile. Defaults to "LATEST_CHANGELOG.md".
14761502
#>
14771503
[CmdletBinding()]
14781504
param (
@@ -1496,14 +1522,20 @@ function Invoke-DotNetPack {
14961522
}
14971523

14981524
try {
1499-
# Prepare PackageReleaseNotesFile property if latest changelog exists
1525+
# Override PackageReleaseNotes to use LATEST_CHANGELOG.md instead of full CHANGELOG.md
1526+
# Use PackageReleaseNotesFile property to avoid command line length limits and escaping issues
15001527
$releaseNotesProperty = ""
1528+
15011529
if (Test-Path $LatestChangelogFile) {
1502-
# Use PackageReleaseNotesFile to reference the file path instead of inline content
1503-
# This avoids command-line parsing issues with special characters like semicolons
1504-
$absolutePath = (Resolve-Path $LatestChangelogFile).Path
1505-
$releaseNotesProperty = "-p:PackageReleaseNotesFile=`"$absolutePath`""
1506-
Write-Information "Using PackageReleaseNotesFile from $LatestChangelogFile" -Tags "Invoke-DotNetPack"
1530+
# Get absolute path to the changelog file for MSBuild
1531+
$absoluteChangelogPath = (Resolve-Path $LatestChangelogFile).Path
1532+
Write-Information "Using release notes from file: $absoluteChangelogPath" -Tags "Invoke-DotNetPack"
1533+
1534+
# Use PackageReleaseNotesFile property instead of PackageReleaseNotes to avoid command line issues
1535+
$releaseNotesProperty = "-p:PackageReleaseNotesFile=`"$absoluteChangelogPath`""
1536+
Write-Information "Overriding PackageReleaseNotesFile with latest changelog file path" -Tags "Invoke-DotNetPack"
1537+
} else {
1538+
Write-Information "No latest changelog found, SDK will use full CHANGELOG.md (automatically truncated if needed)" -Tags "Invoke-DotNetPack"
15071539
}
15081540

15091541
# Build either a specific project or all projects
@@ -1519,6 +1551,7 @@ function Invoke-DotNetPack {
15191551
# Get more details about what might have failed
15201552
Write-Information "Packaging failed with exit code $LASTEXITCODE, trying again with detailed verbosity..." -Tags "Invoke-DotNetPack"
15211553
"dotnet pack --configuration $Configuration -logger:`"Microsoft.Build.Logging.ConsoleLogger,Microsoft.Build;Summary;ForceNoAlign;ShowTimestamp;ShowCommandLine;Verbosity=detailed`" --no-build --output $OutputPath $releaseNotesProperty" | Invoke-ExpressionWithLogging | Write-InformationStream -Tags "Invoke-DotNetPack"
1554+
15221555
throw "Library packaging failed with exit code $LASTEXITCODE"
15231556
}
15241557

@@ -1646,20 +1679,6 @@ function Invoke-DotNetPublish {
16461679
} else {
16471680
Write-Information "No applications were published (projects may not be configured as executables)" -Tags "Invoke-DotNetPublish"
16481681
}
1649-
1650-
# Note: NuGet package publishing is handled separately in Invoke-ReleaseWorkflow
1651-
1652-
Write-StepHeader "Release Process Completed" -Tags "Invoke-ReleaseWorkflow"
1653-
Write-Information "Release process completed successfully!" -Tags "Invoke-ReleaseWorkflow"
1654-
return [PSCustomObject]@{
1655-
Success = $true
1656-
Error = ""
1657-
Data = [PSCustomObject]@{
1658-
Version = $BuildConfiguration.Version
1659-
ReleaseHash = $BuildConfiguration.ReleaseHash
1660-
PackagePaths = @()
1661-
}
1662-
}
16631682
}
16641683

16651684
#endregion
@@ -1700,11 +1719,27 @@ function Invoke-NuGetPublish {
17001719
"dotnet nuget push `"$($BuildConfiguration.PackagePattern)`" --api-key `"$($BuildConfiguration.GithubToken)`" --source `"https://nuget.pkg.github.com/$($BuildConfiguration.GithubOwner)/index.json`" --skip-duplicate" | Invoke-ExpressionWithLogging | Write-InformationStream -Tags "Invoke-NuGetPublish"
17011720
Assert-LastExitCode "GitHub package publish failed"
17021721

1703-
Write-StepHeader "Publishing to NuGet.org" -Tags "Invoke-NuGetPublish"
1722+
# Only publish to NuGet.org if API key is provided
1723+
if (-not [string]::IsNullOrWhiteSpace($BuildConfiguration.NuGetApiKey)) {
1724+
Write-StepHeader "Publishing to NuGet.org" -Tags "Invoke-NuGetPublish"
17041725

1705-
# Execute the command and stream output
1706-
"dotnet nuget push `"$($BuildConfiguration.PackagePattern)`" --api-key `"$($BuildConfiguration.NuGetApiKey)`" --source `"https://api.nuget.org/v3/index.json`" --skip-duplicate" | Invoke-ExpressionWithLogging | Write-InformationStream -Tags "Invoke-NuGetPublish"
1707-
Assert-LastExitCode "NuGet.org package publish failed"
1726+
# Execute the command and stream output
1727+
"dotnet nuget push `"$($BuildConfiguration.PackagePattern)`" --api-key `"$($BuildConfiguration.NuGetApiKey)`" --source `"https://api.nuget.org/v3/index.json`" --skip-duplicate" | Invoke-ExpressionWithLogging | Write-InformationStream -Tags "Invoke-NuGetPublish"
1728+
Assert-LastExitCode "NuGet.org package publish failed"
1729+
} else {
1730+
Write-Information "Skipping NuGet.org publishing - no API key provided" -Tags "Invoke-NuGetPublish"
1731+
}
1732+
1733+
# Only publish to Ktsu.dev if API key is provided
1734+
if (-not [string]::IsNullOrWhiteSpace($BuildConfiguration.KtsuPackageKey)) {
1735+
Write-StepHeader "Publishing to packages.ktsu.dev" -Tags "Invoke-NuGetPublish"
1736+
1737+
# Execute the command and stream output
1738+
"dotnet nuget push `"$($BuildConfiguration.PackagePattern)`" --api-key `"$($BuildConfiguration.KtsuPackageKey)`" --source `"https://packages.ktsu.dev/v3/index.json`" --skip-duplicate" | Invoke-ExpressionWithLogging | Write-InformationStream -Tags "Invoke-NuGetPublish"
1739+
Assert-LastExitCode "packages.ktsu.dev package publish failed"
1740+
} else {
1741+
Write-Information "Skipping packages.ktsu.dev publishing - no API key provided" -Tags "Invoke-NuGetPublish"
1742+
}
17081743
}
17091744

17101745
function New-GitHubRelease {
@@ -2175,8 +2210,8 @@ function Invoke-ReleaseWorkflow {
21752210

21762211
# Create NuGet packages
21772212
try {
2178-
Write-StepHeader "Packaging Libraries" -Tags "Invoke-DotNetPack"
2179-
Invoke-DotNetPack -Configuration $Configuration -OutputPath $BuildConfiguration.StagingPath -LatestChangelogFile $BuildConfiguration.LatestChangelogFile | Write-InformationStream -Tags "Invoke-DotNetPack"
2213+
Write-StepHeader "Packaging Libraries" -Tags "Invoke-DotNetPack"
2214+
Invoke-DotNetPack -Configuration $Configuration -OutputPath $BuildConfiguration.StagingPath -LatestChangelogFile $BuildConfiguration.LatestChangelogFile | Write-InformationStream -Tags "Invoke-DotNetPack"
21802215

21812216
# Add package paths if they exist
21822217
if (Test-Path $BuildConfiguration.PackagePattern) {
@@ -2422,4 +2457,4 @@ $ProgressPreference = 'Ignore'
24222457

24232458
# Get the line ending for the current system
24242459
$script:lineEnding = Get-GitLineEnding
2425-
#endregion
2460+
#endregion

0 commit comments

Comments
 (0)