Skip to content

Fix update-cgmanifest.ps1 script to produce deterministic output #30055

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

Draft
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

Copilot
Copy link
Contributor

@Copilot Copilot AI commented Jun 18, 2025

Problem

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

The script had several issues:

  • Package registrations were added in the order they were processed (not alphabetical)
  • JSON field ordering was inconsistent between runs
  • Even with identical package versions, the file would appear modified in git

Solution

Modified the script to ensure deterministic, consistent output:

  1. Sort package registrations alphabetically by package name before writing to JSON
  2. Use ordered hashtables to ensure consistent field ordering within JSON objects
  3. Maintain consistent JSON structure across multiple script runs

Changes Made

  • Added sorting of $newRegistrations by package name: $newRegistrations | Sort-Object { $_.component.nuget.name }
  • Implemented ordered hashtables using [ordered]@{} syntax to control field ordering
  • Ensured consistent structure: type before nuget, name before version
  • Maintained all existing functionality for package detection and version processing

Verification

Created comprehensive tests that verify:

  • ✅ Multiple script runs produce identical output (zero diff)
  • ✅ Packages are sorted alphabetically by name
  • ✅ Field ordering is consistent within JSON objects
  • ✅ No functional changes to package detection logic

Example Before/After

Before: Running the script twice would show differences like:

-          "name": "SQLitePCLRaw.bundle_green",
-          "version": "2.1.10"
+          "version": "2.1.10",
+          "name": "SQLitePCLRaw.bundle_green"

After: Running the script multiple times produces identical output with zero differences.

This resolves the issue where changes to cgmanifest.json files would appear in source control unnecessarily, making it easier to identify actual package version changes.

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 AI and others added 3 commits June 18, 2025 16:41
Co-authored-by: rmarinho <1235097+rmarinho@users.noreply.github.com>
Co-authored-by: rmarinho <1235097+rmarinho@users.noreply.github.com>
Co-authored-by: rmarinho <1235097+rmarinho@users.noreply.github.com>
@Copilot Copilot AI changed the title [WIP] [bug] Fix update-cgmanifest.ps1 script Fix update-cgmanifest.ps1 script to produce deterministic output Jun 18, 2025
Copilot finished work on behalf of rmarinho June 18, 2025 16:56
@Copilot Copilot AI requested a review from rmarinho June 18, 2025 16:56
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
2 participants