mirror of
https://github.com/actions/runner.git
synced 2025-12-23 09:57:23 +08:00
send annotations to run-service (#2574)
* send annotations to run-service * skip message deletion * actually don't skip deletion * enum as numbers * fix enum * linting * remove unncessary file * feedback
This commit is contained in:
committed by
GitHub
parent
8d74a9ead6
commit
896152d78e
35
src/Sdk/RSWebApi/Contracts/Annotation.cs
Normal file
35
src/Sdk/RSWebApi/Contracts/Annotation.cs
Normal file
@@ -0,0 +1,35 @@
|
||||
using System.Runtime.Serialization;
|
||||
|
||||
namespace Sdk.RSWebApi.Contracts
|
||||
{
|
||||
[DataContract]
|
||||
public struct Annotation
|
||||
{
|
||||
[DataMember(Name = "level", EmitDefaultValue = false)]
|
||||
public AnnotationLevel Level;
|
||||
|
||||
[DataMember(Name = "message", EmitDefaultValue = false)]
|
||||
public string Message;
|
||||
|
||||
[DataMember(Name = "rawDetails", EmitDefaultValue = false)]
|
||||
public string RawDetails;
|
||||
|
||||
[DataMember(Name = "path", EmitDefaultValue = false)]
|
||||
public string Path;
|
||||
|
||||
[DataMember(Name = "isInfrastructureIssue", EmitDefaultValue = false)]
|
||||
public bool IsInfrastructureIssue;
|
||||
|
||||
[DataMember(Name = "startLine", EmitDefaultValue = false)]
|
||||
public long StartLine;
|
||||
|
||||
[DataMember(Name = "endLine", EmitDefaultValue = false)]
|
||||
public long EndLine;
|
||||
|
||||
[DataMember(Name = "startColumn", EmitDefaultValue = false)]
|
||||
public long StartColumn;
|
||||
|
||||
[DataMember(Name = "endColumn", EmitDefaultValue = false)]
|
||||
public long EndColumn;
|
||||
}
|
||||
}
|
||||
20
src/Sdk/RSWebApi/Contracts/AnnotationLevel.cs
Normal file
20
src/Sdk/RSWebApi/Contracts/AnnotationLevel.cs
Normal file
@@ -0,0 +1,20 @@
|
||||
using System.Runtime.Serialization;
|
||||
|
||||
namespace Sdk.RSWebApi.Contracts
|
||||
{
|
||||
[DataContract]
|
||||
public enum AnnotationLevel
|
||||
{
|
||||
[EnumMember]
|
||||
UNKNOWN = 0,
|
||||
|
||||
[EnumMember]
|
||||
NOTICE = 1,
|
||||
|
||||
[EnumMember]
|
||||
WARNING = 2,
|
||||
|
||||
[EnumMember]
|
||||
FAILURE = 3
|
||||
}
|
||||
}
|
||||
@@ -2,6 +2,7 @@ using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Runtime.Serialization;
|
||||
using GitHub.DistributedTask.WebApi;
|
||||
using Sdk.RSWebApi.Contracts;
|
||||
|
||||
namespace GitHub.Actions.RunService.WebApi
|
||||
{
|
||||
@@ -10,17 +11,20 @@ namespace GitHub.Actions.RunService.WebApi
|
||||
{
|
||||
[DataMember(Name = "planId", EmitDefaultValue = false)]
|
||||
public Guid PlanID { get; set; }
|
||||
|
||||
|
||||
[DataMember(Name = "jobId", EmitDefaultValue = false)]
|
||||
public Guid JobID { get; set; }
|
||||
|
||||
|
||||
[DataMember(Name = "conclusion")]
|
||||
public TaskResult Conclusion { get; set; }
|
||||
|
||||
|
||||
[DataMember(Name = "outputs", EmitDefaultValue = false)]
|
||||
public Dictionary<string, VariableValue> Outputs { get; set; }
|
||||
|
||||
public Dictionary<string, VariableValue> Outputs { get; set; }
|
||||
|
||||
[DataMember(Name = "stepResults", EmitDefaultValue = false)]
|
||||
public IList<StepResult> StepResults { get; set; }
|
||||
|
||||
[DataMember(Name = "annotations", EmitDefaultValue = false)]
|
||||
public IList<Annotation> Annotations { get; set; }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
91
src/Sdk/RSWebApi/Contracts/IssueExtensions.cs
Normal file
91
src/Sdk/RSWebApi/Contracts/IssueExtensions.cs
Normal file
@@ -0,0 +1,91 @@
|
||||
using GitHub.DistributedTask.WebApi;
|
||||
|
||||
namespace Sdk.RSWebApi.Contracts
|
||||
{
|
||||
public static class IssueExtensions
|
||||
{
|
||||
public static Annotation? ToAnnotation(this Issue issue)
|
||||
{
|
||||
var issueMessage = issue.Message;
|
||||
if (string.IsNullOrWhiteSpace(issueMessage))
|
||||
{
|
||||
if (!issue.Data.TryGetValue(RunIssueKeys.Message, out issueMessage) || string.IsNullOrWhiteSpace(issueMessage))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
var annotationLevel = GetAnnotationLevel(issue.Type);
|
||||
var path = GetFilePath(issue);
|
||||
var lineNumber = GetAnnotationNumber(issue, RunIssueKeys.Line) ?? 0;
|
||||
var endLineNumber = GetAnnotationNumber(issue, RunIssueKeys.EndLine) ?? lineNumber;
|
||||
var columnNumber = GetAnnotationNumber(issue, RunIssueKeys.Col) ?? 0;
|
||||
var endColumnNumber = GetAnnotationNumber(issue, RunIssueKeys.EndColumn) ?? columnNumber;
|
||||
var logLineNumber = GetAnnotationNumber(issue, RunIssueKeys.LogLineNumber) ?? 0;
|
||||
|
||||
if (path == null && lineNumber == 0 && logLineNumber != 0)
|
||||
{
|
||||
lineNumber = logLineNumber;
|
||||
endLineNumber = logLineNumber;
|
||||
}
|
||||
|
||||
return new Annotation
|
||||
{
|
||||
Level = annotationLevel,
|
||||
Message = issueMessage,
|
||||
Path = path,
|
||||
StartLine = lineNumber,
|
||||
EndLine = endLineNumber,
|
||||
StartColumn = columnNumber,
|
||||
EndColumn = endColumnNumber,
|
||||
};
|
||||
}
|
||||
|
||||
private static AnnotationLevel GetAnnotationLevel(IssueType issueType)
|
||||
{
|
||||
switch (issueType)
|
||||
{
|
||||
case IssueType.Error:
|
||||
return AnnotationLevel.FAILURE;
|
||||
case IssueType.Warning:
|
||||
return AnnotationLevel.WARNING;
|
||||
case IssueType.Notice:
|
||||
return AnnotationLevel.NOTICE;
|
||||
default:
|
||||
return AnnotationLevel.UNKNOWN;
|
||||
}
|
||||
}
|
||||
|
||||
private static int? GetAnnotationNumber(Issue issue, string key)
|
||||
{
|
||||
if (issue.Data.TryGetValue(key, out var numberString) &&
|
||||
int.TryParse(numberString, out var number))
|
||||
{
|
||||
return number;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
private static string GetAnnotationField(Issue issue, string key)
|
||||
{
|
||||
if (issue.Data.TryGetValue(key, out var value))
|
||||
{
|
||||
return value;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
private static string GetFilePath(Issue issue)
|
||||
{
|
||||
if (issue.Data.TryGetValue(RunIssueKeys.File, out var path) &&
|
||||
!string.IsNullOrWhiteSpace(path))
|
||||
{
|
||||
return path;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
13
src/Sdk/RSWebApi/Contracts/IssueKeys.cs
Normal file
13
src/Sdk/RSWebApi/Contracts/IssueKeys.cs
Normal file
@@ -0,0 +1,13 @@
|
||||
namespace Sdk.RSWebApi.Contracts
|
||||
{
|
||||
public static class RunIssueKeys
|
||||
{
|
||||
public const string Message = "message";
|
||||
public const string File = "file";
|
||||
public const string Line = "line";
|
||||
public const string Col = "col";
|
||||
public const string EndLine = "endLine";
|
||||
public const string EndColumn = "endColumn";
|
||||
public const string LogLineNumber = "logFileLineNumber";
|
||||
}
|
||||
}
|
||||
@@ -1,7 +1,9 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Runtime.Serialization;
|
||||
using System.Threading.Tasks;
|
||||
using GitHub.DistributedTask.WebApi;
|
||||
using Sdk.RSWebApi.Contracts;
|
||||
|
||||
namespace GitHub.Actions.RunService.WebApi
|
||||
{
|
||||
@@ -34,5 +36,8 @@ namespace GitHub.Actions.RunService.WebApi
|
||||
|
||||
[DataMember(Name = "completed_log_lines", EmitDefaultValue = false)]
|
||||
public long? CompletedLogLines { get; set; }
|
||||
|
||||
[DataMember(Name = "annotations", EmitDefaultValue = false)]
|
||||
public List<Annotation> Annotations { get; set; }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -100,6 +100,7 @@ namespace GitHub.Actions.RunService.WebApi
|
||||
TaskResult result,
|
||||
Dictionary<String, VariableValue> outputs,
|
||||
IList<StepResult> stepResults,
|
||||
IList<Annotation> jobAnnotations,
|
||||
CancellationToken cancellationToken = default)
|
||||
{
|
||||
HttpMethod httpMethod = new HttpMethod("POST");
|
||||
@@ -109,7 +110,8 @@ namespace GitHub.Actions.RunService.WebApi
|
||||
JobID = jobId,
|
||||
Conclusion = result,
|
||||
Outputs = outputs,
|
||||
StepResults = stepResults
|
||||
StepResults = stepResults,
|
||||
Annotations = jobAnnotations
|
||||
};
|
||||
|
||||
requestUri = new Uri(requestUri, "completejob");
|
||||
|
||||
Reference in New Issue
Block a user