Fix detecting if the step is run: make

This commit is contained in:
Brian Cristante
2021-10-14 16:54:02 -04:00
parent ec420bab24
commit 9fe65b872a

View File

@@ -266,7 +266,7 @@ namespace GitHub.Runner.Worker
{
var action = step as Pipelines.ActionStep;
void EmitStep()
void EmitStep(Pipelines.ActionStep action)
{
Trace.Info($"Adding {action.DisplayName}.");
var actionRunner = HostContext.CreateService<IActionRunner>();
@@ -295,15 +295,27 @@ namespace GitHub.Runner.Worker
}
// HACK: if the step is "run: make," parse the Makefile and emit $"make dependency {target}"
if (action.DisplayName == "Run make")
{
// Load the inputs.
jobContext.Debug("Loading inputs");
var inputs = templateEvaluator.EvaluateStepInputs(action.Inputs, jobContext.ExpressionValues, jobContext.ExpressionFunctions);
// Check if we are running a Makefile.
// Only works for the default target right now.
if (inputs["script"] == "make")
bool isRunMake = false;
if (action.Reference?.Type == Pipelines.ActionSourceType.Script)
{
var inputs = action.Inputs.AssertMapping(null);
foreach (var pair in inputs)
{
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;
@@ -312,7 +324,7 @@ namespace GitHub.Runner.Worker
if (!File.Exists(makefile))
{
// Forget about trying to be smart. Just do the normal thing.
EmitStep();
EmitStep(action);
}
else
{
@@ -321,22 +333,23 @@ namespace GitHub.Runner.Worker
if (targetDependencies.Count == 0)
{
// Forget about trying to be smart. Just do the normal thing.
EmitStep();
EmitStep(action);
}
else
{
foreach (var target in targetDependencies)
{
action = (Pipelines.ActionStep)action.Clone();
action.Id = Guid.NewGuid();
action.DisplayName = $"make dependency {target}";
EmitStep();
}
EmitStep(action);
}
}
}
}
else
{
EmitStep();
EmitStep(action);
}
}
}