mirror of
https://github.com/actions/runner.git
synced 2025-12-10 12:36:23 +00:00
Compare commits
7 Commits
v2.296.0
...
brcrista/m
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
d8a53aa04a | ||
|
|
9fe65b872a | ||
|
|
ec420bab24 | ||
|
|
07cda747b2 | ||
|
|
9ca132380c | ||
|
|
a5a0f8df47 | ||
|
|
ccf53338be |
@@ -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,
|
||||
|
||||
@@ -31,8 +31,8 @@ namespace GitHub.Runner.Worker.Handlers
|
||||
|
||||
Inputs.TryGetValue("script", out string contents);
|
||||
contents = contents ?? string.Empty;
|
||||
if (Action.Type == Pipelines.ActionSourceType.Script)
|
||||
{
|
||||
// if (Action.Type == Pipelines.ActionSourceType.Script)
|
||||
// {
|
||||
var firstLine = contents.TrimStart(' ', '\t', '\r', '\n');
|
||||
var firstNewLine = firstLine.IndexOfAny(new[] { '\r', '\n' });
|
||||
if (firstNewLine >= 0)
|
||||
@@ -41,11 +41,11 @@ namespace GitHub.Runner.Worker.Handlers
|
||||
}
|
||||
|
||||
ExecutionContext.Output($"##[group]Run {firstLine}");
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new InvalidOperationException($"Invalid action type {Action.Type} for {nameof(ScriptHandler)}");
|
||||
}
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// throw new InvalidOperationException($"Invalid action type {Action.Type} for {nameof(ScriptHandler)}");
|
||||
// }
|
||||
|
||||
var multiLines = contents.Replace("\r\n", "\n").TrimEnd('\n').Split('\n');
|
||||
foreach (var line in multiLines)
|
||||
|
||||
@@ -265,29 +265,91 @@ 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(Pipelines.ActionStep action)
|
||||
{
|
||||
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}"
|
||||
// Only works for the default target right now.
|
||||
bool isRunMake = false;
|
||||
if (action.Reference?.Type == Pipelines.ActionSourceType.Script)
|
||||
{
|
||||
Trace.Info($"Adding pre-{action.DisplayName}.");
|
||||
preStep.TryEvaluateDisplayName(contextData, context);
|
||||
preStep.DisplayName = $"Pre {preStep.DisplayName}";
|
||||
preJobSteps.Add(preStep);
|
||||
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;
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
24
src/Runner.Worker/MakefileReader.cs
Normal file
24
src/Runner.Worker/MakefileReader.cs
Normal 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();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user