Skip to content

Commit

Permalink
(cake-contribGH-480) Add support for reading SARIF files (cake-contri…
Browse files Browse the repository at this point in the history
  • Loading branch information
pascalberger authored Jul 25, 2024
1 parent 9ad7ff4 commit 33790a6
Show file tree
Hide file tree
Showing 10 changed files with 98 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ For recipe compatible with Cake Script Runners see Cake.Issues.Recipe.</Descript
<PackageReference Include="Cake.Frosting.Issues.InspectCode" Version="4.9.0" />
<PackageReference Include="Cake.Frosting.Issues.Markdownlint" Version="4.9.0" />
<PackageReference Include="Cake.Frosting.Issues.MsBuild" Version="4.9.0" />
<PackageReference Include="Cake.Frosting.Issues.Sarif" Version="4.9.0" />
<PackageReference Include="Cake.Frosting.Issues.PullRequests" Version="4.9.0" />
<PackageReference Include="Cake.Frosting.Issues.PullRequests.AppVeyor" Version="4.9.0" />
<PackageReference Include="Cake.Frosting.Issues.PullRequests.AzureDevOps" Version="4.9.0" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,11 @@ public interface IIssuesParametersInputFiles
/// </summary>
IDictionary<FilePath, IReadIssuesSettings> EsLintJsonLogFilePaths { get; }

/// <summary>
/// Gets list of registered paths to SARIF log files.
/// </summary>
IDictionary<FilePath, IReadIssuesSettings> SarifLogFilePaths { get; }

/// <summary>
/// Adds a path to a MSBuild log file created by XmlFileLogger.
/// </summary>
Expand Down Expand Up @@ -132,5 +137,18 @@ public interface IIssuesParametersInputFiles
/// <param name="logfilePath">Path to the ESLint log file.</param>
/// <param name="settings">Settings for reading the log file. <c>Null</c> for default values.</param>
void AddEsLintJsonLogFile(FilePath logfilePath, IReadIssuesSettings settings);

/// <summary>
/// Adds a path to a log file in SARIF format.
/// </summary>
/// <param name="logfilePath">Path to the SARIF log file.</param>
void AddSarifLogFile(FilePath logfilePath);

/// <summary>
/// Adds a path to a log file in SARIF format.
/// </summary>
/// <param name="logfilePath">Path to the SARIF log file.</param>
/// <param name="settings">Settings for reading the log file. <c>Null</c> for default values.</param>
void AddSarifLogFile(FilePath logfilePath, IReadIssuesSettings settings);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ public class IssuesParametersInputFiles : IIssuesParametersInputFiles
/// <inheritdoc />
public IDictionary<FilePath, IReadIssuesSettings> EsLintJsonLogFilePaths { get; } = new Dictionary<FilePath, IReadIssuesSettings>();

/// <inheritdoc />
public IDictionary<FilePath, IReadIssuesSettings> SarifLogFilePaths { get; } = new Dictionary<FilePath, IReadIssuesSettings>();

/// <inheritdoc />
public void AddMsBuildXmlFileLoggerLogFile(FilePath logfilePath)
{
Expand Down Expand Up @@ -140,5 +143,21 @@ public void AddEsLintJsonLogFile(FilePath logfilePath, IReadIssuesSettings setti

this.EsLintJsonLogFilePaths.Add(logfilePath, settings);
}

/// <inheritdoc />
public void AddSarifLogFile(FilePath logfilePath)
{
logfilePath.NotNull(nameof(logfilePath));

this.AddSarifLogFile(logfilePath, null);
}

/// <inheritdoc />
public void AddSarifLogFile(FilePath logfilePath, IReadIssuesSettings settings)
{
logfilePath.NotNull(nameof(logfilePath));

this.SarifLogFilePaths.Add(logfilePath, settings);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,20 @@ public override void Run(IIssuesContext context)
logFile.Value);
}

// Read SARIF log files.
foreach (var logFile in context.Parameters.InputFiles.SarifLogFilePaths)
{
context.State.AddIssues(
context.SarifIssues(
new SarifIssuesSettings(logFile.Key)
{
// Since there might be multiple SARIF log files we need to have a predictable
// issue provider name for reporting pull request states.
UseToolNameAsIssueProviderName = false
}),
logFile.Value);
}

context.Information("{0} issues are found.", context.State.Issues.Count());
}
}
Expand Down
1 change: 1 addition & 0 deletions Cake.Issues.Recipe/Content/addins.cake
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#addin nuget:?package=Cake.Issues.InspectCode&version=4.9.0
#addin nuget:?package=Cake.Issues.Markdownlint&version=4.9.0
#addin nuget:?package=Cake.Issues.EsLint&version=4.9.0
#addin nuget:?package=Cake.Issues.Sarif&version=4.9.0
#addin nuget:?package=Cake.Issues.Reporting&version=4.9.0
#addin nuget:?package=Cake.Issues.Reporting.Generic&version=4.9.0
#addin nuget:?package=Cake.Issues.Reporting.Sarif&version=4.9.0
Expand Down
14 changes: 14 additions & 0 deletions Cake.Issues.Recipe/Content/build.cake
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,20 @@ IssuesBuildTasks.ReadIssuesTask = Task("Read-Issues")
logFile.Value);
}

