From d8a53aa04a0c3c9e5362d83eef6c3e00c596acb7 Mon Sep 17 00:00:00 2001 From: Brian Cristante <33549821+brcrista@users.noreply.github.com> Date: Thu, 14 Oct 2021 17:31:23 -0400 Subject: [PATCH] Remove dead code --- src/Runner.Worker/ActionManager.cs | 56 +--------------- src/Runner.Worker/Handlers/HandlerFactory.cs | 5 -- src/Runner.Worker/Handlers/MakefileHandler.cs | 67 ------------------- src/Runner.Worker/JobExtension.cs | 2 +- src/Runner.Worker/MakefileManager.cs | 45 ------------- src/Runner.Worker/MakefileReader.cs | 24 +++++++ 6 files changed, 28 insertions(+), 171 deletions(-) delete mode 100644 src/Runner.Worker/Handlers/MakefileHandler.cs delete mode 100644 src/Runner.Worker/MakefileManager.cs create mode 100644 src/Runner.Worker/MakefileReader.cs diff --git a/src/Runner.Worker/ActionManager.cs b/src/Runner.Worker/ActionManager.cs index 73422b557..34da0a65b 100644 --- a/src/Runner.Worker/ActionManager.cs +++ b/src/Runner.Worker/ActionManager.cs @@ -10,7 +10,6 @@ using System.Text; using System.Threading; using System.Threading.Tasks; using GitHub.DistributedTask.ObjectTemplating.Tokens; -using GitHub.DistributedTask.Pipelines.ContextData; using GitHub.Runner.Common; using GitHub.Runner.Sdk; using GitHub.Runner.Worker.Container; @@ -487,49 +486,9 @@ namespace GitHub.Runner.Worker } else if (action.Reference.Type == Pipelines.ActionSourceType.Script) { - // Load the inputs. - // executionContext.Debug("Loading inputs"); - // var templateEvaluator = executionContext.ToPipelineTemplateEvaluator(); - // var inputs = templateEvaluator.EvaluateStepInputs(action.Inputs, executionContext.ExpressionValues, executionContext.ExpressionFunctions); - - // Check if we are running a Makefile. - // Only works for the default target right now. - // if (inputs["script"] == "make") - // { - // // Get the path of the Makefile in the repository root. - // var githubContext = executionContext.ExpressionValues["github"] as GitHubContext; - // var workspaceDir = githubContext["workspace"] as StringContextData; - // var makefile = Path.Combine(workspaceDir, "Makefile"); - // if (!File.Exists(makefile)) - // { - // // Forget about trying to be smart. Just do the normal thing. - // definition.Data.Execution = new ScriptActionExecutionData(); - // definition.Data.Name = "Run"; - // definition.Data.Description = "Execute a script"; - // } - // else - // { - // // Assume the default target is named `all`. - // var definitionData = MakefileManager.Load(executionContext, makefile, target: "all"); - // if (definitionData is null) - // { - // // Forget about trying to be smart. Just do the normal thing. - // definition.Data.Execution = new ScriptActionExecutionData(); - // definition.Data.Name = "Run"; - // definition.Data.Description = "Execute a script"; - // } - // else - // { - // definition.Data = definitionData; - // } - // } - // } - // else - // { - definition.Data.Execution = new ScriptActionExecutionData(); - definition.Data.Name = "Run"; - definition.Data.Description = "Execute a script"; - // } + definition.Data.Execution = new ScriptActionExecutionData(); + definition.Data.Name = "Run"; + definition.Data.Description = "Execute a script"; } else { @@ -1184,7 +1143,6 @@ namespace GitHub.Runner.Worker Plugin, Script, Composite, - Makefile, } public sealed class ContainerActionExecutionData : ActionExecutionData @@ -1252,14 +1210,6 @@ namespace GitHub.Runner.Worker public MappingToken Outputs { get; set; } } - public sealed class MakefileExecutionData : ActionExecutionData - { - public override ActionExecutionType ExecutionType => ActionExecutionType.Makefile; - public override bool HasPre => false; - public override bool HasPost => false; - public List Targets { get; set; } - } - public abstract class ActionExecutionData { private string _initCondition = $"{Constants.Expressions.Always}()"; diff --git a/src/Runner.Worker/Handlers/HandlerFactory.cs b/src/Runner.Worker/Handlers/HandlerFactory.cs index a29d6bdd9..2b3b98142 100644 --- a/src/Runner.Worker/Handlers/HandlerFactory.cs +++ b/src/Runner.Worker/Handlers/HandlerFactory.cs @@ -73,11 +73,6 @@ namespace GitHub.Runner.Worker.Handlers handler = HostContext.CreateService(); (handler as ICompositeActionHandler).Data = data as CompositeActionExecutionData; } - else if (data.ExecutionType == ActionExecutionType.Makefile) - { - handler = HostContext.CreateService(); - (handler as IMakefileHandler).Data = data as MakefileExecutionData; - } else { // This should never happen. diff --git a/src/Runner.Worker/Handlers/MakefileHandler.cs b/src/Runner.Worker/Handlers/MakefileHandler.cs deleted file mode 100644 index 59608e2cf..000000000 --- a/src/Runner.Worker/Handlers/MakefileHandler.cs +++ /dev/null @@ -1,67 +0,0 @@ -using System; -using System.Collections.Generic; -using System.IO; -using System.Linq; -using System.Text; -using System.Threading; -using System.Threading.Tasks; -using GitHub.DistributedTask.Expressions2; -using GitHub.DistributedTask.ObjectTemplating.Tokens; -using GitHub.DistributedTask.Pipelines.ContextData; -using GitHub.DistributedTask.Pipelines.ObjectTemplating; -using GitHub.DistributedTask.WebApi; -using GitHub.Runner.Common; -using GitHub.Runner.Common.Util; -using GitHub.Runner.Sdk; -using GitHub.Runner.Worker; -using GitHub.Runner.Worker.Expressions; -using Pipelines = GitHub.DistributedTask.Pipelines; - - -namespace GitHub.Runner.Worker.Handlers -{ - [ServiceLocator(Default = typeof(MakefileHandler))] - public interface IMakefileHandler : IHandler - { - MakefileExecutionData Data { get; set; } - } - public sealed class MakefileHandler : Handler, IMakefileHandler - { - public MakefileExecutionData Data { get; set; } - - public async Task RunAsync(ActionRunStage stage) - { - // Validate args - Trace.Entering(); - ArgUtil.NotNull(ExecutionContext, nameof(ExecutionContext)); - ArgUtil.NotNull(Inputs, nameof(Inputs)); - - // Create a script handler for each target - var handlers = Data.Targets.Select(target => - { - var handler = HostContext.CreateService(); - - // IScriptHandler does not need .Action - // handler.Action = action; - handler.Data = new ScriptActionExecutionData(); - handler.Environment = Environment; - handler.RuntimeVariables = RuntimeVariables; - handler.ExecutionContext = ExecutionContext; - handler.StepHost = HostContext.CreateService();; - handler.Inputs = new Dictionary - { - ["script"] = $"make {target}" - }; - handler.ActionDirectory = ActionDirectory; - handler.LocalActionContainerSetupSteps = LocalActionContainerSetupSteps; - - return handler; - }); - - foreach (var handler in handlers) - { - await handler.RunAsync(stage); - } - } - } -} diff --git a/src/Runner.Worker/JobExtension.cs b/src/Runner.Worker/JobExtension.cs index 2c43d391f..3322d320e 100644 --- a/src/Runner.Worker/JobExtension.cs +++ b/src/Runner.Worker/JobExtension.cs @@ -329,7 +329,7 @@ namespace GitHub.Runner.Worker else { // Assume the default target is named `all`. - var targetDependencies = MakefileManager.ReadTargetDependencies(jobContext, makefile, target: "all"); + var targetDependencies = MakefileReader.ReadTargetDependencies(jobContext, makefile, target: "all"); if (targetDependencies.Count == 0) { // Forget about trying to be smart. Just do the normal thing. diff --git a/src/Runner.Worker/MakefileManager.cs b/src/Runner.Worker/MakefileManager.cs deleted file mode 100644 index abb14e68f..000000000 --- a/src/Runner.Worker/MakefileManager.cs +++ /dev/null @@ -1,45 +0,0 @@ -using System.Collections.Generic; -using System.IO; -using System.Linq; - -namespace GitHub.Runner.Worker -{ - public static class MakefileManager - { - // Convert the `all` target to a set of steps of its dependencies. - // Does not recurse into the dependencies of those steps. - public static ActionDefinitionData Load(IExecutionContext executionContext, string makefile, string target) - { - var dependencies = ReadTargetDependencies(executionContext, makefile, target); - if (dependencies.Count == 0) - { - return null; - } - - return new ActionDefinitionData - { - Name = $"make {target}", - Description = "Execute a Makefile target", - Execution = new MakefileExecutionData - { - Targets = dependencies, - InitCondition = "always()", - CleanupCondition = "always()", - } - }; - } - - public static List ReadTargetDependencies(IExecutionContext executionContext, string makefile, string target) - { - var targetToFind = target + ":"; - var lines = File.ReadLines(makefile); - string targetLine = lines.FirstOrDefault(line => line.TrimStart().StartsWith(targetToFind)); - if (targetLine is null) - { - return null; - } - - return targetLine.Split().Skip(1).ToList(); - } - } -} \ No newline at end of file diff --git a/src/Runner.Worker/MakefileReader.cs b/src/Runner.Worker/MakefileReader.cs new file mode 100644 index 000000000..67a3d3cba --- /dev/null +++ b/src/Runner.Worker/MakefileReader.cs @@ -0,0 +1,24 @@ +using System.Collections.Generic; +using System.IO; +using System.Linq; + +namespace GitHub.Runner.Worker +{ + public static class MakefileReader + { + // Get the dependencies for a target from a Makefile. + // Does not recurse into the dependencies of those dependencies. + public static List ReadTargetDependencies(IExecutionContext executionContext, string makefile, string target) + { + var targetToFind = target + ":"; + var lines = File.ReadLines(makefile); + string targetLine = lines.FirstOrDefault(line => line.TrimStart().StartsWith(targetToFind)); + if (targetLine is null) + { + return null; + } + + return targetLine.Split().Skip(1).ToList(); + } + } +} \ No newline at end of file