Skip to content

Fix update-cgmanifest.ps1 script to generate deterministic output #30117

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jun 25, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 28 additions & 8 deletions eng/scripts/update-cgmanifest.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ if (Test-Path $cgManifestPath) {
}
else {
Write-Host "Creating a new cgmanifest.json file"
$cgManifest = @{
$cgManifest = [ordered]@{
'$schema' = 'https://json.schemastore.org/component-detection-manifest.json'
version = 1
registrations = @()
Expand Down Expand Up @@ -71,10 +71,11 @@ function New-PackageEntry {
[string]$PackageVersion
)

return @{
component = @{
# Use ordered hashtables to ensure consistent JSON property ordering
return [ordered]@{
component = [ordered]@{
type = 'nuget'
nuget = @{
nuget = [ordered]@{
name = $PackageName
version = $PackageVersion
}
Expand Down Expand Up @@ -134,12 +135,31 @@ foreach ($package in $packageVersionMappings.GetEnumerator()) {
}
}

# Sort registrations by package name for consistent ordering
$sortedRegistrations = $newRegistrations | Sort-Object { $_.component.nuget.name }

# Update the manifest
$cgManifest.registrations = $newRegistrations
$cgManifest.registrations = $sortedRegistrations

# Convert to JSON with consistent formatting
$newContent = $cgManifest | ConvertTo-Json -Depth 10

# Only write if content has changed to avoid unnecessary file modifications
$shouldWrite = $true
if (Test-Path $cgManifestPath) {
$currentContent = Get-Content $cgManifestPath -Raw
# Normalize line endings and trim whitespace for comparison
$currentContentNormalized = $currentContent.Trim() -replace "`r`n", "`n" -replace "`r", "`n"
$newContentNormalized = $newContent.Trim() -replace "`r`n", "`n" -replace "`r", "`n"
$shouldWrite = $currentContentNormalized -ne $newContentNormalized
}

# Save the updated manifest
$cgManifest | ConvertTo-Json -Depth 10 | Out-File $cgManifestPath -Encoding utf8
Write-Host "Updated cgmanifest.json saved to: $cgManifestPath"
if ($shouldWrite) {
$newContent | Out-File $cgManifestPath -Encoding utf8
Write-Host "Updated cgmanifest.json saved to: $cgManifestPath"
} else {
Write-Host "No changes detected - cgmanifest.json is already up to date"
}

# Print summary
Write-Host "Successfully added $($newRegistrations.Count) package registrations to cgmanifest.json"
136 changes: 68 additions & 68 deletions src/Templates/src/cgmanifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,155 +3,155 @@
"registrations": [
{
"component": {
"type": "nuget",
"nuget": {
"version": "11.1.1",
"name": "CommunityToolkit.Maui"
},
"type": "nuget"
"name": "CommunityToolkit.Maui",
"version": "11.1.1"
}
}
},
{
"component": {
"type": "nuget",
"nuget": {
"version": "9.1.0",
"name": "CommunityToolkit.Maui"
},
"type": "nuget"
"name": "CommunityToolkit.Maui",
"version": "9.1.0"
}
}
},
{
"component": {
"type": "nuget",
"nuget": {
"version": "17.6.0",
"name": "Microsoft.NET.Test.Sdk"
},
"type": "nuget"
"name": "CommunityToolkit.Mvvm",
"version": "8.3.2"
}
}
},
{
"component": {
"type": "nuget",
"nuget": {
"version": "2.8.2",
"name": "xunit.runner.visualstudio"
},
"type": "nuget"
"name": "coverlet.collector",
"version": "6.0.0"
}
}
},
{
"component": {
"type": "nuget",
"nuget": {
"version": "9.0.4",
"name": "Microsoft.Extensions.Configuration"
},
"type": "nuget"
"name": "Microsoft.Data.Sqlite.Core",
"version": "8.0.8"
}
}
},
{
"component": {
"type": "nuget",
"nuget": {
"version": "1.0.4",
"name": "Syncfusion.Maui.Toolkit"
},
"type": "nuget"
"name": "Microsoft.Extensions.Configuration",
"version": "9.0.5"
}
}
},
{
"component": {
"type": "nuget",
"nuget": {
"version": "1.7.250401001",
"name": "Microsoft.WindowsAppSDK"
},
"type": "nuget"
"name": "Microsoft.Extensions.DependencyInjection",
"version": "9.0.5"
}
}
},
{
"component": {
"type": "nuget",
"nuget": {
"version": "2.1.10",
"name": "SQLitePCLRaw.bundle_green"
},
"type": "nuget"
"name": "Microsoft.Extensions.Logging.Debug",
"version": "9.0.5"
}
}
},
{
"component": {
"type": "nuget",
"nuget": {
"version": "9.0.4",
"name": "Microsoft.Extensions.Logging.Debug"
},
"type": "nuget"
"name": "Microsoft.Graphics.Win2D",
"version": "1.3.2"
}
}
},
{
"component": {
"type": "nuget",
"nuget": {
"version": "10.0.22621.756",
"name": "Microsoft.Windows.SDK.BuildTools"
},
"type": "nuget"
"name": "Microsoft.NET.Test.Sdk",
"version": "17.6.0"
}
}
},
{
"component": {
"type": "nuget",
"nuget": {
"version": "8.3.2",
"name": "CommunityToolkit.Mvvm"
},
"type": "nuget"
"name": "Microsoft.Windows.SDK.BuildTools",
"version": "10.0.22621.756"
}
}
},
{
"component": {
"type": "nuget",
"nuget": {
"version": "1.2.0",
"name": "Microsoft.Graphics.Win2D"
},
"type": "nuget"
"name": "Microsoft.WindowsAppSDK",
"version": "1.7.250513003"
}
}
},
{
"component": {
"type": "nuget",
"nuget": {
"version": "2.9.0",
"name": "xunit"
},
"type": "nuget"
"name": "SQLitePCLRaw.bundle_green",
"version": "2.1.10"
}
}
},
{
"component": {
"type": "nuget",
"nuget": {
"version": "8.0.8",
"name": "Microsoft.Data.Sqlite.Core"
},
"type": "nuget"
"name": "Syncfusion.Maui.Toolkit",
"version": "1.0.4"
}
}
},
{
"component": {
"type": "nuget",
"nuget": {
"version": "9.0.4",
"name": "Microsoft.Extensions.DependencyInjection"
},
"type": "nuget"
"name": "xunit",
"version": "2.9.0"
}
}
},
{
"component": {
"type": "nuget",
"nuget": {
"version": "1.15.0",
"name": "xunit.analyzer"
},
"type": "nuget"
"name": "xunit.analyzer",
"version": "1.15.0"
}
}
},
{
"component": {
"type": "nuget",
"nuget": {
"version": "6.0.0",
"name": "coverlet.collector"
},
"type": "nuget"
"name": "xunit.runner.visualstudio",
"version": "2.8.2"
}
}
}
],
Expand Down