// Read SARIF log files.
foreach (var logFile in IssuesParameters.InputFiles.SarifLogFilePaths)
{
data.AddIssues(
SarifIssues(
new SarifIssuesSettings(logFile.Key)
{
// Since there might be multiple SARIF log files we need to have a predictable
// issue provider name for reporting pull request states.
UseToolNameAsIssueProviderName = false
}),
logFile.Value);
}

Information("{0} issues are found.", data.Issues.Count());
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,11 @@ public class IssuesParametersInputFiles
/// </summary>
public IDictionary<FilePath, IReadIssuesSettings> EsLintJsonLogFilePaths { get; } = new Dictionary<FilePath, IReadIssuesSettings>();

/// <summary>
/// Gets list of registered paths to SARIF log files.
/// </summary>
public IDictionary<FilePath, IReadIssuesSettings> SarifLogFilePaths { get; } = new Dictionary<FilePath, IReadIssuesSettings>();

/// <summary>
/// Adds a path to a MSBuild log file created by XmlFileLogger.
/// </summary>
Expand Down Expand Up @@ -184,4 +189,24 @@ public class IssuesParametersInputFiles
logfilePath.NotNull(nameof(logfilePath));
this.EsLintJsonLogFilePaths.Add(logfilePath, settings);
}

/// <summary>
/// Adds a path to a log file in SARIF format.
/// </summary>
/// <param name="logfilePath">Path to the SARIF log file.</param>
public void AddSarifLogFile(FilePath logfilePath)
{
logfilePath.NotNull(nameof(logfilePath));
this.AddSarifLogFile(logfilePath, null);
}
/// <summary>
/// Adds a path to a log file in SARIF format.
/// </summary>
/// <param name="logfilePath">Path to the SARIF log file.</param>
/// <param name="settings">Settings for reading the log file. <c>Null</c> for default values.</param>
public void AddSarifLogFile(FilePath logfilePath, IReadIssuesSettings settings)
{
logfilePath.NotNull(nameof(logfilePath));
this.SarifLogFilePaths.Add(logfilePath, settings);
}
}
1 change: 1 addition & 0 deletions docs/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ By default [Cake.Git addin] will be used.
| `IssuesParameters.InputFiles.`<br/>&nbsp;&nbsp;&nbsp;&nbsp;`AddMarkdownlintCliJsonLogFile()` | `IssuesContext.Parameters.InputFiles.`<br/>&nbsp;&nbsp;&nbsp;&nbsp;`AddMarkdownlintCliJsonLogFile()` | Adds a path to a markdownlint-cli log file writting with `--json`. |
| `IssuesParameters.InputFiles.`<br/>&nbsp;&nbsp;&nbsp;&nbsp;`AddMarkdownlintV1LogFile()` | `IssuesContext.Parameters.InputFiles.`<br/>&nbsp;&nbsp;&nbsp;&nbsp;`AddMarkdownlintV1LogFile()` | Adds a path to a markdownlint log file in version 1. |
| `IssuesParameters.InputFiles.`<br/>&nbsp;&nbsp;&nbsp;&nbsp;`AddEsLintJsonLogFile()` | `IssuesContext.Parameters.InputFiles.`<br/>&nbsp;&nbsp;&nbsp;&nbsp;`AddEsLintJsonLogFile()` | Adds a path to a ESLint log file generated by the [ESLint json formatter]. |
| `IssuesParameters.InputFiles.`<br/>&nbsp;&nbsp;&nbsp;&nbsp;`AddSarifLogFile()` | `IssuesContext.Parameters.InputFiles.`<br/>&nbsp;&nbsp;&nbsp;&nbsp;`AddSarifLogFile()` | Adds a path to a SARIF log file. |

