Skip to content
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

Update cgmanifest to align with the JSON schema #109453

Merged
merged 1 commit into from
Nov 1, 2024

Conversation

jeffhandley
Copy link
Member

With dotnet/machinelearning#7283, we realized that the cgmanifest.json file was not aligned with the JSON schema. It is using Title case property names but it should be using camelCase property names. We also need to add a version property to the manifest.

See this comment for more detail: dotnet/machinelearning#7283 (comment)

Here's the console app I used to confirm the existing manifest isn't valid against its schema, and the updated one in this PR is valid:

using System;
using System.Net.Http;
using System.Text.Json.Nodes;
using System.Threading.Tasks;
using Json.Schema;

HttpClient httpClient = new();

string schemaUrl = "https://json.schemastore.org/component-detection-manifest.json";
HttpResponseMessage schemaResponse = await httpClient.GetAsync(schemaUrl);
schemaResponse.EnsureSuccessStatusCode();
string schemaJson = (await schemaResponse.Content.ReadAsStringAsync()).Replace("/draft-04/", "/draft-06/");
JsonSchema schema = JsonSchema.FromText(schemaJson);

string[] manifestUrls = [
    "https://raw.githubusercontent.com/dotnet/runtime/refs/heads/main/src/native/external/cgmanifest.json",
    "https://raw.githubusercontent.com/jeffhandley/runtime/jeffhandley/cgmanifest/src/native/external/cgmanifest.json"
];

foreach (var manifestUrl in manifestUrls)
{
    HttpResponseMessage manifestResponse = await httpClient.GetAsync(manifestUrl);
    manifestResponse.EnsureSuccessStatusCode();
    string manifestJson = await manifestResponse.Content.ReadAsStringAsync();

    JsonNode manifest = JsonNode.Parse(manifestJson);

    var result = schema.Evaluate(manifest);
    Console.WriteLine(manifestUrl);
    Console.WriteLine($"Valid: {result.IsValid}");
}

Here's the output:

https://raw.githubusercontent.com/dotnet/runtime/refs/heads/main/src/native/external/cgmanifest.json
Valid: False

https://raw.githubusercontent.com/jeffhandley/runtime/jeffhandley/cgmanifest/src/native/external/cgmanifest.json
Valid: True

The format of the file now matches what is shown in https://docs.opensource.microsoft.com/tools/cg/component-detection/cgmanifest/.

@dotnet-issue-labeler dotnet-issue-labeler bot added the needs-area-label An area label is needed to ensure this gets routed to the appropriate area owners label Nov 1, 2024
@jeffhandley jeffhandley added area-Infrastructure and removed needs-area-label An area label is needed to ensure this gets routed to the appropriate area owners labels Nov 1, 2024
Copy link
Member

@tarekgh tarekgh left a comment

Choose a reason for hiding this comment

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

Thanks for helping to fix it!

@jeffhandley
Copy link
Member Author

/ba-g Failures are known and unrelated

@jeffhandley
Copy link
Member Author

@tarekgh I dug in to understand why/how the component governance integration was still working despite the JSON document not adhering to the schema, and I was able to confirm that it was working before, and it's still working after this change. The reason it worked is that the component detection that processes these files has the JSON deserialization set up where it is recognizing either TitleCase or properCase property names.

So while it was working before, we're now adhering to the schema correctly and we won't get tripped up if the component detection ever applies stricter validation of the documents.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

3 participants