From e2bb8d9e2437684e793c8a7c3dfd77875ddd6fc7 Mon Sep 17 00:00:00 2001 From: Ethan Chiu Date: Wed, 10 Jun 2020 17:50:14 -0400 Subject: [PATCH] First attempt at creating baseline code for composite actions --- src/Runner.Listener/Runner.cs | 2 + src/Runner.Worker/ActionManager.cs | 37 +++++++++++++++++++ src/Runner.Worker/ActionManifestManager.cs | 25 +++++++++++++ .../Handlers/CompositeHandler.cs | 20 ++++++++++ src/Runner.Worker/Handlers/HandlerFactory.cs | 7 ++++ src/Runner.Worker/JobRunner.cs | 1 + src/Runner.Worker/action_yaml.json | 18 ++++++++- 7 files changed, 109 insertions(+), 1 deletion(-) create mode 100644 src/Runner.Worker/Handlers/CompositeHandler.cs diff --git a/src/Runner.Listener/Runner.cs b/src/Runner.Listener/Runner.cs index 2fd57d23c..0bfd4f75f 100644 --- a/src/Runner.Listener/Runner.cs +++ b/src/Runner.Listener/Runner.cs @@ -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; diff --git a/src/Runner.Worker/ActionManager.cs b/src/Runner.Worker/ActionManager.cs index 347eb3d0d..bfc8d4df8 100644 --- a/src/Runner.Worker/ActionManager.cs +++ b/src/Runner.Worker/ActionManager.cs @@ -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}()"; diff --git a/src/Runner.Worker/ActionManifestManager.cs b/src/Runner.Worker/ActionManifestManager.cs index 4e9149d26..a2cdad257 100644 --- a/src/Runner.Worker/ActionManifestManager.cs +++ b/src/Runner.Worker/ActionManifestManager.cs @@ -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."); diff --git a/src/Runner.Worker/Handlers/CompositeHandler.cs b/src/Runner.Worker/Handlers/CompositeHandler.cs new file mode 100644 index 000000000..9711500d9 --- /dev/null +++ b/src/Runner.Worker/Handlers/CompositeHandler.cs @@ -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 +} \ No newline at end of file diff --git a/src/Runner.Worker/Handlers/HandlerFactory.cs b/src/Runner.Worker/Handlers/HandlerFactory.cs index 0f2413ef5..0a63ce2ef 100644 --- a/src/Runner.Worker/Handlers/HandlerFactory.cs +++ b/src/Runner.Worker/Handlers/HandlerFactory.cs @@ -66,6 +66,13 @@ namespace GitHub.Runner.Worker.Handlers handler = HostContext.CreateService(); (handler as IRunnerPluginHandler).Data = data as PluginActionExecutionData; } + else if (data.ExecutionType == ActionExecutionType.Composite) + { + // Runner plugin + handler = HostContext.CreateService(); + // handler = CompositeHandler; + (handler as ICompositeHandler).Data = data as CompositeActionExecutionData; + } else { // This should never happen. diff --git a/src/Runner.Worker/JobRunner.cs b/src/Runner.Worker/JobRunner.cs index 31dfb1714..915a43fbf 100644 --- a/src/Runner.Worker/JobRunner.cs +++ b/src/Runner.Worker/JobRunner.cs @@ -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(() => diff --git a/src/Runner.Worker/action_yaml.json b/src/Runner.Worker/action_yaml.json index 7a8b847d3..b3099fbb9 100644 --- a/src/Runner.Worker/action_yaml.json +++ b/src/Runner.Worker/action_yaml.json @@ -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"