-
Notifications
You must be signed in to change notification settings - Fork 1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Composite Actions: Support Env Flow #557
Merged
Merged
Changes from 7 commits
Commits
Show all changes
38 commits
Select commit
Hold shift + click to select a range
038e5e2
Composite Action Run Steps
ethanchewy e56b243
Env Flow => Able to get env variables and overwrite current env varia…
ethanchewy 6552263
clean up
ethanchewy 180a687
Clean up trace messages + add Trace debug in ActionManager
ethanchewy 66cadeb
Merge branch 'users/ethanchewy/compositetest2' of https://github.com/…
ethanchewy 96e0037
Add debugging message
ethanchewy 496064f
Optimize runtime of code
ethanchewy 5843362
Change String to string
ethanchewy 941a24e
Add comma to Composite
ethanchewy 28be3df
Merge branch 'users/ethanchewy/compositetest2' of https://github.com/…
ethanchewy 9939cf5
Change JobSteps to a List, Change Register Step function name
ethanchewy 5988076
Add TODO, remove unn. content
ethanchewy 00a736d
Remove unnecessary code
ethanchewy e4dfd0e
Fix unit tests
ethanchewy f8054f9
Add/Merge changes from Multiple Steps PR
ethanchewy 45ddd42
Fix env format
ethanchewy 37849dc
Remove comment
ethanchewy 94e7b47
Remove TODO message for context
ethanchewy a254442
Add verbose trace logs which are only viewable by devs
ethanchewy fbef557
Merge branch 'users/ethanchewy/compositetest2' of https://github.com/…
ethanchewy 0d5e84b
Sort usings in Composite Action Handler
ethanchewy 9ec7047
Change 0 to location
ethanchewy 8aadbbd
Update context variables in composite action yaml
ethanchewy f9b28c7
Add helpful error message for null steps
ethanchewy 1f6518d
Merge branch 'users/ethanchewy/compositetest2' of https://github.com/…
ethanchewy 57d59fc
Fix Workflow Step Env overiding Parent Env
ethanchewy b63f987
Remove env in composite action scope
ethanchewy da1e2b0
Clean up
ethanchewy 5d61145
Revert back
ethanchewy 4ccac8c
revert back
ethanchewy 0041023
add back envToken
ethanchewy 4b3ec9f
Remove unnecessary code
ethanchewy 96bff6a
Figure out how to handle set-env edge cases
ethanchewy 11b9cac
formatting
ethanchewy b712ba2
Merge branch 'master' into users/ethanchewy/compositeenv
ethanchewy a58ac2e
fix unit tests
ethanchewy 5178468
Merge branch 'users/ethanchewy/compositeenv' of https://github.com/ac…
ethanchewy 881e8e7
Fix windows unit test syntax error
ethanchewy File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,6 +14,7 @@ | |
using YamlDotNet.Core.Events; | ||
using System.Globalization; | ||
using System.Linq; | ||
using Pipelines = GitHub.DistributedTask.Pipelines; | ||
|
||
namespace GitHub.Runner.Worker | ||
{ | ||
|
@@ -26,6 +27,7 @@ public interface IActionManifestManager : IRunnerService | |
|
||
Dictionary<string, string> EvaluateContainerEnvironment(IExecutionContext executionContext, MappingToken token, IDictionary<string, PipelineContextData> extraExpressionValues); | ||
|
||
public Dictionary<string, string> EvaluateCompositeActionEnvironment(IExecutionContext executionContext, MappingToken token, IDictionary<string, PipelineContextData> extraExpressionValues); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. remove |
||
string EvaluateDefaultInput(IExecutionContext executionContext, string inputName, TemplateToken token); | ||
} | ||
|
||
|
@@ -92,7 +94,7 @@ public ActionDefinitionData Load(IExecutionContext executionContext, string mani | |
break; | ||
|
||
case "runs": | ||
actionDefinition.Execution = ConvertRuns(context, actionPair.Value); | ||
actionDefinition.Execution = ConvertRuns(executionContext, context, actionPair.Value); | ||
break; | ||
default: | ||
Trace.Info($"Ignore action property {propertyName}."); | ||
|
@@ -181,7 +183,7 @@ public Dictionary<string, string> EvaluateContainerEnvironment( | |
var context = CreateContext(executionContext, extraExpressionValues); | ||
try | ||
{ | ||
var evaluateResult = TemplateEvaluator.Evaluate(context, "container-runs-env", token, 0, null, omitHeader: true); | ||
var evaluateResult = TemplateEvaluator.Evaluate(context, "runs-env", token, 0, null, omitHeader: true); | ||
context.Errors.Check(); | ||
|
||
Trace.Info($"Environments evaluate result: {StringUtil.ConvertToJson(evaluateResult)}"); | ||
|
@@ -213,6 +215,48 @@ public Dictionary<string, string> EvaluateContainerEnvironment( | |
return result; | ||
} | ||
|
||
public Dictionary<string, string> EvaluateCompositeActionEnvironment( | ||
IExecutionContext executionContext, | ||
MappingToken token, | ||
IDictionary<string, PipelineContextData> extraExpressionValues) | ||
{ | ||
var result = new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase); | ||
|
||
if (token != null) | ||
{ | ||
var context = CreateContext(executionContext, extraExpressionValues); | ||
try | ||
{ | ||
var evaluateResult = TemplateEvaluator.Evaluate(context, "runs-env", token, 0, null, omitHeader: true); | ||
context.Errors.Check(); | ||
|
||
// Mapping | ||
var mapping = evaluateResult.AssertMapping("composite env"); | ||
|
||
foreach (var pair in mapping) | ||
{ | ||
// Literal key | ||
var key = pair.Key.AssertString("composite env key"); | ||
|
||
// Literal value | ||
var value = pair.Value.AssertString("composite env value"); | ||
result[key.Value] = value.Value; | ||
|
||
Trace.Info($"Add env {key} = {value}"); | ||
} | ||
} | ||
catch (Exception ex) when (!(ex is TemplateValidationException)) | ||
{ | ||
Trace.Error(ex); | ||
context.Errors.Add(ex); | ||
} | ||
|
||
context.Errors.Check(); | ||
} | ||
|
||
return result; | ||
|
||
} | ||
public string EvaluateDefaultInput( | ||
IExecutionContext executionContext, | ||
string inputName, | ||
|
@@ -284,7 +328,7 @@ private TemplateContext CreateContext( | |
// Add the file table | ||
if (_fileTable?.Count > 0) | ||
{ | ||
for (var i = 0 ; i < _fileTable.Count ; i++) | ||
for (var i = 0; i < _fileTable.Count; i++) | ||
{ | ||
result.GetFileId(_fileTable[i]); | ||
} | ||
|
@@ -294,6 +338,7 @@ private TemplateContext CreateContext( | |
} | ||
|
||
private ActionExecutionData ConvertRuns( | ||
IExecutionContext executionContext, | ||
TemplateContext context, | ||
TemplateToken inputsToken) | ||
{ | ||
|
@@ -311,6 +356,8 @@ private ActionExecutionData ConvertRuns( | |
var postToken = default(StringToken); | ||
var postEntrypointToken = default(StringToken); | ||
var postIfToken = default(StringToken); | ||
var stepsLoaded = default(List<Pipelines.ActionStep>); | ||
|
||
foreach (var run in runsMapping) | ||
{ | ||
var runsKey = run.Key.AssertString("runs key").Value; | ||
|
@@ -355,6 +402,15 @@ private ActionExecutionData ConvertRuns( | |
case "pre-if": | ||
preIfToken = run.Value.AssertString("pre-if"); | ||
break; | ||
case "steps": | ||
if (!String.IsNullOrEmpty(Environment.GetEnvironmentVariable("TESTING_COMPOSITE_ACTIONS_ALPHA"))) | ||
{ | ||
var steps = run.Value.AssertSequence("steps"); | ||
var evaluator = executionContext.ToPipelineTemplateEvaluator(); | ||
stepsLoaded = evaluator.LoadCompositeSteps(steps); | ||
break; | ||
} | ||
throw new Exception("You aren't supposed to be using Composite Actions yet!"); | ||
default: | ||
Trace.Info($"Ignore run property {runsKey}."); | ||
break; | ||
|
@@ -402,6 +458,21 @@ private ActionExecutionData ConvertRuns( | |
}; | ||
} | ||
} | ||
else if (string.Equals(usingToken.Value, "composite", StringComparison.OrdinalIgnoreCase) && !String.IsNullOrEmpty(Environment.GetEnvironmentVariable("TESTING_COMPOSITE_ACTIONS_ALPHA"))) | ||
{ | ||
if (stepsLoaded == null) | ||
{ | ||
throw new ArgumentNullException($"No steps provided."); | ||
} | ||
else | ||
{ | ||
return new CompositeActionExecutionData() | ||
{ | ||
Steps = stepsLoaded, | ||
Environment = envToken | ||
}; | ||
} | ||
} | ||
else | ||
{ | ||
throw new ArgumentOutOfRangeException($"'using: {usingToken.Value}' is not supported, use 'docker' or 'node12' instead."); | ||
|
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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
remove