From 4e7128d951fa844649cef35b791620e91432cde7 Mon Sep 17 00:00:00 2001 From: smoogipoo Date: Tue, 15 Jun 2021 20:18:51 +0900 Subject: [PATCH 1/3] Add GitHub build server --- src/NVika/BuildServers/GitHub.cs | 58 ++++++++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) create mode 100644 src/NVika/BuildServers/GitHub.cs diff --git a/src/NVika/BuildServers/GitHub.cs b/src/NVika/BuildServers/GitHub.cs new file mode 100644 index 00000000..5902d2f2 --- /dev/null +++ b/src/NVika/BuildServers/GitHub.cs @@ -0,0 +1,58 @@ +// Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. +// See the LICENCE file in the repository root for full licence text. + +using System; +using System.ComponentModel.Composition; +using System.Text; +using NVika.Abstractions; +using NVika.Parsers; + +namespace NVika.BuildServers +{ + internal sealed class GitHub : BuildServerBase + { + private readonly IEnvironment _environment; + + [ImportingConstructor] + internal GitHub(IEnvironment environment) + { + _environment = environment; + } + + public override string Name => nameof(GitHub); + + public override bool CanApplyToCurrentContext() => !string.IsNullOrEmpty(_environment.GetEnvironmentVariable("GITHUB_ACTIONS")); + + public override void WriteMessage(Issue issue) + { + var outputString = new StringBuilder(); + + switch (issue.Severity) + { + case IssueSeverity.Error: + outputString.Append("::error "); + break; + + case IssueSeverity.Warning: + outputString.Append("::warning"); + break; + } + + if (issue.FilePath != null) + { + var file = issue.Project != null + ? issue.FilePath.Replace(issue.Project + @"\", string.Empty) + : issue.FilePath; + + outputString.Append($"file={file},"); + } + + if (issue.Offset != null) + outputString.Append($"col={issue.Offset.Start},"); + + outputString.Append($"line={issue.Line}::{issue.Message}"); + + Console.WriteLine(outputString.ToString()); + } + } +} From 3ee6cca15ced4ea357d2e709b2279a01e1536899 Mon Sep 17 00:00:00 2001 From: smoogipoo Date: Tue, 15 Jun 2021 21:31:20 +0900 Subject: [PATCH 2/3] Fix incorrect file path --- src/NVika/BuildServers/GitHub.cs | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/src/NVika/BuildServers/GitHub.cs b/src/NVika/BuildServers/GitHub.cs index 5902d2f2..b51b0556 100644 --- a/src/NVika/BuildServers/GitHub.cs +++ b/src/NVika/BuildServers/GitHub.cs @@ -40,10 +40,7 @@ public override void WriteMessage(Issue issue) if (issue.FilePath != null) { - var file = issue.Project != null - ? issue.FilePath.Replace(issue.Project + @"\", string.Empty) - : issue.FilePath; - + var file = issue.FilePath.Replace('\\', '/'); outputString.Append($"file={file},"); } From 493b726ddeab0c9fc079089a4d62bdc3b7bed26d Mon Sep 17 00:00:00 2001 From: smoogipoo Date: Tue, 15 Jun 2021 21:31:24 +0900 Subject: [PATCH 3/3] Remove licence header --- src/NVika/BuildServers/GitHub.cs | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/NVika/BuildServers/GitHub.cs b/src/NVika/BuildServers/GitHub.cs index b51b0556..65ca41f4 100644 --- a/src/NVika/BuildServers/GitHub.cs +++ b/src/NVika/BuildServers/GitHub.cs @@ -1,6 +1,3 @@ -// Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. -// See the LICENCE file in the repository root for full licence text. - using System; using System.ComponentModel.Composition; using System.Text;