mirror of
https://github.com/actions/runner.git
synced 2025-12-11 21:06:55 +00:00
* Composite Action Run Steps * Env Flow => Able to get env variables and overwrite current env variables => but it doesn't 'stick' * clean up * Clean up trace messages + add Trace debug in ActionManager * Add debugging message * Optimize runtime of code * Change String to string * Add comma to Composite * Change JobSteps to a List, Change Register Step function name * Add TODO, remove unn. content * Remove unnecessary code * Fix unit tests * Fix env format * Remove comment * Remove TODO message for context * Add verbose trace logs which are only viewable by devs * Sort usings in Composite Action Handler * Change 0 to location * Update context variables in composite action yaml * Add helpful error message for null steps * Fix Workflow Step Env overiding Parent Env * Remove env in composite action scope * Clean up * Revert back * revert back * add back envToken * Remove unnecessary code * Figure out how to handle set-env edge cases * formatting * fix unit tests * Fix windows unit test syntax error
97 lines
3.2 KiB
C#
97 lines
3.2 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.IO;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
using GitHub.DistributedTask.ObjectTemplating.Tokens;
|
|
using GitHub.DistributedTask.Pipelines.ContextData;
|
|
using GitHub.DistributedTask.WebApi;
|
|
using GitHub.Runner.Common;
|
|
using GitHub.Runner.Sdk;
|
|
using Pipelines = GitHub.DistributedTask.Pipelines;
|
|
|
|
|
|
namespace GitHub.Runner.Worker.Handlers
|
|
{
|
|
[ServiceLocator(Default = typeof(CompositeActionHandler))]
|
|
public interface ICompositeActionHandler : IHandler
|
|
{
|
|
CompositeActionExecutionData Data { get; set; }
|
|
}
|
|
public sealed class CompositeActionHandler : Handler, ICompositeActionHandler
|
|
{
|
|
public CompositeActionExecutionData Data { get; set; }
|
|
|
|
public Task RunAsync(ActionRunStage stage)
|
|
{
|
|
// Validate args.
|
|
Trace.Entering();
|
|
ArgUtil.NotNull(ExecutionContext, nameof(ExecutionContext));
|
|
ArgUtil.NotNull(Inputs, nameof(Inputs));
|
|
|
|
var githubContext = ExecutionContext.ExpressionValues["github"] as GitHubContext;
|
|
ArgUtil.NotNull(githubContext, nameof(githubContext));
|
|
|
|
var tempDirectory = HostContext.GetDirectory(WellKnownDirectory.Temp);
|
|
|
|
// Resolve action steps
|
|
var actionSteps = Data.Steps;
|
|
|
|
// Create Context Data to reuse for each composite action step
|
|
var inputsData = new DictionaryContextData();
|
|
foreach (var i in Inputs)
|
|
{
|
|
inputsData[i.Key] = new StringContextData(i.Value);
|
|
}
|
|
|
|
// Add each composite action step to the front of the queue
|
|
int location = 0;
|
|
foreach (Pipelines.ActionStep 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.
|
|
|
|
var actionRunner = HostContext.CreateService<IActionRunner>();
|
|
actionRunner.Action = aStep;
|
|
actionRunner.Stage = stage;
|
|
actionRunner.Condition = aStep.Condition;
|
|
actionRunner.DisplayName = aStep.DisplayName;
|
|
|
|
ExecutionContext.RegisterNestedStep(actionRunner, inputsData, location, Environment);
|
|
location++;
|
|
}
|
|
|
|
return Task.CompletedTask;
|
|
}
|
|
|
|
}
|
|
}
|