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

Conversation

Copilot
Copy link
Contributor

@Copilot Copilot AI commented Jun 22, 2025

The update-cgmanifest.ps1 script was regenerating the entire cgmanifest.json file each time it ran, causing unnecessary changes in source control even when there were no actual changes to package versions.

Issues Fixed

  1. Non-deterministic ordering: Package registrations were added in processing order rather than sorted order, causing different ordering between runs
  2. Inconsistent JSON property ordering: PowerShell hashtables don't guarantee property order, leading to inconsistent JSON structure
  3. Unnecessary file writes: The script would rewrite the file even when content was identical

Changes Made

  • Sort registrations alphabetically: Added Sort-Object { $_.component.nuget.name } to ensure consistent package ordering
  • Use ordered hashtables: Modified New-PackageEntry function to use [ordered] hashtables for consistent JSON property ordering
  • Content comparison optimization: Added logic to compare existing content with new content and only write when changes are detected
  • Normalize line endings: Added proper line ending normalization for cross-platform compatibility

Before/After Comparison

Before: Running the script twice would show git changes even with identical package versions:

 "component": {
+  "type": "nuget",
   "nuget": {
-    "version": "11.1.1",
-    "name": "CommunityToolkit.Maui"
+    "name": "CommunityToolkit.Maui", 
+    "version": "11.1.1"
   },
-  "type": "nuget"
 }

After: Running the script multiple times produces identical output with no spurious git changes, and shows "No changes detected - cgmanifest.json is already up to date" when appropriate.

Testing

✅ Script produces identical output on successive runs
✅ Packages are sorted alphabetically by name
✅ JSON properties have consistent ordering (typenugetnameversion)
✅ Content comparison optimization works correctly
✅ Cake build integration (dotnet cake --target=GenerateCgManifest) still works
✅ New file creation functionality preserved
✅ All existing functionality maintained

Fixes #30054.


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

@Copilot Copilot AI changed the title [WIP] [bug] Fix update-cgmanifest.ps1 script Fix update-cgmanifest.ps1 script to generate deterministic output Jun 22, 2025
@Copilot Copilot AI requested a review from mattleibow June 22, 2025 12:43
Copilot finished work on behalf of mattleibow June 22, 2025 12:43
@rmarinho rmarinho self-requested a review June 25, 2025 15:35
@mattleibow mattleibow marked this pull request as ready for review June 25, 2025 15:50
@Copilot Copilot AI review requested due to automatic review settings June 25, 2025 15:50
@mattleibow mattleibow requested a review from a team as a code owner June 25, 2025 15:50
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR fixes the update-cgmanifest.ps1 script to generate deterministic output by enforcing a consistent JSON structure and package registration order.

  • Sorting of package registrations alphabetically
  • Using [ordered] hashtables to guarantee property ordering
  • Optimizing file writes by comparing content before saving

Reviewed Changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
src/Templates/src/cgmanifest.json Updated JSON structure entries to reflect a consistent order of properties and package registrations.
eng/scripts/update-cgmanifest.ps1 Introduced ordered hashtables, added sorting for registrations, and implemented content comparison logic.

@rmarinho
Copy link
Member

/azp run MAUI-public

Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@rmarinho rmarinho merged commit 6222ba8 into main Jun 25, 2025
11 of 17 checks passed
@rmarinho rmarinho deleted the copilot/fix-30054-2 branch June 25, 2025 16:52
NanthiniMahalingam pushed a commit to NanthiniMahalingam/maui that referenced this pull request Jun 27, 2025
…tnet#30117)

* Initial plan for issue

* Fix update-cgmanifest.ps1 to generate deterministic output

Co-authored-by: mattleibow <[email protected]>

---------

Co-authored-by: copilot-swe-agent[bot] <[email protected]>
Co-authored-by: mattleibow <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[bug] Fix update-cgmanifest.ps1 script
3 participants