mirror of
https://github.com/actions/runner.git
synced 2025-12-11 04:46:58 +00:00
Add/Merge changes from Multiple Steps PR
This commit is contained in:
@@ -63,7 +63,7 @@ namespace GitHub.Runner.Worker
|
|||||||
JobContext JobContext { get; }
|
JobContext JobContext { get; }
|
||||||
|
|
||||||
// Only job level ExecutionContext has JobSteps
|
// Only job level ExecutionContext has JobSteps
|
||||||
Queue<IStep> JobSteps { get; }
|
List<IStep> JobSteps { get; }
|
||||||
|
|
||||||
// Only job level ExecutionContext has PostJobSteps
|
// Only job level ExecutionContext has PostJobSteps
|
||||||
Stack<IStep> PostJobSteps { get; }
|
Stack<IStep> PostJobSteps { get; }
|
||||||
@@ -105,9 +105,8 @@ namespace GitHub.Runner.Worker
|
|||||||
// others
|
// others
|
||||||
void ForceTaskComplete();
|
void ForceTaskComplete();
|
||||||
void RegisterPostJobStep(IStep step);
|
void RegisterPostJobStep(IStep step);
|
||||||
IStep RegisterCompositeStep(IStep step, DictionaryContextData inputsData, Dictionary<string, string> envData);
|
|
||||||
void EnqueueAllCompositeSteps(Queue<IStep> steps);
|
|
||||||
public void SetEnvironmentVariables(Dictionary<string, string> dict);
|
public void SetEnvironmentVariables(Dictionary<string, string> dict);
|
||||||
|
void RegisterNestedStep(IStep step, DictionaryContextData inputsData, int location, Dictionary<string, string> envData);
|
||||||
}
|
}
|
||||||
|
|
||||||
public sealed class ExecutionContext : RunnerService, IExecutionContext
|
public sealed class ExecutionContext : RunnerService, IExecutionContext
|
||||||
@@ -162,7 +161,7 @@ namespace GitHub.Runner.Worker
|
|||||||
public List<ContainerInfo> ServiceContainers { get; private set; }
|
public List<ContainerInfo> ServiceContainers { get; private set; }
|
||||||
|
|
||||||
// Only job level ExecutionContext has JobSteps
|
// Only job level ExecutionContext has JobSteps
|
||||||
public Queue<IStep> JobSteps { get; private set; }
|
public List<IStep> JobSteps { get; private set; }
|
||||||
|
|
||||||
// Only job level ExecutionContext has PostJobSteps
|
// Only job level ExecutionContext has PostJobSteps
|
||||||
public Stack<IStep> PostJobSteps { get; private set; }
|
public Stack<IStep> PostJobSteps { get; private set; }
|
||||||
@@ -268,30 +267,13 @@ namespace GitHub.Runner.Worker
|
|||||||
Root.PostJobSteps.Push(step);
|
Root.PostJobSteps.Push(step);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/// <summary>
|
||||||
RegisterCompositeStep is a helper function used in CompositeActionHandler::RunAsync to
|
/// Helper function used in CompositeActionHandler::RunAsync to
|
||||||
add a child node, aka a step, to the current job to the front of the queue for processing.
|
/// add a child node, aka a step, to the current job to the Root.JobSteps based on the location.
|
||||||
*/
|
/// </summary>
|
||||||
public IStep RegisterCompositeStep(IStep step, DictionaryContextData inputsData, Dictionary<string, string> envData)
|
public void RegisterNestedStep(IStep step, DictionaryContextData inputsData, int location, Dictionary<string, string> envData)
|
||||||
{
|
{
|
||||||
// ~Brute Force Method~
|
// TODO: For UI purposes, look at figuring out how to condense steps in one node => maybe use the same previous GUID
|
||||||
// There is no way to put this current job in front of the queue in < O(n) time where n = # of elements in JobSteps
|
|
||||||
// Everytime we add a new step, you could requeue every item to put those steps from that stack in JobSteps which
|
|
||||||
// would result in O(n) for each time we add a composite action step where n = number of jobSteps which would compound
|
|
||||||
// to O(n*m) where m = number of composite steps
|
|
||||||
// var temp = Root.JobSteps.ToArray();
|
|
||||||
// Root.JobSteps.Clear();
|
|
||||||
// Root.JobSteps.Enqueue(step);
|
|
||||||
// foreach(var s in temp)
|
|
||||||
// Root.JobSteps.Enqueue(s);
|
|
||||||
|
|
||||||
// ~Optimized Method~
|
|
||||||
// Alterative solution: We add to another temp Queue
|
|
||||||
// After we add all the transformed composite steps to this temp queue, we requeue the whole JobSteps accordingly in EnqueueAllCompositeSteps()
|
|
||||||
// where the queued composite steps are at the front of the JobSteps Queue and the rest of the jobs maintain its order and are
|
|
||||||
// placed after the queued composite steps
|
|
||||||
// This will take only O(n+m) time which would be just as efficient if we refactored the code of JobSteps to a PriorityQueue
|
|
||||||
// This temp Queue is created in the CompositeActionHandler.
|
|
||||||
var newGuid = Guid.NewGuid();
|
var newGuid = Guid.NewGuid();
|
||||||
step.ExecutionContext = Root.CreateChild(newGuid, step.DisplayName, newGuid.ToString("N"), null, null);
|
step.ExecutionContext = Root.CreateChild(newGuid, step.DisplayName, newGuid.ToString("N"), null, null);
|
||||||
step.ExecutionContext.ExpressionValues["inputs"] = inputsData;
|
step.ExecutionContext.ExpressionValues["inputs"] = inputsData;
|
||||||
@@ -300,8 +282,7 @@ namespace GitHub.Runner.Worker
|
|||||||
// If the key already exists, we override it since the composite action env variables will have higher precedence
|
// If the key already exists, we override it since the composite action env variables will have higher precedence
|
||||||
// Note that for each composite action step, it's environment variables will be set in the StepRunner automatically
|
// Note that for each composite action step, it's environment variables will be set in the StepRunner automatically
|
||||||
step.ExecutionContext.SetEnvironmentVariables(envData);
|
step.ExecutionContext.SetEnvironmentVariables(envData);
|
||||||
|
Root.JobSteps.Insert(0, step);
|
||||||
return step;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void SetEnvironmentVariables(Dictionary<string, string> dict)
|
public void SetEnvironmentVariables(Dictionary<string, string> dict)
|
||||||
@@ -309,33 +290,6 @@ namespace GitHub.Runner.Worker
|
|||||||
this.EnvironmentVariables = dict;
|
this.EnvironmentVariables = dict;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Add Composite Steps first and then requeue the rest of the job steps.
|
|
||||||
public void EnqueueAllCompositeSteps(Queue<IStep> steps)
|
|
||||||
{
|
|
||||||
// TODO: For UI purposes, look at figuring out how to condense steps in one node
|
|
||||||
// maybe use "this" instead of "Root"?
|
|
||||||
if (Root.JobSteps != null)
|
|
||||||
{
|
|
||||||
var temp = Root.JobSteps.ToArray();
|
|
||||||
Root.JobSteps.Clear();
|
|
||||||
foreach (var cs in steps)
|
|
||||||
{
|
|
||||||
Root.JobSteps.Enqueue(cs);
|
|
||||||
}
|
|
||||||
foreach (var s in temp)
|
|
||||||
{
|
|
||||||
Root.JobSteps.Enqueue(s);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
Root.JobSteps = new Queue<IStep>();
|
|
||||||
foreach (var cs in steps)
|
|
||||||
{
|
|
||||||
Root.JobSteps.Enqueue(cs);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
public IExecutionContext CreateChild(Guid recordId, string displayName, string refName, string scopeName, string contextName, Dictionary<string, string> intraActionState = null, int? recordOrder = null)
|
public IExecutionContext CreateChild(Guid recordId, string displayName, string refName, string scopeName, string contextName, Dictionary<string, string> intraActionState = null, int? recordOrder = null)
|
||||||
{
|
{
|
||||||
Trace.Entering();
|
Trace.Entering();
|
||||||
@@ -730,7 +684,7 @@ namespace GitHub.Runner.Worker
|
|||||||
PrependPath = new List<string>();
|
PrependPath = new List<string>();
|
||||||
|
|
||||||
// JobSteps for job ExecutionContext
|
// JobSteps for job ExecutionContext
|
||||||
JobSteps = new Queue<IStep>();
|
JobSteps = new List<IStep>();
|
||||||
|
|
||||||
// PostJobSteps for job ExecutionContext
|
// PostJobSteps for job ExecutionContext
|
||||||
PostJobSteps = new Stack<IStep>();
|
PostJobSteps = new Stack<IStep>();
|
||||||
|
|||||||
@@ -68,7 +68,7 @@ namespace GitHub.Runner.Worker.Handlers
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Add each composite action step to the front of the queue
|
// Add each composite action step to the front of the queue
|
||||||
var compositeActionSteps = new Queue<IStep>();
|
int location = 0;
|
||||||
foreach (Pipelines.ActionStep aStep in actionSteps)
|
foreach (Pipelines.ActionStep aStep in actionSteps)
|
||||||
{
|
{
|
||||||
// Ex:
|
// Ex:
|
||||||
@@ -86,7 +86,7 @@ namespace GitHub.Runner.Worker.Handlers
|
|||||||
// - run echo hello world 3 (d)
|
// - run echo hello world 3 (d)
|
||||||
// - run echo hello world 4 (e)
|
// - run echo hello world 4 (e)
|
||||||
//
|
//
|
||||||
// Stack (LIFO) [Bottom => Middle => Top]:
|
// Steps processed as follow:
|
||||||
// | a |
|
// | a |
|
||||||
// | a | => | d |
|
// | a | => | d |
|
||||||
// (Run step d)
|
// (Run step d)
|
||||||
@@ -109,9 +109,9 @@ namespace GitHub.Runner.Worker.Handlers
|
|||||||
// TODO: Do we need to add any context data from the job message?
|
// TODO: Do we need to add any context data from the job message?
|
||||||
// (See JobExtension.cs ~line 236)
|
// (See JobExtension.cs ~line 236)
|
||||||
|
|
||||||
compositeActionSteps.Enqueue(ExecutionContext.RegisterCompositeStep(actionRunner, inputsData, envData));
|
ExecutionContext.RegisterNestedStep(actionRunner, inputsData, location, envData);
|
||||||
|
location++;
|
||||||
}
|
}
|
||||||
ExecutionContext.EnqueueAllCompositeSteps(compositeActionSteps);
|
|
||||||
|
|
||||||
return Task.CompletedTask;
|
return Task.CompletedTask;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -68,10 +68,7 @@ namespace GitHub.Runner.Worker.Handlers
|
|||||||
}
|
}
|
||||||
else if (data.ExecutionType == ActionExecutionType.Composite)
|
else if (data.ExecutionType == ActionExecutionType.Composite)
|
||||||
{
|
{
|
||||||
// TODO
|
|
||||||
// Runner plugin
|
|
||||||
handler = HostContext.CreateService<ICompositeActionHandler>();
|
handler = HostContext.CreateService<ICompositeActionHandler>();
|
||||||
// handler = CompositeHandler;
|
|
||||||
(handler as ICompositeActionHandler).Data = data as CompositeActionExecutionData;
|
(handler as ICompositeActionHandler).Data = data as CompositeActionExecutionData;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
|||||||
@@ -152,7 +152,7 @@ namespace GitHub.Runner.Worker
|
|||||||
{
|
{
|
||||||
foreach (var step in jobSteps)
|
foreach (var step in jobSteps)
|
||||||
{
|
{
|
||||||
jobContext.JobSteps.Enqueue(step);
|
jobContext.JobSteps.Add(step);
|
||||||
}
|
}
|
||||||
|
|
||||||
await stepsRunner.RunAsync(jobContext);
|
await stepsRunner.RunAsync(jobContext);
|
||||||
|
|||||||
@@ -59,19 +59,15 @@ namespace GitHub.Runner.Worker
|
|||||||
checkPostJobActions = true;
|
checkPostJobActions = true;
|
||||||
while (jobContext.PostJobSteps.TryPop(out var postStep))
|
while (jobContext.PostJobSteps.TryPop(out var postStep))
|
||||||
{
|
{
|
||||||
jobContext.JobSteps.Enqueue(postStep);
|
jobContext.JobSteps.Add(postStep);
|
||||||
}
|
}
|
||||||
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
var step = jobContext.JobSteps.Dequeue();
|
var step = jobContext.JobSteps[0];
|
||||||
var nextStep = jobContext.JobSteps.Count > 0 ? jobContext.JobSteps.Peek() : null;
|
jobContext.JobSteps.RemoveAt(0);
|
||||||
// TODO: Fix this temporary workaround for Composite Actions
|
var nextStep = jobContext.JobSteps.Count > 0 ? jobContext.JobSteps[0] : null;
|
||||||
if (!string.IsNullOrEmpty(Environment.GetEnvironmentVariable("TESTING_COMPOSITE_ACTIONS_ALPHA")))
|
|
||||||
{
|
|
||||||
nextStep = null;
|
|
||||||
}
|
|
||||||
|
|
||||||
Trace.Info($"Processing step: DisplayName='{step.DisplayName}'");
|
Trace.Info($"Processing step: DisplayName='{step.DisplayName}'");
|
||||||
ArgUtil.NotNull(step.ExecutionContext, nameof(step.ExecutionContext));
|
ArgUtil.NotNull(step.ExecutionContext, nameof(step.ExecutionContext));
|
||||||
|
|||||||
@@ -65,7 +65,6 @@ namespace GitHub.DistributedTask.Pipelines.ObjectTemplating
|
|||||||
public const String StepEnv = "step-env";
|
public const String StepEnv = "step-env";
|
||||||
public const String StepIfResult = "step-if-result";
|
public const String StepIfResult = "step-if-result";
|
||||||
public const String Steps = "steps";
|
public const String Steps = "steps";
|
||||||
|
|
||||||
public const String StepsInTemplate = "steps-in-template";
|
public const String StepsInTemplate = "steps-in-template";
|
||||||
public const String StepsScopeInputs = "steps-scope-inputs";
|
public const String StepsScopeInputs = "steps-scope-inputs";
|
||||||
public const String StepsScopeOutputs = "steps-scope-outputs";
|
public const String StepsScopeOutputs = "steps-scope-outputs";
|
||||||
|
|||||||
@@ -80,7 +80,7 @@ namespace GitHub.Runner.Common.Tests.Worker
|
|||||||
{
|
{
|
||||||
_ec.Object.Result = null;
|
_ec.Object.Result = null;
|
||||||
|
|
||||||
_ec.Setup(x => x.JobSteps).Returns(new Queue<IStep>(variableSet.Select(x => x.Object).ToList()));
|
_ec.Setup(x => x.JobSteps).Returns(new List<IStep>(variableSet.Select(x => x.Object).ToList()));
|
||||||
|
|
||||||
// Act.
|
// Act.
|
||||||
await _stepsRunner.RunAsync(jobContext: _ec.Object);
|
await _stepsRunner.RunAsync(jobContext: _ec.Object);
|
||||||
@@ -115,7 +115,7 @@ namespace GitHub.Runner.Common.Tests.Worker
|
|||||||
{
|
{
|
||||||
_ec.Object.Result = null;
|
_ec.Object.Result = null;
|
||||||
|
|
||||||
_ec.Setup(x => x.JobSteps).Returns(new Queue<IStep>(variableSet.Select(x => x.Object).ToList()));
|
_ec.Setup(x => x.JobSteps).Returns(new List<IStep>(variableSet.Select(x => x.Object).ToList()));
|
||||||
|
|
||||||
// Act.
|
// Act.
|
||||||
await _stepsRunner.RunAsync(jobContext: _ec.Object);
|
await _stepsRunner.RunAsync(jobContext: _ec.Object);
|
||||||
@@ -154,7 +154,7 @@ namespace GitHub.Runner.Common.Tests.Worker
|
|||||||
{
|
{
|
||||||
_ec.Object.Result = null;
|
_ec.Object.Result = null;
|
||||||
|
|
||||||
_ec.Setup(x => x.JobSteps).Returns(new Queue<IStep>(variableSet.Steps.Select(x => x.Object).ToList()));
|
_ec.Setup(x => x.JobSteps).Returns(new List<IStep>(variableSet.Steps.Select(x => x.Object).ToList()));
|
||||||
|
|
||||||
// Act.
|
// Act.
|
||||||
await _stepsRunner.RunAsync(jobContext: _ec.Object);
|
await _stepsRunner.RunAsync(jobContext: _ec.Object);
|
||||||
@@ -208,7 +208,7 @@ namespace GitHub.Runner.Common.Tests.Worker
|
|||||||
{
|
{
|
||||||
_ec.Object.Result = null;
|
_ec.Object.Result = null;
|
||||||
|
|
||||||
_ec.Setup(x => x.JobSteps).Returns(new Queue<IStep>(variableSet.Steps.Select(x => x.Object).ToList()));
|
_ec.Setup(x => x.JobSteps).Returns(new List<IStep>(variableSet.Steps.Select(x => x.Object).ToList()));
|
||||||
|
|
||||||
// Act.
|
// Act.
|
||||||
await _stepsRunner.RunAsync(jobContext: _ec.Object);
|
await _stepsRunner.RunAsync(jobContext: _ec.Object);
|
||||||
@@ -287,7 +287,7 @@ namespace GitHub.Runner.Common.Tests.Worker
|
|||||||
{
|
{
|
||||||
_ec.Object.Result = null;
|
_ec.Object.Result = null;
|
||||||
|
|
||||||
_ec.Setup(x => x.JobSteps).Returns(new Queue<IStep>(variableSet.Steps.Select(x => x.Object).ToList()));
|
_ec.Setup(x => x.JobSteps).Returns(new List<IStep>(variableSet.Steps.Select(x => x.Object).ToList()));
|
||||||
|
|
||||||
// Act.
|
// Act.
|
||||||
await _stepsRunner.RunAsync(jobContext: _ec.Object);
|
await _stepsRunner.RunAsync(jobContext: _ec.Object);
|
||||||
@@ -330,7 +330,7 @@ namespace GitHub.Runner.Common.Tests.Worker
|
|||||||
{
|
{
|
||||||
_ec.Object.Result = null;
|
_ec.Object.Result = null;
|
||||||
|
|
||||||
_ec.Setup(x => x.JobSteps).Returns(new Queue<IStep>(variableSet.Step.Select(x => x.Object).ToList()));
|
_ec.Setup(x => x.JobSteps).Returns(new List<IStep>(variableSet.Step.Select(x => x.Object).ToList()));
|
||||||
|
|
||||||
// Act.
|
// Act.
|
||||||
await _stepsRunner.RunAsync(jobContext: _ec.Object);
|
await _stepsRunner.RunAsync(jobContext: _ec.Object);
|
||||||
@@ -361,7 +361,7 @@ namespace GitHub.Runner.Common.Tests.Worker
|
|||||||
{
|
{
|
||||||
_ec.Object.Result = null;
|
_ec.Object.Result = null;
|
||||||
|
|
||||||
_ec.Setup(x => x.JobSteps).Returns(new Queue<IStep>(variableSet.Select(x => x.Object).ToList()));
|
_ec.Setup(x => x.JobSteps).Returns(new List<IStep>(variableSet.Select(x => x.Object).ToList()));
|
||||||
|
|
||||||
// Act.
|
// Act.
|
||||||
await _stepsRunner.RunAsync(jobContext: _ec.Object);
|
await _stepsRunner.RunAsync(jobContext: _ec.Object);
|
||||||
@@ -391,7 +391,7 @@ namespace GitHub.Runner.Common.Tests.Worker
|
|||||||
{
|
{
|
||||||
_ec.Object.Result = null;
|
_ec.Object.Result = null;
|
||||||
|
|
||||||
_ec.Setup(x => x.JobSteps).Returns(new Queue<IStep>(variableSet.Select(x => x.Object).ToList()));
|
_ec.Setup(x => x.JobSteps).Returns(new List<IStep>(variableSet.Select(x => x.Object).ToList()));
|
||||||
|
|
||||||
// Act.
|
// Act.
|
||||||
await _stepsRunner.RunAsync(jobContext: _ec.Object);
|
await _stepsRunner.RunAsync(jobContext: _ec.Object);
|
||||||
@@ -417,7 +417,7 @@ namespace GitHub.Runner.Common.Tests.Worker
|
|||||||
|
|
||||||
_ec.Object.Result = null;
|
_ec.Object.Result = null;
|
||||||
|
|
||||||
_ec.Setup(x => x.JobSteps).Returns(new Queue<IStep>(new[] { step1.Object }));
|
_ec.Setup(x => x.JobSteps).Returns(new List<IStep>(new[] { step1.Object }));
|
||||||
|
|
||||||
// Act.
|
// Act.
|
||||||
await _stepsRunner.RunAsync(jobContext: _ec.Object);
|
await _stepsRunner.RunAsync(jobContext: _ec.Object);
|
||||||
@@ -455,7 +455,7 @@ namespace GitHub.Runner.Common.Tests.Worker
|
|||||||
|
|
||||||
_ec.Object.Result = null;
|
_ec.Object.Result = null;
|
||||||
|
|
||||||
_ec.Setup(x => x.JobSteps).Returns(new Queue<IStep>(new[] { step1.Object, step2.Object }));
|
_ec.Setup(x => x.JobSteps).Returns(new List<IStep>(new[] { step1.Object, step2.Object }));
|
||||||
|
|
||||||
// Act.
|
// Act.
|
||||||
await _stepsRunner.RunAsync(jobContext: _ec.Object);
|
await _stepsRunner.RunAsync(jobContext: _ec.Object);
|
||||||
@@ -493,7 +493,7 @@ namespace GitHub.Runner.Common.Tests.Worker
|
|||||||
|
|
||||||
_ec.Object.Result = null;
|
_ec.Object.Result = null;
|
||||||
|
|
||||||
_ec.Setup(x => x.JobSteps).Returns(new Queue<IStep>(new[] { step1.Object, step2.Object }));
|
_ec.Setup(x => x.JobSteps).Returns(new List<IStep>(new[] { step1.Object, step2.Object }));
|
||||||
|
|
||||||
// Act.
|
// Act.
|
||||||
await _stepsRunner.RunAsync(jobContext: _ec.Object);
|
await _stepsRunner.RunAsync(jobContext: _ec.Object);
|
||||||
@@ -524,7 +524,7 @@ namespace GitHub.Runner.Common.Tests.Worker
|
|||||||
|
|
||||||
_ec.Object.Result = null;
|
_ec.Object.Result = null;
|
||||||
|
|
||||||
_ec.Setup(x => x.JobSteps).Returns(new Queue<IStep>(new[] { step1.Object, step2.Object, step3.Object }));
|
_ec.Setup(x => x.JobSteps).Returns(new List<IStep>(new[] { step1.Object, step2.Object, step3.Object }));
|
||||||
|
|
||||||
// Act.
|
// Act.
|
||||||
await _stepsRunner.RunAsync(jobContext: _ec.Object);
|
await _stepsRunner.RunAsync(jobContext: _ec.Object);
|
||||||
@@ -560,7 +560,7 @@ namespace GitHub.Runner.Common.Tests.Worker
|
|||||||
|
|
||||||
_ec.Object.Result = null;
|
_ec.Object.Result = null;
|
||||||
|
|
||||||
_ec.Setup(x => x.JobSteps).Returns(new Queue<IStep>(new[] { step1.Object, step2.Object, step3.Object }));
|
_ec.Setup(x => x.JobSteps).Returns(new List<IStep>(new[] { step1.Object, step2.Object, step3.Object }));
|
||||||
|
|
||||||
// Act.
|
// Act.
|
||||||
await _stepsRunner.RunAsync(jobContext: _ec.Object);
|
await _stepsRunner.RunAsync(jobContext: _ec.Object);
|
||||||
|
|||||||
Reference in New Issue
Block a user