From 65287fb0f07337b586ba7cdf0fc3346eda133c3f Mon Sep 17 00:00:00 2001 From: Ethan Chiu Date: Thu, 11 Jun 2020 10:37:29 -0400 Subject: [PATCH] Add comments + fix action_yaml schema --- src/Runner.Worker/ActionManager.cs | 9 - src/Runner.Worker/ActionManifestManager.cs | 1 + .../Handlers/CompositeActionHandler.cs | 55 +++++- src/Runner.Worker/action_yaml.json | 173 +++++++++++++++++- 4 files changed, 224 insertions(+), 14 deletions(-) diff --git a/src/Runner.Worker/ActionManager.cs b/src/Runner.Worker/ActionManager.cs index bfc8d4df8..ab4effb1b 100644 --- a/src/Runner.Worker/ActionManager.cs +++ b/src/Runner.Worker/ActionManager.cs @@ -449,15 +449,6 @@ 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()); diff --git a/src/Runner.Worker/ActionManifestManager.cs b/src/Runner.Worker/ActionManifestManager.cs index a2cdad257..6c2ee77af 100644 --- a/src/Runner.Worker/ActionManifestManager.cs +++ b/src/Runner.Worker/ActionManifestManager.cs @@ -364,6 +364,7 @@ namespace GitHub.Runner.Worker break; case "steps": stepsToken = run.Value.AssertMapping("steps"); + // Maybe insert a for loop here instead since MappingToken is not supposed to be used in HandlerFactory.cs break; default: Trace.Info($"Ignore run property {runsKey}."); diff --git a/src/Runner.Worker/Handlers/CompositeActionHandler.cs b/src/Runner.Worker/Handlers/CompositeActionHandler.cs index b380649f2..c34331dc8 100644 --- a/src/Runner.Worker/Handlers/CompositeActionHandler.cs +++ b/src/Runner.Worker/Handlers/CompositeActionHandler.cs @@ -17,5 +17,58 @@ namespace GitHub.Runner.Worker.Handlers } // TODO: IMPLEMENT LOGIC FOR HANDLER CODE - + public sealed class CompositeActionHandler : Handler, ICompositeActionHandler + { + public CompositeActionExecutionData Data { get; set; } + + public async Task RunAsync(ActionRunStage stage) + { + // Copied from NodEscriptActionHandler.cs + // Validate args. + Trace.Entering(); + ArgUtil.NotNull(Data, nameof(Data)); + ArgUtil.NotNull(ExecutionContext, nameof(ExecutionContext)); + ArgUtil.NotNull(Inputs, nameof(Inputs)); + ArgUtil.Directory(ActionDirectory, nameof(ActionDirectory)); + + // Update the env dictionary. + AddInputsToEnvironment(); + AddPrependPathToEnvironment(); + + // expose context to environment + // for example, this is how we know what OS the runner is running on + foreach (var context in ExecutionContext.ExpressionValues) + { + if (context.Value is IEnvironmentContextData runtimeContext && runtimeContext != null) + { + foreach (var env in runtimeContext.GetRuntimeEnvironmentVariables()) + { + Environment[env.Key] = env.Value; + } + } + } + + // Add Actions Runtime server info + var systemConnection = ExecutionContext.Endpoints.Single(x => string.Equals(x.Name, WellKnownServiceEndpointNames.SystemVssConnection, StringComparison.OrdinalIgnoreCase)); + Environment["ACTIONS_RUNTIME_URL"] = systemConnection.Url.AbsoluteUri; + Environment["ACTIONS_RUNTIME_TOKEN"] = systemConnection.Authorization.Parameters[EndpointAuthorizationParameters.AccessToken]; + if (systemConnection.Data.TryGetValue("CacheServerUrl", out var cacheUrl) && !string.IsNullOrEmpty(cacheUrl)) + { + Environment["ACTIONS_CACHE_URL"] = cacheUrl; + } + + // Resolve steps + // How do I handle the MappingToken? + MappingToken target = null; + if (stage == ActionRunStage.Main) + { + target = Data.Steps; + } + + + + + + } + } } \ No newline at end of file diff --git a/src/Runner.Worker/action_yaml.json b/src/Runner.Worker/action_yaml.json index b3099fbb9..bc36aea58 100644 --- a/src/Runner.Worker/action_yaml.json +++ b/src/Runner.Worker/action_yaml.json @@ -92,11 +92,176 @@ } } }, - "steps" : { + "steps": { + "sequence": { + "item-type": "steps-item" + } + }, + "steps-item": { + "one-of": [ + "run-step", + "regular-step", + "steps-template-reference" + ] + }, + "run-step": { "mapping": { - "properties": { - "run": "non-empty-string" - } + "properties": { + "name": "string-steps-context", + "id": "non-empty-string", + "if": "step-if", + "timeout-minutes": "number-steps-context", + "run": { + "type": "string-steps-context", + "required": true + }, + "continue-on-error": "boolean-steps-context", + "env": "step-env", + "working-directory": "string-steps-context", + "shell": "non-empty-string" + } + } + }, + "regular-step": { + "mapping": { + "properties": { + "name": "string-steps-context", + "id": "non-empty-string", + "if": "step-if", + "continue-on-error": "boolean-steps-context", + "timeout-minutes": "number-steps-context", + "uses": { + "type": "non-empty-string", + "required": true + }, + "with": "step-with", + "env": "step-env" + } + } + }, + "steps-template-reference": { + "mapping": { + "properties": { + "template": "non-empty-string", + "id": "non-empty-string", + "inputs": "steps-template-reference-inputs" + } + } + }, + "string-steps-context": { + "context": [ + "github", + "needs", + "strategy", + "matrix", + "secrets", + "steps", + "job", + "runner", + "env", + "hashFiles(1,255)" + ], + "string": {} + }, + "step-if": { + "context": [ + "github", + "needs", + "strategy", + "matrix", + "steps", + "job", + "runner", + "env", + "always(0,0)", + "failure(0,0)", + "cancelled(0,0)", + "success(0,0)", + "hashFiles(1,255)" + ], + "string": {} + }, + "number-steps-context": { + "context": [ + "github", + "needs", + "strategy", + "matrix", + "secrets", + "steps", + "job", + "runner", + "env", + "hashFiles(1,255)" + ], + "number": {} + }, + "boolean-steps-context": { + "context": [ + "github", + "needs", + "strategy", + "matrix", + "secrets", + "steps", + "job", + "runner", + "env", + "hashFiles(1,255)" + ], + "boolean": {} + }, + "step-env": { + "context": [ + "github", + "needs", + "strategy", + "matrix", + "secrets", + "steps", + "job", + "runner", + "env", + "hashFiles(1,255)" + ], + "mapping": { + "loose-key-type": "non-empty-string", + "loose-value-type": "string" + } + }, + "step-with": { + "context": [ + "github", + "needs", + "strategy", + "matrix", + "secrets", + "steps", + "job", + "runner", + "env", + "hashFiles(1,255)" + ], + "mapping": { + "loose-key-type": "non-empty-string", + "loose-value-type": "string" + } + }, + "steps-template-reference-inputs": { + "context": [ + "github", + "needs", + "strategy", + "matrix", + "secrets", + "steps", + "job", + "runner", + "env" + ], + "mapping": { + "loose-key-type": "non-empty-string", + "loose-value-type": "string" } }, "container-runs-context": {