From 9a1dd80bcbf3534b06929eebb3b7e592f82d6f36 Mon Sep 17 00:00:00 2001 From: Ethan Chiu Date: Wed, 8 Jul 2020 11:14:46 -0400 Subject: [PATCH] Sanity check for fileTable add + remove unn. code --- src/Runner.Worker/ActionManifestManager.cs | 27 +++++++++---------- .../PipelineTemplateEvaluator.cs | 10 +------ 2 files changed, 14 insertions(+), 23 deletions(-) diff --git a/src/Runner.Worker/ActionManifestManager.cs b/src/Runner.Worker/ActionManifestManager.cs index df8a8ac04..a0071c9bf 100644 --- a/src/Runner.Worker/ActionManifestManager.cs +++ b/src/Runner.Worker/ActionManifestManager.cs @@ -33,13 +33,10 @@ namespace GitHub.Runner.Worker public sealed class ActionManifestManager : RunnerService, IActionManifestManager { private TemplateSchema _actionManifestSchema; - private IHostContext _hostContext; public override void Initialize(IHostContext hostContext) { base.Initialize(hostContext); - _hostContext = hostContext; - var assembly = Assembly.GetExecutingAssembly(); var json = default(string); using (var stream = assembly.GetManifestResourceStream("GitHub.Runner.Worker.action_yaml.json")) @@ -62,11 +59,11 @@ namespace GitHub.Runner.Worker // 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); - string fileName = manifestFile; + string basePath = HostContext.GetDirectory(WellKnownDirectory.Actions); + string fileRelativePath = manifestFile; if (manifestFile.Length > basePath.Length + 1) { - fileName = manifestFile.Remove(0, basePath.Length + 1); + fileRelativePath = manifestFile.Remove(0, basePath.Length + 1); } try @@ -74,10 +71,13 @@ namespace GitHub.Runner.Worker var token = default(TemplateToken); // Get the file ID - var fileId = templateContext.GetFileId(fileName); + var fileId = templateContext.GetFileId(fileRelativePath); - // Add this file to the FileTable in executionContext - executionContext.FileTable.Add(fileName); + // Add this file to the FileTable in executionContext if it hasn't been added already + if (fileId > executionContext.FileTable.Count) + { + executionContext.FileTable.Add(fileRelativePath); + } // Read the file var fileContent = File.ReadAllText(manifestFile); @@ -107,7 +107,7 @@ namespace GitHub.Runner.Worker break; case "runs": - actionDefinition.Execution = ConvertRuns(executionContext, templateContext, actionPair.Value, fileId); + actionDefinition.Execution = ConvertRuns(executionContext, templateContext, actionPair.Value); break; default: Trace.Info($"Ignore action property {propertyName}."); @@ -129,7 +129,7 @@ namespace GitHub.Runner.Worker executionContext.Error(error.Message); } - throw new ArgumentException($"Fail to load {fileName}"); + throw new ArgumentException($"Fail to load {fileRelativePath}"); } if (actionDefinition.Execution == null) @@ -311,8 +311,7 @@ namespace GitHub.Runner.Worker private ActionExecutionData ConvertRuns( IExecutionContext executionContext, TemplateContext context, - TemplateToken inputsToken, - Int32 fileID) + TemplateToken inputsToken) { var runsMapping = inputsToken.AssertMapping("runs"); var usingToken = default(StringToken); @@ -379,7 +378,7 @@ namespace GitHub.Runner.Worker { var steps = run.Value.AssertSequence("steps"); var evaluator = executionContext.ToPipelineTemplateEvaluator(); - stepsLoaded = evaluator.LoadCompositeSteps(steps, context.GetFileTable()); + stepsLoaded = evaluator.LoadCompositeSteps(steps); break; } throw new Exception("You aren't supposed to be using Composite Actions yet!"); diff --git a/src/Sdk/DTPipelines/Pipelines/ObjectTemplating/PipelineTemplateEvaluator.cs b/src/Sdk/DTPipelines/Pipelines/ObjectTemplating/PipelineTemplateEvaluator.cs index a41c831c8..a523327f8 100644 --- a/src/Sdk/DTPipelines/Pipelines/ObjectTemplating/PipelineTemplateEvaluator.cs +++ b/src/Sdk/DTPipelines/Pipelines/ObjectTemplating/PipelineTemplateEvaluator.cs @@ -160,20 +160,12 @@ namespace GitHub.DistributedTask.Pipelines.ObjectTemplating } public List LoadCompositeSteps( - TemplateToken token, - IReadOnlyList fileTable) + TemplateToken token) { var result = default(List); if (token != null && token.Type != TokenType.Null) { - // Create New Context Object var context = CreateContext(null, null, setMissingContext: false); - - // Pass original filetable to the new context: - foreach (var f in fileTable) { - context.GetFileId(f); - } - try { token = TemplateEvaluator.Evaluate(context, PipelineTemplateConstants.StepsInTemplate, token, 0, null, omitHeader: true);