First attempt at creating baseline code for composite actions

This commit is contained in:
Ethan Chiu
2020-06-10 17:50:14 -04:00
parent 5815819f24
commit e2bb8d9e24
7 changed files with 109 additions and 1 deletions

View File

@@ -37,6 +37,8 @@ namespace GitHub.Runner.Listener
{
try
{
_term.WriteLine("Runner Repo TESTING VERSION OF RUNNER...");
Trace.Info("Hey I'm in the log file yay!");
VssUtil.InitializeVssClientSettings(HostContext.UserAgents, HostContext.WebProxy);
_inConfigStage = true;

View File

@@ -395,6 +395,9 @@ namespace GitHub.Runner.Worker
Trace.Info($"Action cleanup plugin: {plugin.PluginTypeName}.");
}
}
else if (definition.Data.Execution.ExecutionType == ActionExecutionType.Composite) {
// Don't do anything for now
}
else
{
throw new NotSupportedException(definition.Data.Execution.ExecutionType.ToString());
@@ -446,6 +449,15 @@ namespace GitHub.Runner.Worker
definition.Data.Name = "Run";
definition.Data.Description = "Execute a script";
}
// else if (definition.Data.Execution.ExecutionType == ActionExecutionType.Composite) {
// // var compositeAction = definition.Data.Execution as CompositeActionExecutionData;
// // // add Trace Info here later => maybe we don't need this?
// // Trace.Info($"Action pre composite file: {compositeAction.Pre ?? "N/A"}.");
// // // Trace.Info($"Action composite file: {compositeAction.Script}.");
// // Trace.Info($"Action post composite file: {compositeAction.Post ?? "N/A"}.");
// // We don't have to do anything since definition.Data contains everything we need.
// }
else
{
throw new NotSupportedException(action.Reference.Type.ToString());
@@ -1101,6 +1113,11 @@ namespace GitHub.Runner.Worker
Trace.Info($"Action plugin: {(actionDefinitionData.Execution as PluginActionExecutionData).Plugin}, no more preparation.");
return null;
}
else if (actionDefinitionData.Execution.ExecutionType == ActionExecutionType.Composite)
{
// Trace.Info($"Action composite: {(actionDefinitionData.Execution as CompositeActionExecutionData).Unknown}, no more preparation.");
return null;
}
else
{
throw new NotSupportedException(actionDefinitionData.Execution.ExecutionType.ToString());
@@ -1211,6 +1228,7 @@ namespace GitHub.Runner.Worker
NodeJS,
Plugin,
Script,
Composite
}
public sealed class ContainerActionExecutionData : ActionExecutionData
@@ -1267,6 +1285,25 @@ namespace GitHub.Runner.Worker
public override bool HasPost => false;
}
public sealed class CompositeActionExecutionData : ActionExecutionData
{
// Do I actually need this??
// Pre => pre execution for checking steps before, ibid for post
// Look at Script for dummy example
public override ActionExecutionType ExecutionType => ActionExecutionType.Composite;
public override bool HasPre => false;
public override bool HasPost => false;
public MappingToken Steps {get; set;}
// public string Script { get; set; }
// public string Pre { get; set; }
// public string Post { get; set; }
}
public abstract class ActionExecutionData
{
private string _initCondition = $"{Constants.Expressions.Always}()";

View File

@@ -311,6 +311,13 @@ namespace GitHub.Runner.Worker
var postToken = default(StringToken);
var postEntrypointToken = default(StringToken);
var postIfToken = default(StringToken);
// TODO: How do I represent stepsToken as a list of steps?
// Well for default value, we can set it to this?
// var stepsToken = runsMapping.AssertMapping("steps");
// Actually, not sure, let's just set it to MappingToken since AssertMapping("steps")
// returns a MappingToken
var stepsToken = default(MappingToken);
foreach (var run in runsMapping)
{
var runsKey = run.Key.AssertString("runs key").Value;
@@ -355,6 +362,9 @@ namespace GitHub.Runner.Worker
case "pre-if":
preIfToken = run.Value.AssertString("pre-if");
break;
case "steps":
stepsToken = run.Value.AssertMapping("steps");
break;
default:
Trace.Info($"Ignore run property {runsKey}.");
break;
@@ -402,6 +412,21 @@ namespace GitHub.Runner.Worker
};
}
}
// TODO: add composite stuff here
else if (string.Equals(usingToken.Value, "composite", StringComparison.OrdinalIgnoreCase))
{
if (stepsToken.Count <= 0)
{
throw new ArgumentNullException($"No steps provided.");
}
else
{
return new CompositeActionExecutionData()
{
Steps = stepsToken
};
}
}
else
{
throw new ArgumentOutOfRangeException($"'using: {usingToken.Value}' is not supported, use 'docker' or 'node12' instead.");

View File

@@ -0,0 +1,20 @@
using System.IO;
using System.Text;
using System.Threading.Tasks;
using GitHub.Runner.Common;
using GitHub.Runner.Sdk;
using GitHub.DistributedTask.WebApi;
using Pipelines = GitHub.DistributedTask.Pipelines;
using System;
using System.Linq;
namespace GitHub.Runner.Worker.Handlers
{
[ServiceLocator(Default = typeof(CompositeActionHandler))]
public interface ICompositeActionHandler : IHandler
{
CompositeActionExecutionData Data { get; set; }
}
// TODO: IMPLEMENT LOGIC FOR HANDLER CODE
}

View File

@@ -66,6 +66,13 @@ namespace GitHub.Runner.Worker.Handlers
handler = HostContext.CreateService<IRunnerPluginHandler>();
(handler as IRunnerPluginHandler).Data = data as PluginActionExecutionData;
}
else if (data.ExecutionType == ActionExecutionType.Composite)
{
// Runner plugin
handler = HostContext.CreateService<ICompositeHandler>();
// handler = CompositeHandler;
(handler as ICompositeHandler).Data = data as CompositeActionExecutionData;
}
else
{
// This should never happen.

View File

@@ -63,6 +63,7 @@ namespace GitHub.Runner.Worker
jobContext.InitializeJob(message, jobRequestCancellationToken);
Trace.Info("Starting the job execution context.");
jobContext.Start();
// User will see this message too
jobContext.Debug($"Starting: {message.JobDisplayName}");
runnerShutdownRegistration = HostContext.RunnerShutdownToken.Register(() =>

View File

@@ -32,7 +32,8 @@
"one-of": [
"container-runs",
"node12-runs",
"plugin-runs"
"plugin-runs",
"composite-runs"
]
},
"container-runs": {
@@ -83,6 +84,21 @@
}
}
},
"composite-runs": {
"mapping" : {
"properties": {
"using": "non-empty-string",
"steps": "steps"
}
}
},
"steps" : {
"mapping": {
"properties": {
"run": "non-empty-string"
}
}
},
"container-runs-context": {
"context": [
"inputs"