Skip to content

Commit

Permalink
Pick best license for markdown report
Browse files Browse the repository at this point in the history
  • Loading branch information
Malcolm Nixon committed Jun 24, 2024
1 parent 795e4b3 commit 3c6d57e
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 3 deletions.
4 changes: 4 additions & 0 deletions .github/workflows/build_on_push.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ jobs:
-pv ${{ env.version }}
-ps DemaConsulting
-nsb https://DemaConsulting.com/SpdxTool
-li true
-pm true
- name: Generate Tests SBOM
run: >
Expand All @@ -64,6 +66,8 @@ jobs:
-pv ${{ env.version }}
-ps DemaConsulting
-nsb https://DemaConsulting.com/SpdxTool.Tests
-li true
-pm true
- name: Run SBOM Workflow
run: >
Expand Down
4 changes: 4 additions & 0 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@ jobs:
-pv ${{ github.event.inputs.version }}
-ps DemaConsulting
-nsb https://DemaConsulting.com/SpdxTool
-li true
-pm true
- name: Generate Tests SBOM
run: >
Expand All @@ -76,6 +78,8 @@ jobs:
-pv ${{ github.event.inputs.version }}
-ps DemaConsulting
-nsb https://DemaConsulting.com/SpdxTool.Tests
-li true
-pm true
- name: Run SBOM Workflow
run: >
Expand Down
25 changes: 22 additions & 3 deletions src/DemaConsulting.SpdxTool/Commands/ToMarkdown.cs
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ public static void GenerateSummaryMarkdown(string spdxFile, string markdownFile,
markdown.AppendLine("| :-------- | :--- | :--- |");
foreach (var package in rootPackages)
markdown.AppendLine(
$"| {package.Name} | {package.Version ?? string.Empty} | {package.ConcludedLicense} |");
$"| {package.Name} | {package.Version ?? string.Empty} | {License(package)} |");
markdown.AppendLine();
markdown.AppendLine();
}
Expand All @@ -170,7 +170,7 @@ public static void GenerateSummaryMarkdown(string spdxFile, string markdownFile,
markdown.AppendLine("| :-------- | :--- | :--- |");
foreach (var package in packages)
markdown.AppendLine(
$"| {package.Name} | {package.Version ?? string.Empty} | {package.ConcludedLicense} |");
$"| {package.Name} | {package.Version ?? string.Empty} | {License(package)} |");
markdown.AppendLine();
markdown.AppendLine();
}
Expand All @@ -184,12 +184,31 @@ public static void GenerateSummaryMarkdown(string spdxFile, string markdownFile,
markdown.AppendLine("| :-------- | :--- | :--- |");
foreach (var package in tools)
markdown.AppendLine(
$"| {package.Name} | {package.Version ?? string.Empty} | {package.ConcludedLicense} |");
$"| {package.Name} | {package.Version ?? string.Empty} | {License(package)} |");
markdown.AppendLine();
markdown.AppendLine();
}

// Save the Markdown text to file
File.WriteAllText(markdownFile, markdown.ToString());
}

/// <summary>
/// Get a license for a package
/// </summary>
/// <param name="package">SPDX package</param>
/// <returns>License</returns>
private static string License(SpdxPackage package)
{
// Use the concluded license if available
if (!string.IsNullOrEmpty(package.ConcludedLicense) && package.ConcludedLicense != "NOASSERTION")
return package.ConcludedLicense;

// Use the declared license if available
if (!string.IsNullOrEmpty(package.DeclaredLicense) && package.DeclaredLicense != "NOASSERTION")
return package.DeclaredLicense;

// Could not find license
return "NOASSERTION";
}
}

0 comments on commit 3c6d57e

Please sign in to comment.