[ESLint json formatter]: https://eslint.org/docs/user-guide/formatters/#json

Expand Down
3 changes: 3 additions & 0 deletions docs/overview.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ Cake.Issues recipes will add the following addins to your build:
| [Cake.Issues.InspectCode] 4.9.0 | [Cake.Frosting.Issues.InspectCode] 4.9.0 | |
| [Cake.Issues.Markdownlint] 4.9.0 | [Cake.Frosting.Issues.Markdownlint] 4.9.0 | |
| [Cake.Issues.EsLint] 4.9.0 | [Cake.Frosting.Issues.EsLint] 4.9.0 | |
| [Cake.Issues.Sarif] 4.9.0 | [Cake.Frosting.Issues.Sarif] 4.9.0 | |
| [Cake.Issues.Reporting] 4.9.0 | [Cake.Frosting.Issues.Reporting] 4.9.0 | |
| [Cake.Issues.Reporting.Generic] 4.9.0 | [Cake.Frosting.Issues.Reporting.Generic] 4.9.0 | |
| [Cake.Issues.Reporting.Sarif] 4.9.0 | [Cake.Frosting.Issues.Reporting.Sarif] 4.9.0 | |
Expand Down Expand Up @@ -58,6 +59,8 @@ Cake.Issues recipes will add the following addins to your build:
[Cake.Frosting.Issues.Markdownlint]: https://cakebuild.net/extensions/cake-issues-markdownlint/
[Cake.Issues.EsLint]: https://cakebuild.net/extensions/cake-issues-eslint/
[Cake.Frosting.Issues.EsLint]: https://cakebuild.net/extensions/cake-issues-eslint/
[Cake.Issues.Sarif]: https://cakebuild.net/extensions/cake-issues-sarif/
[Cake.Frosting.Issues.Sarif]: https://cakebuild.net/extensions/cake-issues-sarif/
[Cake.Issues.Reporting]: https://cakebuild.net/extensions/cake-issues-reporting/
[Cake.Frosting.Issues.Reporting]: https://cakebuild.net/extensions/cake-issues-reporting/
[Cake.Issues.Reporting.Generic]: https://cakebuild.net/extensions/cake-issues-reporting-generic/
Expand Down
2 changes: 2 additions & 0 deletions docs/supported-tools.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,14 @@ Cake.Issues recipes support reading issues from output of the following tools:
| markdownlint | [markdownlint-cli] with `--json` | `IssuesParameters.InputFiles.`<br/>&nbsp;&nbsp;&nbsp;&nbsp;`AddMarkdownlintCliJsonLogFile()` | `IssuesContext.Parameters.InputFiles.`<br/>&nbsp;&nbsp;&nbsp;&nbsp;`AddMarkdownlintCliJsonLogFile()` |
| markdownlint | [markdownlint] version 1 | `IssuesParameters.InputFiles.`<br/>&nbsp;&nbsp;&nbsp;&nbsp;`AddMarkdownlintV1LogFile()` | `IssuesContext.Parameters.InputFiles.`<br/>&nbsp;&nbsp;&nbsp;&nbsp;`AddMarkdownlintV1LogFile()` |
| [ESLint] | [json formatter] | `IssuesParameters.InputFiles.`<br/>&nbsp;&nbsp;&nbsp;&nbsp;`AddEsLintJsonLogFile()` | `IssuesContext.Parameters.InputFiles.`<br/>&nbsp;&nbsp;&nbsp;&nbsp;`AddEsLintJsonLogFile()` |
| Any SARIF compatible tool | [SARIF] | `IssuesParameters.InputFiles.`<br/>&nbsp;&nbsp;&nbsp;&nbsp;`AddSarifLogFile()` | `IssuesContext.Parameters.InputFiles.`<br/>&nbsp;&nbsp;&nbsp;&nbsp;`AddSarifLogFile()` |

[MSBuild Extension Pack XmlFileLogger]: http://www.msbuildextensionpack.com/help/4.0.5.0/html/242ab4fd-c2e2-f6aa-325b-7588725aed24.htm
[markdownlint-cli]: https://github.com/igorshubovych/markdownlint-cli
[markdownlint]: https://github.com/DavidAnson/markdownlint
[ESLint]: https://eslint.org/
[json formatter]: https://eslint.org/docs/user-guide/formatters/#json
[SARIF]: https://sarifweb.azurewebsites.net/

# Build systems

Expand Down

0 comments on commit 33790a6

Please sign in to comment.