Clean up file path for error message

This commit is contained in:
Ethan Chiu
2020-06-23 14:19:51 -04:00
parent 368b6254ed
commit 0a6453e241

View File

@@ -34,10 +34,13 @@ namespace GitHub.Runner.Worker
public sealed class ActionManifestManager : RunnerService, IActionManifestManager public sealed class ActionManifestManager : RunnerService, IActionManifestManager
{ {
private TemplateSchema _actionManifestSchema; private TemplateSchema _actionManifestSchema;
private IHostContext _hostContext;
public override void Initialize(IHostContext hostContext) public override void Initialize(IHostContext hostContext)
{ {
base.Initialize(hostContext); base.Initialize(hostContext);
_hostContext = hostContext;
var assembly = Assembly.GetExecutingAssembly(); var assembly = Assembly.GetExecutingAssembly();
var json = default(string); var json = default(string);
using (var stream = assembly.GetManifestResourceStream("GitHub.Runner.Worker.action_yaml.json")) using (var stream = assembly.GetManifestResourceStream("GitHub.Runner.Worker.action_yaml.json"))
@@ -56,13 +59,19 @@ namespace GitHub.Runner.Worker
{ {
var templateContext = CreateContext(executionContext); var templateContext = CreateContext(executionContext);
ActionDefinitionData actionDefinition = new ActionDefinitionData(); ActionDefinitionData actionDefinition = new ActionDefinitionData();
// Clean up file name real quick
// Instead of using Regex which can be computationally expensive,
// we can just remove the # of characters from the fileName according to the length of the basePath
string basePath = _hostContext.GetDirectory(WellKnownDirectory.Actions);
var fileName = manifestFile.Remove(0, basePath.Length + 1);
try try
{ {
var token = default(TemplateToken); var token = default(TemplateToken);
// Get the file ID // Get the file ID
var fileId = templateContext.GetFileId(manifestFile); var fileId = templateContext.GetFileId(fileName);
var fileName = templateContext.GetFileName(fileId);
// Add this file to the FileTable in executionContext // Add this file to the FileTable in executionContext
executionContext.FileTable.Add(fileName); executionContext.FileTable.Add(fileName);
@@ -124,7 +133,7 @@ namespace GitHub.Runner.Worker
executionContext.Error(error.Message); executionContext.Error(error.Message);
} }
throw new ArgumentException($"Fail to load {manifestFile}"); throw new ArgumentException($"Fail to load {fileName}");
} }
if (actionDefinition.Execution == null) if (actionDefinition.Execution == null)