From a4cc13e36f83d63584b2ce82396bec57ef30dea9 Mon Sep 17 00:00:00 2001 From: Ethan Chiu Date: Fri, 10 Jul 2020 14:33:12 -0400 Subject: [PATCH] Starting framework --- src/Runner.Worker/ActionManifestManager.cs | 2 +- .../Handlers/CompositeActionHandler.cs | 98 +++++++++++-------- .../PipelineTemplateConverter.cs | 7 +- .../PipelineTemplateEvaluator.cs | 6 +- 4 files changed, 65 insertions(+), 48 deletions(-) diff --git a/src/Runner.Worker/ActionManifestManager.cs b/src/Runner.Worker/ActionManifestManager.cs index 91ad36b63..f5ac1ecbd 100644 --- a/src/Runner.Worker/ActionManifestManager.cs +++ b/src/Runner.Worker/ActionManifestManager.cs @@ -325,7 +325,7 @@ namespace GitHub.Runner.Worker var postToken = default(StringToken); var postEntrypointToken = default(StringToken); var postIfToken = default(StringToken); - var stepsLoaded = default(List); + var stepsLoaded = default(List); foreach (var run in runsMapping) { diff --git a/src/Runner.Worker/Handlers/CompositeActionHandler.cs b/src/Runner.Worker/Handlers/CompositeActionHandler.cs index 99c269c3f..dbe511b0c 100644 --- a/src/Runner.Worker/Handlers/CompositeActionHandler.cs +++ b/src/Runner.Worker/Handlers/CompositeActionHandler.cs @@ -48,50 +48,68 @@ namespace GitHub.Runner.Worker.Handlers // Add each composite action step to the front of the queue int location = 0; + + + // While loop till we have reached the last layer? + Stack stepsToAppend = new Stack(); // TODO: Assume that each step is not an actionStep // How do we handle all types of steps????? - - foreach (Pipelines.ActionStep aStep in actionSteps) + + // Append in reverse order since we are using a stack + for (int i = actionSteps.Count - 1; i --> 0; ) { - // Ex: - // runs: - // using: "composite" - // steps: - // - uses: example/test-composite@v2 (a) - // - run echo hello world (b) - // - run echo hello world 2 (c) - // - // ethanchewy/test-composite/action.yaml - // runs: - // using: "composite" - // steps: - // - run echo hello world 3 (d) - // - run echo hello world 4 (e) - // - // Steps processed as follow: - // | a | - // | a | => | d | - // (Run step d) - // | a | - // | a | => | e | - // (Run step e) - // | a | - // (Run step a) - // | b | - // (Run step b) - // | c | - // (Run step c) - // Done. - - var actionRunner = HostContext.CreateService(); - actionRunner.Action = aStep; - actionRunner.Stage = stage; - actionRunner.Condition = aStep.Condition; - actionRunner.DisplayName = aStep.DisplayName; - - ExecutionContext.RegisterNestedStep(actionRunner, inputsData, location, Environment); - location++; + stepsToAppend.Append(actionSteps[i]); } + while (stepsToAppend != null) + { + var currentStep = stepsToAppend.Pop(); + } + + // foreach (Pipelines.Step aStep in actionSteps) + // { + // // Ex: + // // runs: + // // using: "composite" + // // steps: + // // - uses: example/test-composite@v2 (a) + // // - run echo hello world (b) + // // - run echo hello world 2 (c) + // // + // // ethanchewy/test-composite/action.yaml + // // runs: + // // using: "composite" + // // steps: + // // - run echo hello world 3 (d) + // // - run echo hello world 4 (e) + // // + // // Steps processed as follow: + // // | a | + // // | a | => | d | + // // (Run step d) + // // | a | + // // | a | => | e | + // // (Run step e) + // // | a | + // // (Run step a) + // // | b | + // // (Run step b) + // // | c | + // // (Run step c) + // // Done. + + // // TODO: how are we going to order each step? + // // How is this going to look in the UI (will we have a bunch of nesting) + // // ^ We need to focus on how we are going to get the steps to run in the right order. + + // var actionRunner = HostContext.CreateService(); + // actionRunner.Action = aStep; + // actionRunner.Stage = stage; + // actionRunner.Condition = aStep.Condition; + // actionRunner.DisplayName = aStep.DisplayName; + + // ExecutionContext.RegisterNestedStep(actionRunner, inputsData, location, Environment); + // location++; + // } return Task.CompletedTask; } diff --git a/src/Sdk/DTPipelines/Pipelines/ObjectTemplating/PipelineTemplateConverter.cs b/src/Sdk/DTPipelines/Pipelines/ObjectTemplating/PipelineTemplateConverter.cs index a952f58fb..1fee7966f 100644 --- a/src/Sdk/DTPipelines/Pipelines/ObjectTemplating/PipelineTemplateConverter.cs +++ b/src/Sdk/DTPipelines/Pipelines/ObjectTemplating/PipelineTemplateConverter.cs @@ -264,14 +264,13 @@ namespace GitHub.DistributedTask.Pipelines.ObjectTemplating return result; } - //Note: originally was List but we need to change to List to use the "Inputs" attribute - internal static List ConvertToSteps( + internal static List ConvertToSteps( TemplateContext context, TemplateToken steps) { var stepsSequence = steps.AssertSequence($"job {PipelineTemplateConstants.Steps}"); - var result = new List(); + var result = new List(); foreach (var stepsItem in stepsSequence) { var step = ConvertToStep(context, stepsItem); @@ -287,7 +286,7 @@ namespace GitHub.DistributedTask.Pipelines.ObjectTemplating return result; } - private static ActionStep ConvertToStep( + private static Step ConvertToStep( TemplateContext context, TemplateToken stepsItem) { diff --git a/src/Sdk/DTPipelines/Pipelines/ObjectTemplating/PipelineTemplateEvaluator.cs b/src/Sdk/DTPipelines/Pipelines/ObjectTemplating/PipelineTemplateEvaluator.cs index f42f0c28c..7ea94595c 100644 --- a/src/Sdk/DTPipelines/Pipelines/ObjectTemplating/PipelineTemplateEvaluator.cs +++ b/src/Sdk/DTPipelines/Pipelines/ObjectTemplating/PipelineTemplateEvaluator.cs @@ -159,11 +159,11 @@ namespace GitHub.DistributedTask.Pipelines.ObjectTemplating return result; } - // Change to return a variety of steps. - public List LoadCompositeSteps( + // TODO: Change to return a variety of steps. + public List LoadCompositeSteps( TemplateToken token) { - var result = default(List); + var result = default(List); if (token != null && token.Type != TokenType.Null) { var context = CreateContext(null, null, setMissingContext: false);