diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml new file mode 100644 index 000000000..f32ddcb82 --- /dev/null +++ b/.github/workflows/build.yml @@ -0,0 +1,68 @@ +name: Build and tests + +# Workflow Trigger +on: + # Trigger the workflow on a pull request to any branch + pull_request: + # Triggers the workflow in the event there is a push to master + push: + branches: + - master + +jobs: + # Build + Build: + name: Build + runs-on: ubuntu-22.04 + steps: + - name: Get the sources + uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4 + - name: Fetch all tags and branches + run: git fetch --prune --unshallow + - name: Install .NET + uses: actions/setup-dotnet@4d6c8fcf3c8f7a60068d26b594648e99df24cee3 # v4 + with: + # .NET 5 required for GitVersion + dotnet-version: | + 5.x + 6.x + 7.x + 8.x + - name: Build + run: ./build.sh + shell: bash + - name: Publish NuGet package as build artifact + uses: actions/upload-artifact@5d5d22a31266ced268874388b861e4b58bb5c2f3 # v4 + with: + name: NuGet Package + path: ./BuildArtifacts/Packages/NuGet/ + # Integration Tests Cake.Issues.PullRequests.GitHubActions Cake Scripting + IntegrationTestsPullRequestsGitHubActionsCakeScripting: + name: Integration Tests Cake.Issues.PullRequests.GitHubActions Cake Scripting + needs: Build + strategy: + fail-fast: false + matrix: + os: [ + windows-2019, windows-2022, + # Disabled until https://github.com/cake-contrib/Cake.Issues/issues/514 is fixed + # ubuntu-20.04, ubuntu-22.04, + macos-11, macos-14] + dotnet: [6.x, 7.x, 8.x] + runs-on: ${{ matrix.os }} + steps: + - name: Get the sources + uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4 + - name: Download build artifact + uses: actions/download-artifact@eaceaf801fd36c7dee90939fad912460b18a1ffe # v4 + with: + name: NuGet Package + path: ./BuildArtifacts/Packages/NuGet + - name: Install .NET + uses: actions/setup-dotnet@4d6c8fcf3c8f7a60068d26b594648e99df24cee3 # v4 + with: + dotnet-version: ${{ matrix.dotnet }} + - name: Run integration tests + run: ./build.sh --verbosity=diagnostic + working-directory: ./tests/Cake.Issues.PullRequests.GitHubActions/script-runner/ + shell: bash diff --git a/CiStatus.md b/CiStatus.md index a0ab35025..dc4a26fb4 100644 --- a/CiStatus.md +++ b/CiStatus.md @@ -1,6 +1,6 @@ # Build & Test Status -## Build / Unit Tests +## Build / Tests | CI Server | Runner | Operating System | Develop | Master | |:--:|:--:|:--:|:--:|:--:| @@ -8,6 +8,7 @@ |Azure Pipelines|N/A|Windows|[![Build Status](https://dev.azure.com/cake-contrib/Cake.Issues/_apis/build/status%2Fcake-contrib.Cake.Issues?branchName=develop&jobName=Build%20%26%20Unit%20Tests&configuration=Build%20%26%20Unit%20Tests%20Windows)](https://dev.azure.com/cake-contrib/Cake.Issues/_build/latest?definitionId=2&branchName=develop)|[![Build Status](https://dev.azure.com/cake-contrib/Cake.Issues/_apis/build/status%2Fcake-contrib.Cake.Issues?branchName=master&jobName=Build%20%26%20Unit%20Tests&configuration=Build%20%26%20Unit%20Tests%20Windows)](https://dev.azure.com/cake-contrib/Cake.Issues/_build/latest?definitionId=2&branchName=master)| |Azure Pipelines|N/A|Ubuntu|[![Build Status](https://dev.azure.com/cake-contrib/Cake.Issues/_apis/build/status%2Fcake-contrib.Cake.Issues?branchName=develop&jobName=Build%20%26%20Unit%20Tests&configuration=Build%20%26%20Unit%20Tests%20Ubuntu)](https://dev.azure.com/cake-contrib/Cake.Issues/_build/latest?definitionId=2&branchName=develop)|[![Build Status](https://dev.azure.com/cake-contrib/Cake.Issues/_apis/build/status%2Fcake-contrib.Cake.Issues?branchName=master&jobName=Build%20%26%20Unit%20Tests&configuration=Build%20%26%20Unit%20Tests%20Ubuntu)](https://dev.azure.com/cake-contrib/Cake.Issues/_build/latest?definitionId=2&branchName=master)| |Azure Pipelines|N/A|macOS|[![Build Status](https://dev.azure.com/cake-contrib/Cake.Issues/_apis/build/status%2Fcake-contrib.Cake.Issues?branchName=develop&jobName=Build%20%26%20Unit%20Tests&configuration=Build%20%26%20Unit%20Tests%20macOS)](https://dev.azure.com/cake-contrib/Cake.Issues/_build/latest?definitionId=2&branchName=develop)|[![Build Status](https://dev.azure.com/cake-contrib/Cake.Issues/_apis/build/status%2Fcake-contrib.Cake.Issues?branchName=master&jobName=Build%20%26%20Unit%20Tests&configuration=Build%20%26%20Unit%20Tests%20macOS)](https://dev.azure.com/cake-contrib/Cake.Issues/_build/latest?definitionId=2&branchName=master)| +|GitHub Actions|N/A|Ubuntu|[![Build and tests](https://github.com/cake-contrib/Cake.Issues/actions/workflows/build.yml/badge.svg?branch=develop)](https://github.com/cake-contrib/Cake.Issues/actions/workflows/build.yml)|[![Build and tests](https://github.com/cake-contrib/Cake.Issues/actions/workflows/build.yml/badge.svg?branch=master)](https://github.com/cake-contrib/Cake.Issues/actions/workflows/build.yml)| ## Integration Tests Cake.Issues.GitRepository diff --git a/README.md b/README.md index db8ebf5dd..9f195a37b 100644 --- a/README.md +++ b/README.md @@ -126,6 +126,7 @@ For questions and to discuss ideas & feature requests, use the [GitHub discussio | [Cake.Issues.PullRequests](https://www.nuget.org/packages/Cake.Issues.PullRequests) | [Cake.Frosting.Issues.PullRequests](https://www.nuget.org/packages/Cake.Frosting.Issues.PullRequests) | Addin providing the aliases for writing issues to pull requests and build servers. | | [Cake.Issues.PullRequests.AppVeyor](https://www.nuget.org/packages/Cake.Issues.PullRequests.AppVeyor) | [Cake.Issues.PullRequests.AppVeyor](https://www.nuget.org/packages/Cake.Issues.PullRequests.AppVeyor) | Integration with AppVeyor builds. | | [Cake.Issues.PullRequests.AzureDevOps](https://www.nuget.org/packages/Cake.Issues.PullRequests.AzureDevOps) | [Cake.Frosting.Issues.PullRequests.AzureDevOps](https://www.nuget.org/packages/Cake.Frosting.Issues.PullRequests.AzureDevOps) | Integration with Azure DevOps pull requests. | +| [Cake.Issues.PullRequests.GitHubActions](https://www.nuget.org/packages/Cake.Issues.PullRequests.GitHubActions) | [Cake.Issues.PullRequests.AzureDevOps](https://www.nuget.org/packages/Cake.Issues.PullRequests.AzureDevOps) | Integration with GitHub Actions. | | [Cake.Issues.Reporting](https://www.nuget.org/packages/Cake.Issues.Reporting) | [Cake.Frosting.Issues.Reporting](https://www.nuget.org/packages/Cake.Frosting.Issues.Reporting) | Addin providing the aliases for creating reports. | | [Cake.Issues.Reporting.Console](https://www.nuget.org/packages/Cake.Issues.Reporting.Console) | [Cake.Frosting.Issues.Reporting.Console](https://www.nuget.org/packages/Cake.Frosting.Issues.Reporting.Console) | Support for reporting issues to the console. | | [Cake.Issues.Reporting.Generic](https://www.nuget.org/packages/Cake.Issues.Reporting.Generic) | [Cake.Frosting.Issues.Reporting.Generic](https://www.nuget.org/packages/Cake.Frosting.Issues.Reporting.Generic) | Support for creating reports in any text based format (HTML, Markdown, ...). | diff --git a/docs/input/docs/pull-request-systems/github-actions/examples/index.cshtml b/docs/input/docs/pull-request-systems/github-actions/examples/index.cshtml new file mode 100644 index 000000000..f6edfee20 --- /dev/null +++ b/docs/input/docs/pull-request-systems/github-actions/examples/index.cshtml @@ -0,0 +1,7 @@ +--- +Title: Examples +Description: Examples for using the Cake.Issues.PullRequests.GitHubActions addin. +--- +

