Compare commits

...

7 Commits

Author SHA1 Message Date
Brian Cristante
d8a53aa04a Remove dead code 2021-10-14 17:40:49 -04:00
Brian Cristante
9fe65b872a Fix detecting if the step is run: make 2021-10-14 17:16:50 -04:00
Brian Cristante
ec420bab24 Try adding steps in JobExtension 2021-10-14 16:26:00 -04:00
Brian Cristante
07cda747b2 Create a new step host for each sub-step 2021-10-14 13:59:34 -04:00
Brian Cristante
9ca132380c Detect Makefiles and parse out the targets 2021-10-14 11:56:26 -04:00
Brian Cristante
a5a0f8df47 Revert "Add GNUMakeManager"
This reverts commit ccf53338be.
2021-10-14 09:09:58 -04:00
Brian Cristante
ccf53338be Add GNUMakeManager 2021-10-12 14:11:14 -04:00
4 changed files with 120 additions and 24 deletions

View File

@@ -262,6 +262,16 @@ namespace GitHub.Runner.Worker
environment[$"STATE_{state.Key}"] = state.Value ?? string.Empty; environment[$"STATE_{state.Key}"] = state.Value ?? string.Empty;
} }
// HACK
if (Action.DisplayName != null && Action.DisplayName.StartsWith("make dependency"))
{
var target = Action.DisplayName.Split()[2];
inputs = new Dictionary<string, string>
{
["script"] = $"make {target}"
};
}
// Create the handler. // Create the handler.
IHandler handler = handlerFactory.Create( IHandler handler = handlerFactory.Create(
ExecutionContext, ExecutionContext,

View File

@@ -31,8 +31,8 @@ namespace GitHub.Runner.Worker.Handlers
Inputs.TryGetValue("script", out string contents); Inputs.TryGetValue("script", out string contents);
contents = contents ?? string.Empty; contents = contents ?? string.Empty;
if (Action.Type == Pipelines.ActionSourceType.Script) // if (Action.Type == Pipelines.ActionSourceType.Script)
{ // {
var firstLine = contents.TrimStart(' ', '\t', '\r', '\n'); var firstLine = contents.TrimStart(' ', '\t', '\r', '\n');
var firstNewLine = firstLine.IndexOfAny(new[] { '\r', '\n' }); var firstNewLine = firstLine.IndexOfAny(new[] { '\r', '\n' });
if (firstNewLine >= 0) if (firstNewLine >= 0)
@@ -41,11 +41,11 @@ namespace GitHub.Runner.Worker.Handlers
} }
ExecutionContext.Output($"##[group]Run {firstLine}"); ExecutionContext.Output($"##[group]Run {firstLine}");
} // }
else // else
{ // {
throw new InvalidOperationException($"Invalid action type {Action.Type} for {nameof(ScriptHandler)}"); // throw new InvalidOperationException($"Invalid action type {Action.Type} for {nameof(ScriptHandler)}");
} // }
var multiLines = contents.Replace("\r\n", "\n").TrimEnd('\n').Split('\n'); var multiLines = contents.Replace("\r\n", "\n").TrimEnd('\n').Split('\n');
foreach (var line in multiLines) foreach (var line in multiLines)

View File

@@ -265,29 +265,91 @@ namespace GitHub.Runner.Worker
if (step.Type == Pipelines.StepType.Action) if (step.Type == Pipelines.StepType.Action)
{ {
var action = step as Pipelines.ActionStep; var action = step as Pipelines.ActionStep;
Trace.Info($"Adding {action.DisplayName}.");
var actionRunner = HostContext.CreateService<IActionRunner>(); void EmitStep(Pipelines.ActionStep action)
actionRunner.Action = action;
actionRunner.Stage = ActionRunStage.Main;
actionRunner.Condition = step.Condition;
var contextData = new Pipelines.ContextData.DictionaryContextData();
if (message.ContextData?.Count > 0)
{ {
foreach (var pair in message.ContextData) Trace.Info($"Adding {action.DisplayName}.");
var actionRunner = HostContext.CreateService<IActionRunner>();
actionRunner.Action = action;
actionRunner.Stage = ActionRunStage.Main;
actionRunner.Condition = step.Condition;
var contextData = new Pipelines.ContextData.DictionaryContextData();
if (message.ContextData?.Count > 0)
{ {
contextData[pair.Key] = pair.Value; foreach (var pair in message.ContextData)
{
contextData[pair.Key] = pair.Value;
}
}
actionRunner.TryEvaluateDisplayName(contextData, context);
jobSteps.Add(actionRunner);
if (prepareResult.PreStepTracker.TryGetValue(step.Id, out var preStep))
{
Trace.Info($"Adding pre-{action.DisplayName}.");
preStep.TryEvaluateDisplayName(contextData, context);
preStep.DisplayName = $"Pre {preStep.DisplayName}";
preJobSteps.Add(preStep);
} }
} }
actionRunner.TryEvaluateDisplayName(contextData, context); // HACK: if the step is "run: make," parse the Makefile and emit $"make dependency {target}"
jobSteps.Add(actionRunner); // Only works for the default target right now.
bool isRunMake = false;
if (prepareResult.PreStepTracker.TryGetValue(step.Id, out var preStep)) if (action.Reference?.Type == Pipelines.ActionSourceType.Script)
{ {
Trace.Info($"Adding pre-{action.DisplayName}."); var inputs = action.Inputs.AssertMapping(null);
preStep.TryEvaluateDisplayName(contextData, context); foreach (var pair in inputs)
preStep.DisplayName = $"Pre {preStep.DisplayName}"; {
preJobSteps.Add(preStep); var propertyName = pair.Key.AssertString($"{PipelineTemplateConstants.Steps}");
if (string.Equals(propertyName.Value, "script", StringComparison.OrdinalIgnoreCase))
{
var tokenToParse = pair.Value.AssertScalar($"{PipelineTemplateConstants.Steps} item {PipelineTemplateConstants.Run}");
if (tokenToParse.ToString() == "make")
{
isRunMake = true;
}
break;
}
}
}
if (isRunMake)
{
// Get the path of the Makefile in the repository root.
var githubContext = jobContext.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.
EmitStep(action);
}
else
{
// Assume the default target is named `all`.
var targetDependencies = MakefileReader.ReadTargetDependencies(jobContext, makefile, target: "all");
if (targetDependencies.Count == 0)
{
// Forget about trying to be smart. Just do the normal thing.
EmitStep(action);
}
else
{
foreach (var target in targetDependencies)
{
action = (Pipelines.ActionStep)action.Clone();
action.Id = Guid.NewGuid();
action.DisplayName = $"make dependency {target}";
EmitStep(action);
}
}
}
}
else
{
EmitStep(action);
} }
} }
} }

View File

@@ -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<string> 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();
}
}
}