mirror of
https://github.com/actions/runner.git
synced 2025-12-10 12:36:23 +00:00
Compare commits
7 Commits
v2.306.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;
|
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,
|
||||||
|
|||||||
@@ -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)
|
||||||
|
|||||||
@@ -265,6 +265,9 @@ 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;
|
||||||
|
|
||||||
|
void EmitStep(Pipelines.ActionStep action)
|
||||||
|
{
|
||||||
Trace.Info($"Adding {action.DisplayName}.");
|
Trace.Info($"Adding {action.DisplayName}.");
|
||||||
var actionRunner = HostContext.CreateService<IActionRunner>();
|
var actionRunner = HostContext.CreateService<IActionRunner>();
|
||||||
actionRunner.Action = action;
|
actionRunner.Action = action;
|
||||||
@@ -290,6 +293,65 @@ namespace GitHub.Runner.Worker
|
|||||||
preJobSteps.Add(preStep);
|
preJobSteps.Add(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)
|
||||||
|
{
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var intraActionStates = new Dictionary<Guid, Dictionary<string, string>>();
|
var intraActionStates = new Dictionary<Guid, Dictionary<string, string>>();
|
||||||
|
|||||||
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