mirror of
https://github.com/actions/runner.git
synced 2025-12-15 14:36:59 +00:00
Try adding steps in JobExtension
This commit is contained in:
@@ -488,44 +488,48 @@ 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);
|
||||
// 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";
|
||||
}
|
||||
|
||||
// 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";
|
||||
}
|
||||
|
||||
definition.Data = definitionData;
|
||||
}
|
||||
else
|
||||
{
|
||||
// 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";
|
||||
}
|
||||
// }
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
@@ -262,6 +262,16 @@ namespace GitHub.Runner.Worker
|
||||
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.
|
||||
IHandler handler = handlerFactory.Create(
|
||||
ExecutionContext,
|
||||
|
||||
@@ -265,29 +265,78 @@ namespace GitHub.Runner.Worker
|
||||
if (step.Type == Pipelines.StepType.Action)
|
||||
{
|
||||
var action = step as Pipelines.ActionStep;
|
||||
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)
|
||||
|
||||
void EmitStep()
|
||||
{
|
||||
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);
|
||||
jobSteps.Add(actionRunner);
|
||||
|
||||
if (prepareResult.PreStepTracker.TryGetValue(step.Id, out var preStep))
|
||||
// HACK: if the step is "run: make," parse the Makefile and emit $"make dependency {target}"
|
||||
if (action.DisplayName == "Run make")
|
||||
{
|
||||
Trace.Info($"Adding pre-{action.DisplayName}.");
|
||||
preStep.TryEvaluateDisplayName(contextData, context);
|
||||
preStep.DisplayName = $"Pre {preStep.DisplayName}";
|
||||
preJobSteps.Add(preStep);
|
||||
// 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")
|
||||
{
|
||||
// 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();
|
||||
}
|
||||
else
|
||||
{
|
||||
// Assume the default target is named `all`.
|
||||
var targetDependencies = MakefileManager.ReadTargetDependencies(jobContext, makefile, target: "all");
|
||||
if (targetDependencies.Count == 0)
|
||||
{
|
||||
// Forget about trying to be smart. Just do the normal thing.
|
||||
EmitStep();
|
||||
}
|
||||
else
|
||||
{
|
||||
foreach (var target in targetDependencies)
|
||||
{
|
||||
action.DisplayName = $"make dependency {target}";
|
||||
EmitStep();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
EmitStep();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
|
||||
@@ -9,15 +10,7 @@ namespace GitHub.Runner.Worker
|
||||
// Does not recurse into the dependencies of those steps.
|
||||
public static ActionDefinitionData Load(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;
|
||||
}
|
||||
|
||||
var dependencies = targetLine.Split().Skip(1).ToList();
|
||||
var dependencies = ReadTargetDependencies(executionContext, makefile, target);
|
||||
if (dependencies.Count == 0)
|
||||
{
|
||||
return null;
|
||||
@@ -35,5 +28,18 @@ namespace GitHub.Runner.Worker
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
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();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user