mirror of
https://github.com/actions/runner.git
synced 2025-12-15 14:36:59 +00:00
Detect Makefiles and parse out the targets
This commit is contained in:
39
src/Runner.Worker/MakefileManager.cs
Normal file
39
src/Runner.Worker/MakefileManager.cs
Normal file
@@ -0,0 +1,39 @@
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
|
||||
namespace GitHub.Runner.Worker
|
||||
{
|
||||
public static class MakefileManager
|
||||
{
|
||||
// Convert the `all` target to a set of steps of its dependencies.
|
||||
// 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();
|
||||
if (dependencies.Count == 0)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
return new ActionDefinitionData
|
||||
{
|
||||
Name = $"make {target}",
|
||||
Description = "Execute a Makefile target",
|
||||
Execution = new MakefileExecutionData
|
||||
{
|
||||
Targets = dependencies,
|
||||
InitCondition = "always()",
|
||||
CleanupCondition = "always()",
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user