forked from actions/runner
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Composite Actions Support for Multiple Run Steps (actions#549)
* Composite Action Run Steps * Clean up trace messages + add Trace debug in ActionManager * 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 * 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
- Loading branch information
1 parent
ee5b7ce
commit 5e0e4ff
Showing
13 changed files
with
624 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
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; | ||
// TODO: Do we need to add any context data from the job message? | ||
// (See JobExtension.cs ~line 236) | ||
|
||
ExecutionContext.RegisterNestedStep(actionRunner, inputsData, location); | ||
location++; | ||
} | ||
|
||
return Task.CompletedTask; | ||
} | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.