@Html.Raw(Model.String(DocsKeys.Description))

+ +@Html.Partial("_ChildPages") \ No newline at end of file diff --git a/docs/input/docs/pull-request-systems/github-actions/examples/write-annotations.md b/docs/input/docs/pull-request-systems/github-actions/examples/write-annotations.md new file mode 100644 index 000000000..719a51917 --- /dev/null +++ b/docs/input/docs/pull-request-systems/github-actions/examples/write-annotations.md @@ -0,0 +1,54 @@ +--- +Order: 10 +Title: Create annotations in GitHub Actions +Description: Example how to write issues as annotations to a GitHub Actions build. +--- +This example shows how to report issues as annotations to a GitHub Actions build. + +To report issues as annotations to a GitHub Actions build you need to import the core addin, +the core pull request addin, the GitHub Actions support and one or more issue providers, +in this example for JetBrains InspectCode: + +```csharp +#addin "Cake.Issues" +#addin "Cake.Issues.InspectCode" +#addin "Cake.Issues.PullRequests" +#addin "Cake.Issues.PullRequests.GitHubActions" +``` + +:::{.alert .alert-warning} +Please note that you always should pin addins to a specific version to make sure your builds are deterministic and +won't break due to updates to one of the addins. + +See [pinning addin versions](https://cakebuild.net/docs/tutorials/pinning-cake-version#pinning-addin-version) for details. +::: + +In the following task we'll first determine the remote repository URL and +source branch of the pull request and with this information call the [GitHubActionsBuilds] alias: + +```csharp +Task("ReportIssuesToGitHubActions").Does(() => +{ + var repoRootFolder = MakeAbsolute(Directory("./")); + + ReportIssuesToPullRequest( + InspectCodeIssuesFromFilePath( + @"C:\build\inspectcode.log"), + GitHubActionsBuilds(), + repoRootFolder); +}); +``` + +The output will show up in the build log grouped by issue provider / run: + +![Log output](../githubactions-log-output.png "Log output") + +Additionally the issues show up as annotations: + +![Annotations](../githubactions-annotations.png "Annotations") + +Having issues available as annotations also means that they will be shown in pull requests on the related file / position: + +![Pull request integration](../githubactions-pullrequest-integration.png "Pull request integration") + +[GitHubActionsBuilds]: ../../../../api/Cake.Issues.PullRequests.GitHubActions/GitHubActionsBuildsAliases/ diff --git a/docs/input/docs/pull-request-systems/github-actions/features.md b/docs/input/docs/pull-request-systems/github-actions/features.md new file mode 100644 index 000000000..91dea5e3c --- /dev/null +++ b/docs/input/docs/pull-request-systems/github-actions/features.md @@ -0,0 +1,25 @@ +--- +Order: 20 +Title: Features +Description: Features of the Cake.Issues.PullRequests.GitHubActions addin. +--- +The [Cake.Issues.PullRequests.GitHubActions addin] creates annotations from issues when running on GitHub actions. + +![Pull request integration](githubactions-pullrequest-integration.png "Pull request integration") + +# Basic features + +* Reports issues as annotations to GitHub Actions builds. +* Group issues in log output by provider and run information. + +# Supported capabilities + +The [Cake.Issues.PullRequests.GitHubActions addin] doesn't support any additional capabilities. + +| | Capability | Remarks | +|--------------------------------------------------------------------|--------------------------------|--------------------------------| +| | Checking commit ID | | +| | Discussion threads | | +| | Filtering by modified files | | + +[Cake.Issues.PullRequests.GitHubActions addin]: https://www.nuget.org/packages/Cake.Issues.PullRequests.GitHubActions diff --git a/docs/input/docs/pull-request-systems/github-actions/githubactions-annotations.png b/docs/input/docs/pull-request-systems/github-actions/githubactions-annotations.png new file mode 100644 index 000000000..d9c8bb693 Binary files /dev/null and b/docs/input/docs/pull-request-systems/github-actions/githubactions-annotations.png differ diff --git a/docs/input/docs/pull-request-systems/github-actions/githubactions-log-output.png b/docs/input/docs/pull-request-systems/github-actions/githubactions-log-output.png new file mode 100644 index 000000000..779bc0b9b Binary files /dev/null and b/docs/input/docs/pull-request-systems/github-actions/githubactions-log-output.png differ diff --git a/docs/input/docs/pull-request-systems/github-actions/githubactions-pullrequest-integration.png b/docs/input/docs/pull-request-systems/github-actions/githubactions-pullrequest-integration.png new file mode 100644 index 000000000..def6f8cb0 Binary files /dev/null and b/docs/input/docs/pull-request-systems/github-actions/githubactions-pullrequest-integration.png differ diff --git a/docs/input/docs/pull-request-systems/github-actions/index.cshtml b/docs/input/docs/pull-request-systems/github-actions/index.cshtml new file mode 100644 index 000000000..aba361913 --- /dev/null +++ b/docs/input/docs/pull-request-systems/github-actions/index.cshtml @@ -0,0 +1,10 @@ +--- +Title: GitHub Actions +Description: Support for GitHub Actions. +--- +

