Skip to content

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/.

@ghost ghost 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 jeffhandley merged commit 275ea58 into dotnet:main Nov 1, 2024
145 of 148 checks passed
@jeffhandley jeffhandley deleted the jeffhandley/cgmanifest branch November 1, 2024 19:42
@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 subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

3 participants