mirror of
https://github.com/actions/runner.git
synced 2025-12-11 12:57:05 +00:00
Let the IssueMetadata class be the mechanism for specifying log message overrides.
This commit is contained in:
@@ -648,7 +648,7 @@ namespace GitHub.Runner.Worker
|
|||||||
var filteredDictionaryEntries = command.Properties
|
var filteredDictionaryEntries = command.Properties
|
||||||
.Where(kvp => !string.Equals(kvp.Key, keyToExclude, StringComparison.OrdinalIgnoreCase));
|
.Where(kvp => !string.Equals(kvp.Key, keyToExclude, StringComparison.OrdinalIgnoreCase));
|
||||||
|
|
||||||
var metadata = new IssueMetadata(issueCategory, false, filteredDictionaryEntries);
|
var metadata = new IssueMetadata(issueCategory, false, null, filteredDictionaryEntries);
|
||||||
var issue = context.CreateIssue(this.Type, command.Data, metadata, true);
|
var issue = context.CreateIssue(this.Type, command.Data, metadata, true);
|
||||||
context.AddIssue(issue);
|
context.AddIssue(issue);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -620,10 +620,15 @@ namespace GitHub.Runner.Worker
|
|||||||
|
|
||||||
if (!string.IsNullOrEmpty(wellKnownTag))
|
if (!string.IsNullOrEmpty(wellKnownTag))
|
||||||
{
|
{
|
||||||
if (writeToLog && !string.IsNullOrEmpty(refinedMessage))
|
if (writeToLog)
|
||||||
{
|
{
|
||||||
long logLineNumber = Write(wellKnownTag, refinedMessage);
|
//Note that ::Write() has it's own secret masking logic
|
||||||
result.Data["logFileLineNumber"] = logLineNumber.ToString();
|
string logText = metadata?.LogMessageOverride ?? result.Message;
|
||||||
|
if (!string.IsNullOrEmpty(logText))
|
||||||
|
{
|
||||||
|
long logLineNumber = Write(wellKnownTag, logText);
|
||||||
|
result.Data["logFileLineNumber"] = logLineNumber.ToString();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (previousCountForIssueType.GetValueOrDefault(0) < _maxIssueCount)
|
if (previousCountForIssueType.GetValueOrDefault(0) < _maxIssueCount)
|
||||||
{
|
{
|
||||||
@@ -1192,7 +1197,7 @@ namespace GitHub.Runner.Worker
|
|||||||
// Do not add a format string overload. See comment on ExecutionContext.Write().
|
// Do not add a format string overload. See comment on ExecutionContext.Write().
|
||||||
public static void InfrastructureError(this IExecutionContext context, string message)
|
public static void InfrastructureError(this IExecutionContext context, string message)
|
||||||
{
|
{
|
||||||
var metadata = new IssueMetadata(null, true, Enumerable.Empty<KeyValuePair<string, string>>());
|
var metadata = new IssueMetadata(null, true, null, Enumerable.Empty<KeyValuePair<string, string>>());
|
||||||
var issue = context.CreateIssue(IssueType.Error, message, metadata, true);
|
var issue = context.CreateIssue(IssueType.Error, message, metadata, true);
|
||||||
context.AddIssue(issue);
|
context.AddIssue(issue);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -98,7 +98,7 @@ namespace GitHub.Runner.Worker.Handlers
|
|||||||
var matchers = _matchers;
|
var matchers = _matchers;
|
||||||
|
|
||||||
// Strip color codes
|
// Strip color codes
|
||||||
var stripped = line.Contains(_colorCodePrefix) ? _colorCodeRegex.Replace(line, string.Empty) : line;
|
var refinedLine = line.Contains(_colorCodePrefix) ? _colorCodeRegex.Replace(line, string.Empty) : line;
|
||||||
|
|
||||||
foreach (var matcher in matchers)
|
foreach (var matcher in matchers)
|
||||||
{
|
{
|
||||||
@@ -108,7 +108,7 @@ namespace GitHub.Runner.Worker.Handlers
|
|||||||
// Match
|
// Match
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
match = matcher.Match(stripped);
|
match = matcher.Match(refinedLine);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
catch (RegexMatchTimeoutException ex)
|
catch (RegexMatchTimeoutException ex)
|
||||||
@@ -116,7 +116,7 @@ namespace GitHub.Runner.Worker.Handlers
|
|||||||
if (attempt < _maxAttempts)
|
if (attempt < _maxAttempts)
|
||||||
{
|
{
|
||||||
// Debug
|
// Debug
|
||||||
_executionContext.Debug($"Timeout processing issue matcher '{matcher.Owner}' against line '{stripped}'. Exception: {ex}");
|
_executionContext.Debug($"Timeout processing issue matcher '{matcher.Owner}' against line '{refinedLine}'. Exception: {ex}");
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@@ -324,7 +324,7 @@ namespace GitHub.Runner.Worker.Handlers
|
|||||||
_executionContext.Debug($"Dropping file value '{match.File}' and fromPath value '{match.FromPath}'. Exception during validation: {ex}");
|
_executionContext.Debug($"Dropping file value '{match.File}' and fromPath value '{match.FromPath}'. Exception during validation: {ex}");
|
||||||
}
|
}
|
||||||
|
|
||||||
var metadata = new IssueMetadata(null, false, issueData);
|
var metadata = new IssueMetadata(null, false, match.SourceText, issueData);
|
||||||
var issue = _executionContext.CreateIssue(issueType, match.Message, metadata, true);
|
var issue = _executionContext.CreateIssue(issueType, match.Message, metadata, true);
|
||||||
return issue;
|
return issue;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,6 +8,28 @@ namespace GitHub.Runner.Worker
|
|||||||
{
|
{
|
||||||
public delegate void OnMatcherChanged(object sender, MatcherChangedEventArgs e);
|
public delegate void OnMatcherChanged(object sender, MatcherChangedEventArgs e);
|
||||||
|
|
||||||
|
|
||||||
|
public sealed class IssueMetadata
|
||||||
|
{
|
||||||
|
public IssueMetadata(string key, string value)
|
||||||
|
: this(null, false, null, new []{ KeyValuePair.Create(key, value) })
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
public IssueMetadata(string category, bool infrastructureIssue, string logMessageOverride, IEnumerable<KeyValuePair<string, string>> data)
|
||||||
|
{
|
||||||
|
this.Category = category;
|
||||||
|
this.IsInfrastructureIssue = infrastructureIssue;
|
||||||
|
this.LogMessageOverride = logMessageOverride;
|
||||||
|
this.Data = data;
|
||||||
|
}
|
||||||
|
|
||||||
|
public readonly string Category;
|
||||||
|
public readonly bool IsInfrastructureIssue;
|
||||||
|
public readonly string LogMessageOverride;
|
||||||
|
public readonly IEnumerable<KeyValuePair<string, string>> Data;
|
||||||
|
}
|
||||||
|
|
||||||
public sealed class MatcherChangedEventArgs : EventArgs
|
public sealed class MatcherChangedEventArgs : EventArgs
|
||||||
{
|
{
|
||||||
public MatcherChangedEventArgs(IssueMatcherConfig config)
|
public MatcherChangedEventArgs(IssueMatcherConfig config)
|
||||||
@@ -69,7 +91,7 @@ namespace GitHub.Runner.Worker
|
|||||||
|
|
||||||
if (regexMatch.Success)
|
if (regexMatch.Success)
|
||||||
{
|
{
|
||||||
return new IssueMatch(null, pattern, regexMatch.Groups, DefaultSeverity);
|
return new IssueMatch(line, null, pattern, regexMatch.Groups, DefaultSeverity);
|
||||||
}
|
}
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
@@ -110,13 +132,13 @@ namespace GitHub.Runner.Worker
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Return
|
// Return
|
||||||
return new IssueMatch(runningMatch, pattern, regexMatch.Groups, DefaultSeverity);
|
return new IssueMatch(line, runningMatch, pattern, regexMatch.Groups, DefaultSeverity);
|
||||||
}
|
}
|
||||||
// Not the last pattern
|
// Not the last pattern
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
// Store the match
|
// Store the match
|
||||||
_state[i] = new IssueMatch(runningMatch, pattern, regexMatch.Groups);
|
_state[i] = new IssueMatch(line, runningMatch, pattern, regexMatch.Groups);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Not matched
|
// Not matched
|
||||||
@@ -184,8 +206,9 @@ namespace GitHub.Runner.Worker
|
|||||||
|
|
||||||
public sealed class IssueMatch
|
public sealed class IssueMatch
|
||||||
{
|
{
|
||||||
public IssueMatch(IssueMatch runningMatch, IssuePattern pattern, GroupCollection groups, string defaultSeverity = null)
|
public IssueMatch(string sourceText, IssueMatch runningMatch, IssuePattern pattern, GroupCollection groups, string defaultSeverity = null)
|
||||||
{
|
{
|
||||||
|
SourceText = sourceText;
|
||||||
File = runningMatch?.File ?? GetValue(groups, pattern.File);
|
File = runningMatch?.File ?? GetValue(groups, pattern.File);
|
||||||
Line = runningMatch?.Line ?? GetValue(groups, pattern.Line);
|
Line = runningMatch?.Line ?? GetValue(groups, pattern.Line);
|
||||||
Column = runningMatch?.Column ?? GetValue(groups, pattern.Column);
|
Column = runningMatch?.Column ?? GetValue(groups, pattern.Column);
|
||||||
@@ -200,6 +223,8 @@ namespace GitHub.Runner.Worker
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public string SourceText { get; }
|
||||||
|
|
||||||
public string File { get; }
|
public string File { get; }
|
||||||
|
|
||||||
public string Line { get; }
|
public string Line { get; }
|
||||||
@@ -455,7 +480,7 @@ namespace GitHub.Runner.Worker
|
|||||||
if (Loop && Message == null)
|
if (Loop && Message == null)
|
||||||
{
|
{
|
||||||
throw new ArgumentException($"The {_loopPropertyName} pattern must set '{_messagePropertyName}'");
|
throw new ArgumentException($"The {_loopPropertyName} pattern must set '{_messagePropertyName}'");
|
||||||
}
|
}
|
||||||
|
|
||||||
var regex = new Regex(Pattern ?? string.Empty, RegexOptions);
|
var regex = new Regex(Pattern ?? string.Empty, RegexOptions);
|
||||||
var groupCount = regex.GetGroupNumbers().Length;
|
var groupCount = regex.GetGroupNumbers().Length;
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Runtime.Serialization;
|
using System.Runtime.Serialization;
|
||||||
|
using GitHub.Services.Common;
|
||||||
|
|
||||||
namespace GitHub.DistributedTask.WebApi
|
namespace GitHub.DistributedTask.WebApi
|
||||||
{
|
{
|
||||||
@@ -14,48 +15,25 @@ namespace GitHub.DistributedTask.WebApi
|
|||||||
string this[string key] { get; }
|
string this[string key] { get; }
|
||||||
}
|
}
|
||||||
|
|
||||||
public class IssueMetadata
|
|
||||||
{
|
|
||||||
|
|
||||||
public IssueMetadata(string key, string value)
|
|
||||||
: this(null, false, new []{ KeyValuePair.Create(key, value) })
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
public IssueMetadata(string category, bool infrastructureIssue, IEnumerable<KeyValuePair<string, string>> data)
|
|
||||||
{
|
|
||||||
this.Category = category;
|
|
||||||
this.IsInfrastructureIssue = infrastructureIssue;
|
|
||||||
this.Data = data;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public readonly string Category;
|
|
||||||
public readonly bool IsInfrastructureIssue;
|
|
||||||
public readonly IEnumerable<KeyValuePair<string, string>> Data;
|
|
||||||
}
|
|
||||||
|
|
||||||
[DataContract]
|
[DataContract]
|
||||||
public class Issue : IReadOnlyIssue
|
public class Issue : IReadOnlyIssue
|
||||||
{
|
{
|
||||||
|
|
||||||
public Issue()
|
public Issue()
|
||||||
|
: this(null)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
private Issue(Issue original)
|
private Issue(Issue original)
|
||||||
{
|
{
|
||||||
this.Type = original.Type;
|
m_data = new Dictionary<String, String>(StringComparer.OrdinalIgnoreCase);
|
||||||
this.Category = original.Category;
|
if (original != null)
|
||||||
this.Message = original.Message;
|
|
||||||
this.IsInfrastructureIssue = original.IsInfrastructureIssue;
|
|
||||||
|
|
||||||
if (original.m_data != null)
|
|
||||||
{
|
{
|
||||||
foreach (var item in original.m_data)
|
this.Type = original.Type;
|
||||||
{
|
this.Category = original.Category;
|
||||||
this.Data.Add(item);
|
this.Message = original.Message;
|
||||||
}
|
this.IsInfrastructureIssue = original.IsInfrastructureIssue;
|
||||||
|
this.Data.AddRange(original.Data);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -91,10 +69,6 @@ namespace GitHub.DistributedTask.WebApi
|
|||||||
{
|
{
|
||||||
get
|
get
|
||||||
{
|
{
|
||||||
if (m_data == null)
|
|
||||||
{
|
|
||||||
m_data = new Dictionary<String, String>(StringComparer.OrdinalIgnoreCase);
|
|
||||||
}
|
|
||||||
return m_data;
|
return m_data;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -983,8 +983,8 @@ namespace GitHub.Runner.Common.Tests.Worker
|
|||||||
{
|
{
|
||||||
_onMatcherChanged = handler;
|
_onMatcherChanged = handler;
|
||||||
});
|
});
|
||||||
_executionContext.Setup(x => x.CreateIssue(It.IsAny<DTWebApi.IssueType>(), It.IsAny<string>(), It.IsAny<DTWebApi.IssueMetadata>(), It.IsAny<bool>()))
|
_executionContext.Setup(x => x.CreateIssue(It.IsAny<DTWebApi.IssueType>(), It.IsAny<string>(), It.IsAny<IssueMetadata>(), It.IsAny<bool>()))
|
||||||
.Returns((DTWebApi.IssueType type, string message, DTWebApi.IssueMetadata metadata, bool writeToLog) =>
|
.Returns((DTWebApi.IssueType type, string message, IssueMetadata metadata, bool writeToLog) =>
|
||||||
{
|
{
|
||||||
var result = new DTWebApi.Issue()
|
var result = new DTWebApi.Issue()
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user