+ Support for GitHub Actions is implemented in the + Cake.Issues.PullRequests.GitHubActions addin. +

+ +@Html.Partial("_ChildPages") \ No newline at end of file diff --git a/docs/input/docs/pull-request-systems/github-actions/requirements.md b/docs/input/docs/pull-request-systems/github-actions/requirements.md new file mode 100644 index 000000000..e1e66947a --- /dev/null +++ b/docs/input/docs/pull-request-systems/github-actions/requirements.md @@ -0,0 +1,9 @@ +--- +Order: 10 +Title: Requirements +Description: Requirements for the Cake.Issues.PullRequests.GitHubActions addin. +--- +The requirements for using the [Cake.Issues.PullRequests.GitHubActions addin] are listed in the [release notes] for any specific version. + +[Cake.Issues.PullRequests.GitHubActions addin]: https://www.nuget.org/packages/Cake.Issues.PullRequests.GitHubActions +[release notes]: release-notes diff --git a/nuspec/nuget/Cake.Issues.PullRequests.GitHubActions.nuspec b/nuspec/nuget/Cake.Issues.PullRequests.GitHubActions.nuspec new file mode 100644 index 000000000..b6ed5aa37 --- /dev/null +++ b/nuspec/nuget/Cake.Issues.PullRequests.GitHubActions.nuspec @@ -0,0 +1,39 @@ + + + + Cake.Issues.PullRequests.GitHubActions + Cake.Issues.PullRequests.GitHubActions + 0.0.0 + Cake Issues contributors + pascalberger, cake-contrib + GitHub Actions support for the Cake.Issues addin for Cake Build Automation System + +GitHub Actions support for the Cake.Issues addin for Cake allows you to report to GitHub Actions builds. + +This addin provides the aliases for writing to GitHub Actions builds. +It also requires the core Cake.Issues and Cake.Issues.PullRequests addins and one or more issue providers. + +See the Project Site for an overview of the whole ecosystem of addins for working with issues in Cake scripts. + + MIT + https://cakeissues.net + icon.png + false + + Copyright © Cake Issues contributors + cake cake-addin cake-issues cake-pullrequestsystem issues pullrequest buildserver github github-actions + https://github.com/cake-contrib/Cake.Issues/releases/tag/4.0.0 + + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/Cake.Issues.PullRequests.GitHubActions.Tests/Cake.Issues.PullRequests.GitHubActions.Tests.csproj b/src/Cake.Issues.PullRequests.GitHubActions.Tests/Cake.Issues.PullRequests.GitHubActions.Tests.csproj new file mode 100644 index 000000000..62e6abb40 --- /dev/null +++ b/src/Cake.Issues.PullRequests.GitHubActions.Tests/Cake.Issues.PullRequests.GitHubActions.Tests.csproj @@ -0,0 +1,37 @@ + + + + net6.0 + false + Tests for the Cake.Issues.PullRequests.GitHubActions addin + Cake Issues contributors + Copyright © Cake Issues contributors + Cake.Issues + + + + ..\Cake.Issues.Tests.ruleset + + + + + + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + + + + + + + + + + diff --git a/src/Cake.Issues.PullRequests.GitHubActions.Tests/GitHubActionsBuildSettingsTests.cs b/src/Cake.Issues.PullRequests.GitHubActions.Tests/GitHubActionsBuildSettingsTests.cs new file mode 100644 index 000000000..1d5d4ac42 --- /dev/null +++ b/src/Cake.Issues.PullRequests.GitHubActions.Tests/GitHubActionsBuildSettingsTests.cs @@ -0,0 +1,15 @@ +namespace Cake.Issues.PullRequests.GitHubActions.Tests +{ + using System; + using Cake.Issues.Testing; + using Cake.Testing; + using Shouldly; + using Xunit; + + public sealed class GitHubActionsBuildSettingsTests + { + public sealed class TheCtor + { + } + } +} \ No newline at end of file diff --git a/src/Cake.Issues.PullRequests.GitHubActions/Cake.Issues.PullRequests.GitHubActions.csproj b/src/Cake.Issues.PullRequests.GitHubActions/Cake.Issues.PullRequests.GitHubActions.csproj new file mode 100644 index 000000000..382066ef8 --- /dev/null +++ b/src/Cake.Issues.PullRequests.GitHubActions/Cake.Issues.PullRequests.GitHubActions.csproj @@ -0,0 +1,35 @@ + + + + net6.0;net7.0;net8.0 + Addin for writing code analyzer or linter issues to GitHub Actions + Cake Issues contributors + Copyright © Cake Issues contributors + Cake.Issues + + + + full + true + AllEnabledByDefault + ..\Cake.Issues.ruleset + bin\$(Configuration)\$(TargetFramework)\Cake.Issues.PullRequests.GitHubActions.xml + + + + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + + + + + + + + diff --git a/src/Cake.Issues.PullRequests.GitHubActions/GitHubActionsBuildSettings.cs b/src/Cake.Issues.PullRequests.GitHubActions/GitHubActionsBuildSettings.cs new file mode 100644 index 000000000..beb2aedef --- /dev/null +++ b/src/Cake.Issues.PullRequests.GitHubActions/GitHubActionsBuildSettings.cs @@ -0,0 +1,14 @@ +namespace Cake.Issues.PullRequests.GitHubActions +{ + /// + /// Settings for . + /// + public class GitHubActionsBuildSettings + { + /// + /// Gets or sets a value indicating whether issues should be grouped by issue provider and run information. + /// Enabled by default. + /// + public bool GroupIssues { get; set; } = true; + } +} \ No newline at end of file diff --git a/src/Cake.Issues.PullRequests.GitHubActions/GitHubActionsBuildsAliases.cs b/src/Cake.Issues.PullRequests.GitHubActions/GitHubActionsBuildsAliases.cs new file mode 100644 index 000000000..811f1fa47 --- /dev/null +++ b/src/Cake.Issues.PullRequests.GitHubActions/GitHubActionsBuildsAliases.cs @@ -0,0 +1,76 @@ +namespace Cake.Issues.PullRequests.GitHubActions +{ + using Cake.Core; + using Cake.Core.Annotations; + + /// + /// Contains functionality related to writing code analysis issues to GitHub Actions. + /// + [CakeAliasCategory(IssuesAliasConstants.MainCakeAliasCategory)] + public static class GitHubActionsBuildsAliases + { + /// + /// Gets an object for writing issues to GitHub Actions using the default settings. + /// + /// The context. + /// Object for writing issues to GitHub Actions. + /// + /// Report code analysis issues reported as MsBuild warnings to GitHub Actions: + /// + /// + /// + /// + [CakeMethodAlias] + [CakeAliasCategory(PullRequestsAliasConstants.PullRequestSystemCakeAliasCategory)] + public static IPullRequestSystem GitHubActionsBuilds( + this ICakeContext context) + { + context.NotNull(nameof(context)); + + return new GitHubActionsPullRequestSystem(context, new GitHubActionsBuildSettings()); + } + + /// + /// Gets an object for writing issues to GitHub Actions using the specified settings. + /// + /// The context. + /// Settings for writing issues to GitHub Actions. + /// Object for writing issues to GitHub Actions. + /// + /// Report code analysis issues reported as MsBuild warnings to GitHub Actions: + /// + /// + /// + /// + [CakeMethodAlias] + [CakeAliasCategory(PullRequestsAliasConstants.PullRequestSystemCakeAliasCategory)] + public static IPullRequestSystem GitHubActionsBuilds( + this ICakeContext context, + GitHubActionsBuildSettings settings) + { + context.NotNull(nameof(context)); + settings.NotNull(nameof(settings)); + + return new GitHubActionsPullRequestSystem(context, settings); + } + } +} diff --git a/src/Cake.Issues.PullRequests.GitHubActions/GitHubActionsPullRequestSystem.cs b/src/Cake.Issues.PullRequests.GitHubActions/GitHubActionsPullRequestSystem.cs new file mode 100644 index 000000000..25be50a48 --- /dev/null +++ b/src/Cake.Issues.PullRequests.GitHubActions/GitHubActionsPullRequestSystem.cs @@ -0,0 +1,124 @@ +namespace Cake.Issues.PullRequests.GitHubActions +{ + using System; + using System.Collections.Generic; + using System.Linq; + using Cake.Core; + using Cake.Core.Diagnostics; + using Cake.Core.IO; + + /// + /// Class for posting issues to GitHub Actions. + /// + public class GitHubActionsPullRequestSystem : BasePullRequestSystem + { + private static readonly char[] Separator = ['\n']; + private readonly GitHubActionsBuildSettings settings; + + /// + /// Initializes a new instance of the class. + /// + /// The Cake context. + /// Settings for writing the issues to GitHub Actions. + public GitHubActionsPullRequestSystem(ICakeContext context, GitHubActionsBuildSettings settings) + : base(context?.Log) + { + settings.NotNull(nameof(settings)); + + this.settings = settings; + } + + /// + protected override void InternalPostDiscussionThreads(IEnumerable issues, string commentSource) + { + issues.NotNull(nameof(issues)); + + if (this.settings.GroupIssues) + { + this.WriteGroupedIssues(issues); + } + else + { + this.WriteIssues(issues); + } + } + + /// + /// Formats the options for the warning service message. + /// + /// The root path of the file, relative to the repository root. + /// The file path relative to the project root. + /// The line where the issue ocurred. + /// The column where the issue ocurred. + /// Formatted options string for the warning service message. + private static string FormatWarningOptions(DirectoryPath rootDirectoryPath, FilePath filePath, int? line, int? column) + { + var result = new List(); + + if (filePath != null) + { + result.Add($"file={rootDirectoryPath.CombineWithFilePath(filePath)}"); + } + + if (line.HasValue) + { + result.Add($"line={line.Value}"); + } + + if (column.HasValue) + { + result.Add($"col={column}"); + } + + return string.Join(",", result); + } + + /// + /// Writes services messages to report issues to GitHub Actions grouped by provider and run. + /// + /// Issues which should be reported. + private void WriteGroupedIssues(IEnumerable issues) + { + // Group annotations by provider type and run + var groupedIssues = + from issue in issues + group issue by new { issue.ProviderType, issue.Run }; + + foreach (var group in groupedIssues) + { + var groupName = group.First().ProviderName; + + if (!string.IsNullOrWhiteSpace(group.Key.Run)) + { + groupName += " - " + group.Key.Run; + } + + this.Log.Information($"::group::{groupName}"); + + this.WriteIssues(group); + + this.Log.Information($"::endgroup::{groupName}"); + } + } + + /// + /// Writes services message to report issues to GitHub Actions. + /// + /// Issues which should be reported. + private void WriteIssues(IEnumerable issues) + { + foreach (var issue in issues.OrderByDescending(x => x.Priority)) + { + // Commands don't support line breaks, therefore we only use the first line of the message. + var message = + issue.MessageText + .Split(Separator, StringSplitOptions.RemoveEmptyEntries) + .FirstOrDefault() + ?.Trim(); + + this.Log.Information( + $"::warning {FormatWarningOptions(this.Settings.RepositoryRoot, issue.AffectedFileRelativePath, issue.Line, issue.Column)}::{message}"); + } + } + } +} diff --git a/src/Cake.Issues.Terraform.Tests/Cake.Issues.Terraform.Tests.csproj b/src/Cake.Issues.Terraform.Tests/Cake.Issues.Terraform.Tests.csproj index 535a4d7c0..a1a305f71 100644 --- a/src/Cake.Issues.Terraform.Tests/Cake.Issues.Terraform.Tests.csproj +++ b/src/Cake.Issues.Terraform.Tests/Cake.Issues.Terraform.Tests.csproj @@ -39,10 +39,10 @@ - 2.7.0 + 2.7.1 - 2.5.7 + 2.5.8 runtime; build; native; contentfiles; analyzers all diff --git a/src/Cake.Issues.sln b/src/Cake.Issues.sln index e65219525..109f023be 100644 --- a/src/Cake.Issues.sln +++ b/src/Cake.Issues.sln @@ -150,6 +150,12 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Cake.Issues.Terraform", "Ca EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Cake.Issues.Terraform.Tests", "Cake.Issues.Terraform.Tests\Cake.Issues.Terraform.Tests.csproj", "{5538D216-5A1B-4941-8E3E-B0BF32314751}" EndProject +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "GitHubActions", "GitHubActions", "{E93E527B-60FF-45A3-BCAA-5AADA0A6DDB2}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Cake.Issues.PullRequests.GitHubActions", "Cake.Issues.PullRequests.GitHubActions\Cake.Issues.PullRequests.GitHubActions.csproj", "{D873FA70-A3EB-4B99-AD9B-D8879A752BD7}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Cake.Issues.PullRequests.GitHubActions.Tests", "Cake.Issues.PullRequests.GitHubActions.Tests\Cake.Issues.PullRequests.GitHubActions.Tests.csproj", "{7BFDC8EC-9CFB-4A15-8B00-41A922DD6019}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -288,6 +294,14 @@ Global {5538D216-5A1B-4941-8E3E-B0BF32314751}.Debug|Any CPU.Build.0 = Debug|Any CPU {5538D216-5A1B-4941-8E3E-B0BF32314751}.Release|Any CPU.ActiveCfg = Release|Any CPU {5538D216-5A1B-4941-8E3E-B0BF32314751}.Release|Any CPU.Build.0 = Release|Any CPU + {D873FA70-A3EB-4B99-AD9B-D8879A752BD7}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {D873FA70-A3EB-4B99-AD9B-D8879A752BD7}.Debug|Any CPU.Build.0 = Debug|Any CPU + {D873FA70-A3EB-4B99-AD9B-D8879A752BD7}.Release|Any CPU.ActiveCfg = Release|Any CPU + {D873FA70-A3EB-4B99-AD9B-D8879A752BD7}.Release|Any CPU.Build.0 = Release|Any CPU + {7BFDC8EC-9CFB-4A15-8B00-41A922DD6019}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {7BFDC8EC-9CFB-4A15-8B00-41A922DD6019}.Debug|Any CPU.Build.0 = Debug|Any CPU + {7BFDC8EC-9CFB-4A15-8B00-41A922DD6019}.Release|Any CPU.ActiveCfg = Release|Any CPU + {7BFDC8EC-9CFB-4A15-8B00-41A922DD6019}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -343,6 +357,9 @@ Global {9323409D-2A31-4D93-8479-3DBBC154816A} = {D404813F-4EBD-4093-BA1C-B5BFEB781A65} {F9FC503D-6A0B-423F-BA00-9AAA7C9CAA17} = {9323409D-2A31-4D93-8479-3DBBC154816A} {5538D216-5A1B-4941-8E3E-B0BF32314751} = {9323409D-2A31-4D93-8479-3DBBC154816A} + {E93E527B-60FF-45A3-BCAA-5AADA0A6DDB2} = {40421A26-BC87-4097-B9B5-EDA8229CB11E} + {D873FA70-A3EB-4B99-AD9B-D8879A752BD7} = {E93E527B-60FF-45A3-BCAA-5AADA0A6DDB2} + {7BFDC8EC-9CFB-4A15-8B00-41A922DD6019} = {E93E527B-60FF-45A3-BCAA-5AADA0A6DDB2} EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution SolutionGuid = {E9F2EC94-9A1B-4834-A464-E5208B210F11} diff --git a/global.json b/src/global.json similarity index 100% rename from global.json rename to src/global.json diff --git a/tests/Cake.Issues.PullRequests.GitHubActions/script-runner/.config/dotnet-tools.json b/tests/Cake.Issues.PullRequests.GitHubActions/script-runner/.config/dotnet-tools.json new file mode 100644 index 000000000..da200cdae --- /dev/null +++ b/tests/Cake.Issues.PullRequests.GitHubActions/script-runner/.config/dotnet-tools.json @@ -0,0 +1,12 @@ +{ + "version": 1, + "isRoot": true, + "tools": { + "cake.tool": { + "version": "4.0.0", + "commands": [ + "dotnet-cake" + ] + } + } +} \ No newline at end of file diff --git a/tests/Cake.Issues.PullRequests.GitHubActions/script-runner/.gitignore b/tests/Cake.Issues.PullRequests.GitHubActions/script-runner/.gitignore new file mode 100644 index 000000000..e7c496290 --- /dev/null +++ b/tests/Cake.Issues.PullRequests.GitHubActions/script-runner/.gitignore @@ -0,0 +1,379 @@ + +# Created by https://www.gitignore.io/api/cake,windows,visualstudio,visualstudiocode + +### Cake ### +tools/* +!tools/packages.config + +### VisualStudioCode ### +.vscode/* +!.vscode/settings.json +!.vscode/tasks.json +!.vscode/launch.json +!.vscode/extensions.json + +### Windows ### +# Windows thumbnail cache files +Thumbs.db +ehthumbs.db +ehthumbs_vista.db + +# Dump file +*.stackdump + +# Folder config file +[Dd]esktop.ini + +# Recycle Bin used on file shares +$RECYCLE.BIN/ + +# Windows Installer files +*.cab +*.msi +*.msix +*.msm +*.msp + +# Windows shortcuts +*.lnk + +### VisualStudio ### +## Ignore Visual Studio temporary files, build results, and +## files generated by popular Visual Studio add-ons. +## +## Get latest from https://github.com/github/gitignore/blob/master/VisualStudio.gitignore + +# User-specific files +*.suo +*.user +*.userosscache +*.sln.docstates + +# User-specific files (MonoDevelop/Xamarin Studio) +*.userprefs + +# Build results +[Dd]ebug/ +[Dd]ebugPublic/ +[Rr]elease/ +[Rr]eleases/ +x64/ +x86/ +bld/ +[Bb]in/ +[Oo]bj/ +[Ll]og/ + +# Visual Studio 2015/2017 cache/options directory +.vs/ +# Uncomment if you have tasks that create the project's static files in wwwroot +#wwwroot/ + +# Visual Studio 2017 auto generated files +Generated\ Files/ + +# MSTest test Results +[Tt]est[Rr]esult*/ +[Bb]uild[Ll]og.* + +# NUNIT +*.VisualState.xml +TestResult.xml + +# Build Results of an ATL Project +[Dd]ebugPS/ +[Rr]eleasePS/ +dlldata.c + +# Benchmark Results +BenchmarkDotNet.Artifacts/ + +# .NET Core +project.lock.json +project.fragment.lock.json +artifacts/ + +# StyleCop +StyleCopReport.xml + +# Files built by Visual Studio +*_i.c +*_p.c +*_i.h +*.ilk +*.meta +*.obj +*.iobj +*.pch +*.pdb +*.ipdb +*.pgc +*.pgd +*.rsp +*.sbr +*.tlb +*.tli +*.tlh +*.tmp +*.tmp_proj +*.log +*.vspscc +*.vssscc +.builds +*.pidb +*.svclog +*.scc + +# Chutzpah Test files +_Chutzpah* + +# Visual C++ cache files +ipch/ +*.aps +*.ncb +*.opendb +*.opensdf +*.sdf +*.cachefile +*.VC.db +*.VC.VC.opendb + +# Visual Studio profiler +*.psess +*.vsp +*.vspx +*.sap + +# Visual Studio Trace Files +*.e2e + +# TFS 2012 Local Workspace +$tf/ + +# Guidance Automation Toolkit +*.gpState + +# ReSharper is a .NET coding add-in +_ReSharper*/ +*.[Rr]e[Ss]harper +*.DotSettings.user + +# JustCode is a .NET coding add-in +.JustCode + +# TeamCity is a build add-in +_TeamCity* + +# DotCover is a Code Coverage Tool +*.dotCover + +# AxoCover is a Code Coverage Tool +.axoCover/* +!.axoCover/settings.json + +# Visual Studio code coverage results +*.coverage +*.coveragexml + +# NCrunch +_NCrunch_* +.*crunch*.local.xml +nCrunchTemp_* + +# MightyMoose +*.mm.* +AutoTest.Net/ + +# Web workbench (sass) +.sass-cache/ + +# Installshield output folder +[Ee]xpress/ + +# DocProject is a documentation generator add-in +DocProject/buildhelp/ +DocProject/Help/*.HxT +DocProject/Help/*.HxC +DocProject/Help/*.hhc +DocProject/Help/*.hhk +DocProject/Help/*.hhp +DocProject/Help/Html2 +DocProject/Help/html + +# Click-Once directory +publish/ + +# Publish Web Output +*.[Pp]ublish.xml +*.azurePubxml +# Note: Comment the next line if you want to checkin your web deploy settings, +# but database connection strings (with potential passwords) will be unencrypted +*.pubxml +*.publishproj + +# Microsoft Azure Web App publish settings. Comment the next line if you want to +# checkin your Azure Web App publish settings, but sensitive information contained +# in these scripts will be unencrypted +PublishScripts/ + +# NuGet Packages +*.nupkg +# The packages folder can be ignored because of Package Restore +**/[Pp]ackages/* +# except build/, which is used as an MSBuild target. +!**/[Pp]ackages/build/ +# Uncomment if necessary however generally it will be regenerated when needed +#!**/[Pp]ackages/repositories.config +# NuGet v3's project.json files produces more ignorable files +*.nuget.props +*.nuget.targets + +# Microsoft Azure Build Output +csx/ +*.build.csdef + +# Microsoft Azure Emulator +ecf/ +rcf/ + +# Windows Store app package directories and files +AppPackages/ +BundleArtifacts/ +Package.StoreAssociation.xml +_pkginfo.txt +*.appx + +# Visual Studio cache files +# files ending in .cache can be ignored +*.[Cc]ache +# but keep track of directories ending in .cache +!*.[Cc]ache/ + +# Others +ClientBin/ +~$* +*~ +*.dbmdl +*.dbproj.schemaview +*.jfm +*.pfx +*.publishsettings +orleans.codegen.cs + +# Including strong name files can present a security risk +# (https://github.com/github/gitignore/pull/2483#issue-259490424) +#*.snk + +# Since there are multiple workflows, uncomment next line to ignore bower_components +# (https://github.com/github/gitignore/pull/1529#issuecomment-104372622) +#bower_components/ + +# RIA/Silverlight projects +Generated_Code/ + +# Backup & report files from converting an old project file +# to a newer Visual Studio version. Backup files are not needed, +# because we have git ;-) +_UpgradeReport_Files/ +Backup*/ +UpgradeLog*.XML +UpgradeLog*.htm +ServiceFabricBackup/ +*.rptproj.bak + +# SQL Server files +*.mdf +*.ldf +*.ndf + +# Business Intelligence projects +*.rdl.data +*.bim.layout +*.bim_*.settings +*.rptproj.rsuser + +# Microsoft Fakes +FakesAssemblies/ + +# GhostDoc plugin setting file +*.GhostDoc.xml + +# Node.js Tools for Visual Studio +.ntvs_analysis.dat +node_modules/ + +# Visual Studio 6 build log +*.plg + +# Visual Studio 6 workspace options file +*.opt + +# Visual Studio 6 auto-generated workspace file (contains which files were open etc.) +*.vbw + +# Visual Studio LightSwitch build output +**/*.HTMLClient/GeneratedArtifacts +**/*.DesktopClient/GeneratedArtifacts +**/*.DesktopClient/ModelManifest.xml +**/*.Server/GeneratedArtifacts +**/*.Server/ModelManifest.xml +_Pvt_Extensions + +# Paket dependency manager +.paket/paket.exe +paket-files/ + +# FAKE - F# Make +.fake/ + +# JetBrains Rider +.idea/ +*.sln.iml + +# CodeRush +.cr/ + +# Python Tools for Visual Studio (PTVS) +__pycache__/ +*.pyc + +# Cake - Uncomment if you are using it +# tools/** +# !tools/packages.config + +# Tabs Studio +*.tss + +# Telerik's JustMock configuration file +*.jmconfig + +# BizTalk build output +*.btp.cs +*.btm.cs +*.odx.cs +*.xsd.cs + +# OpenCover UI analysis results +OpenCover/ + +# Azure Stream Analytics local run output +ASALocalRun/ + +# MSBuild Binary and Structured Log +*.binlog + +# NVidia Nsight GPU debugger configuration file +*.nvuser + +# MFractors (Xamarin productivity tool) working folder +.mfractor/ + +# Local History for Visual Studio +.localhistory/ + + +# End of https://www.gitignore.io/api/cake,windows,visualstudio,visualstudiocode + + +# Project specific folders +BuildArtifacts diff --git a/tests/Cake.Issues.PullRequests.GitHubActions/script-runner/build.cake b/tests/Cake.Issues.PullRequests.GitHubActions/script-runner/build.cake new file mode 100644 index 000000000..c02bfed35 --- /dev/null +++ b/tests/Cake.Issues.PullRequests.GitHubActions/script-runner/build.cake @@ -0,0 +1,88 @@ +#load "buildData.cake" + +#addin "Cake.Markdownlint" +#addin "Cake.Issues&prerelease" +#addin "Cake.Issues.MsBuild&prerelease" +#addin "Cake.Issues.PullRequests&prerelease" +#addin "Cake.Issues.PullRequests.GitHubActions&prerelease" + +////////////////////////////////////////////////// +// ARGUMENTS +////////////////////////////////////////////////// + +var target = Argument("target", "Default"); + +////////////////////////////////////////////////// +// SETUP / TEARDOWN +////////////////////////////////////////////////// + +Setup(setupContext => +{ + return new BuildData(); +}); + +var repoRootFolder = MakeAbsolute(Directory("./")); +var logPath = repoRootFolder.Combine("BuildArtifacts").Combine("logs"); + +////////////////////////////////////////////////// +// TARGETS +////////////////////////////////////////////////// + +Task("Build") + .Does((data) => +{ + var msBuildLogPath = logPath.CombineWithFilePath("msbuild.binlog"); + var solutionFile = + repoRootFolder + .Combine("src") + .CombineWithFilePath("ClassLibrary1.sln"); + + DotNetRestore(solutionFile.FullPath); + + var settings = + new DotNetMSBuildSettings() + .WithTarget("Rebuild") + .WithLogger( + "BinaryLogger," + Context.Tools.Resolve("Cake.Issues.MsBuild*/**/StructuredLogger.dll"), + "", + msBuildLogPath.FullPath + ); + + DotNetBuild( + solutionFile.FullPath, + new DotNetBuildSettings + { + MSBuildSettings = settings + }); + + data.AddIssues( + ReadIssues( + MsBuildIssuesFromFilePath( + msBuildLogPath, + MsBuildBinaryLogFileFormat), + repoRootFolder) + ); +}); + +Task("Report-IssuesToBuildServer") + .Does((data) => +{ + ReportIssuesToPullRequest( + data.Issues, + GitHubActionsBuilds(), + repoRootFolder); +}); + +Task("Lint") + .IsDependentOn("Build"); + +// Run issues task by default. +Task("Default") + .IsDependentOn("Lint") + .IsDependentOn("Report-IssuesToBuildServer"); + +////////////////////////////////////////////////// +// EXECUTION +////////////////////////////////////////////////// + +RunTarget(target); \ No newline at end of file diff --git a/tests/Cake.Issues.PullRequests.GitHubActions/script-runner/build.ps1 b/tests/Cake.Issues.PullRequests.GitHubActions/script-runner/build.ps1 new file mode 100644 index 000000000..fe6027689 --- /dev/null +++ b/tests/Cake.Issues.PullRequests.GitHubActions/script-runner/build.ps1 @@ -0,0 +1,15 @@ +$ErrorActionPreference = 'Stop' + +$SCRIPT_NAME = "build.cake" + +Write-Host "Restoring .NET Core tools" +dotnet tool restore +if ($LASTEXITCODE -ne 0) { exit $LASTEXITCODE } + +Write-Host "Bootstrapping Cake" +dotnet cake $SCRIPT_NAME --bootstrap +if ($LASTEXITCODE -ne 0) { exit $LASTEXITCODE } + +Write-Host "Running Build" +dotnet cake $SCRIPT_NAME @args +if ($LASTEXITCODE -ne 0) { exit $LASTEXITCODE } \ No newline at end of file diff --git a/tests/Cake.Issues.PullRequests.GitHubActions/script-runner/build.sh b/tests/Cake.Issues.PullRequests.GitHubActions/script-runner/build.sh new file mode 100755 index 000000000..921a3241b --- /dev/null +++ b/tests/Cake.Issues.PullRequests.GitHubActions/script-runner/build.sh @@ -0,0 +1,11 @@ +#!/bin/bash +SCRIPT_NAME="build.cake" + +echo "Restoring .NET Core tools" +dotnet tool restore + +echo "Bootstrapping Cake" +dotnet cake $SCRIPT_NAME --bootstrap + +echo "Running Build" +dotnet cake $SCRIPT_NAME "$@" \ No newline at end of file diff --git a/tests/Cake.Issues.PullRequests.GitHubActions/script-runner/buildData.cake b/tests/Cake.Issues.PullRequests.GitHubActions/script-runner/buildData.cake new file mode 100644 index 000000000..8a22d4145 --- /dev/null +++ b/tests/Cake.Issues.PullRequests.GitHubActions/script-runner/buildData.cake @@ -0,0 +1,29 @@ +public class BuildData +{ + private readonly List issues = new List(); + + /// + /// Gets issues determined during building. + /// + public IEnumerable Issues + { + get + { + return issues.AsReadOnly(); + } + } + + /// + /// Add issues to . + /// + /// List of issues which should be added. + public void AddIssues(IEnumerable issues) + { + if (issues == null) + { + throw new NullReferenceException(nameof(issues)); + } + + this.issues.AddRange(issues); + } +} \ No newline at end of file diff --git a/tests/Cake.Issues.PullRequests.GitHubActions/script-runner/nuget.config b/tests/Cake.Issues.PullRequests.GitHubActions/script-runner/nuget.config new file mode 100644 index 000000000..62768c3d3 --- /dev/null +++ b/tests/Cake.Issues.PullRequests.GitHubActions/script-runner/nuget.config @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/tests/Cake.Issues.PullRequests.GitHubActions/script-runner/src/ClassLibrary1.sln b/tests/Cake.Issues.PullRequests.GitHubActions/script-runner/src/ClassLibrary1.sln new file mode 100644 index 000000000..62df92e3d --- /dev/null +++ b/tests/Cake.Issues.PullRequests.GitHubActions/script-runner/src/ClassLibrary1.sln @@ -0,0 +1,22 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio 14 +VisualStudioVersion = 14.0.25420.1 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ClassLibrary1", "ClassLibrary1\ClassLibrary1.csproj", "{9B73BB5B-06A3-46F3-9068-E3607A8217B0}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {9B73BB5B-06A3-46F3-9068-E3607A8217B0}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {9B73BB5B-06A3-46F3-9068-E3607A8217B0}.Debug|Any CPU.Build.0 = Debug|Any CPU + {9B73BB5B-06A3-46F3-9068-E3607A8217B0}.Release|Any CPU.ActiveCfg = Release|Any CPU + {9B73BB5B-06A3-46F3-9068-E3607A8217B0}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection +EndGlobal diff --git a/tests/Cake.Issues.PullRequests.GitHubActions/script-runner/src/ClassLibrary1/Class1.cs b/tests/Cake.Issues.PullRequests.GitHubActions/script-runner/src/ClassLibrary1/Class1.cs new file mode 100644 index 000000000..4ea00049a --- /dev/null +++ b/tests/Cake.Issues.PullRequests.GitHubActions/script-runner/src/ClassLibrary1/Class1.cs @@ -0,0 +1,31 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ClassLibrary1 +{ + public class Class1 + { + public void Foo() + { + var foo = "foo"; + var bar = "bar"; + if (!string.IsNullOrEmpty(foo) && !string.IsNullOrEmpty(bar)) + { + var foobar = foo + bar; + } + } + + public void Bar() + { + var foo = "foo"; + var bar = "bar"; + if (!string.IsNullOrEmpty(foo) && !string.IsNullOrEmpty(bar)) + { + var foobar = foo + bar; + } + } + } +} diff --git a/tests/Cake.Issues.PullRequests.GitHubActions/script-runner/src/ClassLibrary1/ClassLibrary1.csproj b/tests/Cake.Issues.PullRequests.GitHubActions/script-runner/src/ClassLibrary1/ClassLibrary1.csproj new file mode 100644 index 000000000..9ec4dd90e --- /dev/null +++ b/tests/Cake.Issues.PullRequests.GitHubActions/script-runner/src/ClassLibrary1/ClassLibrary1.csproj @@ -0,0 +1,21 @@ + + + + netstandard2.0 + + + + + all + 3.0.0 + + + all + 1.1.118 + + + + + + + \ No newline at end of file