Skip to content
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 38 commits into from
Jul 8, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
038e5e2
Composite Action Run Steps
ethanchewy Jun 18, 2020
e56b243
Env Flow => Able to get env variables and overwrite current env varia…
ethanchewy Jun 18, 2020
6552263
clean up
ethanchewy Jun 18, 2020
180a687
Clean up trace messages + add Trace debug in ActionManager
ethanchewy Jun 18, 2020
66cadeb
Merge branch 'users/ethanchewy/compositetest2' of https://github.com/…
ethanchewy Jun 18, 2020
96e0037
Add debugging message
ethanchewy Jun 18, 2020
496064f
Optimize runtime of code
ethanchewy Jun 18, 2020
5843362
Change String to string
ethanchewy Jun 19, 2020
941a24e
Add comma to Composite
ethanchewy Jun 19, 2020
28be3df
Merge branch 'users/ethanchewy/compositetest2' of https://github.com/…
ethanchewy Jun 19, 2020
9939cf5
Change JobSteps to a List, Change Register Step function name
ethanchewy Jun 19, 2020
5988076
Add TODO, remove unn. content
ethanchewy Jun 19, 2020
00a736d
Remove unnecessary code
ethanchewy Jun 19, 2020
e4dfd0e
Fix unit tests
ethanchewy Jun 19, 2020
f8054f9
Add/Merge changes from Multiple Steps PR
ethanchewy Jun 19, 2020
45ddd42
Fix env format
ethanchewy Jun 20, 2020
37849dc
Remove comment
ethanchewy Jun 22, 2020
94e7b47
Remove TODO message for context
ethanchewy Jun 22, 2020
a254442
Add verbose trace logs which are only viewable by devs
ethanchewy Jun 22, 2020
fbef557
Merge branch 'users/ethanchewy/compositetest2' of https://github.com/…
ethanchewy Jun 22, 2020
0d5e84b
Sort usings in Composite Action Handler
ethanchewy Jun 23, 2020
9ec7047
Change 0 to location
ethanchewy Jun 23, 2020
8aadbbd
Update context variables in composite action yaml
ethanchewy Jun 23, 2020
f9b28c7
Add helpful error message for null steps
ethanchewy Jun 23, 2020
1f6518d
Merge branch 'users/ethanchewy/compositetest2' of https://github.com/…
ethanchewy Jun 23, 2020
57d59fc
Fix Workflow Step Env overiding Parent Env
ethanchewy Jun 25, 2020
b63f987
Remove env in composite action scope
ethanchewy Jul 7, 2020
da1e2b0
Clean up
ethanchewy Jul 7, 2020
5d61145
Revert back
ethanchewy Jul 7, 2020
4ccac8c
revert back
ethanchewy Jul 7, 2020
0041023
add back envToken
ethanchewy Jul 7, 2020
4b3ec9f
Remove unnecessary code
ethanchewy Jul 7, 2020
96bff6a
Figure out how to handle set-env edge cases
ethanchewy Jul 7, 2020
11b9cac
formatting
ethanchewy Jul 7, 2020
b712ba2
Merge branch 'master' into users/ethanchewy/compositeenv
ethanchewy Jul 7, 2020
a58ac2e
fix unit tests
ethanchewy Jul 8, 2020
5178468
Merge branch 'users/ethanchewy/compositeenv' of https://github.com/ac…
ethanchewy Jul 8, 2020
881e8e7
Fix windows unit test syntax error
ethanchewy Jul 8, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
379 changes: 194 additions & 185 deletions src/Misc/dotnet-install.ps1

Large diffs are not rendered by default.

21 changes: 18 additions & 3 deletions src/Runner.Worker/ExecutionContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ public interface IExecutionContext : IRunnerService
// others
void ForceTaskComplete();
void RegisterPostJobStep(IStep step);
void RegisterNestedStep(IStep step, DictionaryContextData inputsData, int location);
void RegisterNestedStep(IStep step, DictionaryContextData inputsData, int location, Dictionary<string, string> envData);
}

public sealed class ExecutionContext : RunnerService, IExecutionContext
Expand Down Expand Up @@ -270,13 +270,28 @@ public void RegisterPostJobStep(IStep step)
/// Helper function used in CompositeActionHandler::RunAsync to
/// add a child node, aka a step, to the current job to the Root.JobSteps based on the location.
/// </summary>
public void RegisterNestedStep(IStep step, DictionaryContextData inputsData, int location)
public void RegisterNestedStep(IStep step, DictionaryContextData inputsData, int location, Dictionary<string, string> envData)
{
// TODO: For UI purposes, look at figuring out how to condense steps in one node => maybe use the same previous GUID
var newGuid = Guid.NewGuid();
step.ExecutionContext = Root.CreateChild(newGuid, step.DisplayName, newGuid.ToString("N"), null, null);
step.ExecutionContext.ExpressionValues["inputs"] = inputsData;
// TODO: confirm whether not copying message contexts is safe

// Add the composite action environment variables to each step.
// 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
// step.ExecutionContext.SetEnvironmentVariables(envData);
#if OS_WINDOWS
var envContext = new DictionaryContextData();
#else
var envContext = new CaseSensitiveDictionaryContextData();
#endif
foreach (var pair in envData)
{
envContext[pair.Key] = new StringContextData(pair.Value ?? string.Empty);
}
step.ExecutionContext.ExpressionValues["env"] = envContext;

Root.JobSteps.Insert(location, step);
}

Expand Down
4 changes: 1 addition & 3 deletions src/Runner.Worker/Handlers/CompositeActionHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -84,10 +84,8 @@ public Task RunAsync(ActionRunStage stage)
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);
ExecutionContext.RegisterNestedStep(actionRunner, inputsData, location, Environment);
location++;
}

Expand Down
18 changes: 17 additions & 1 deletion src/Runner.Worker/StepsRunner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -93,12 +93,28 @@ public async Task RunAsync(IExecutionContext jobContext)
#else
var envContext = new CaseSensitiveDictionaryContextData();
#endif
step.ExecutionContext.ExpressionValues["env"] = envContext;
// Global env
foreach (var pair in step.ExecutionContext.EnvironmentVariables)
{
envContext[pair.Key] = new StringContextData(pair.Value ?? string.Empty);
}

// Stomps over with outside step env
if (step.ExecutionContext.ExpressionValues.TryGetValue("env", out var envContextData))
{
#if OS_WINDOWS
var dict = envContextData as DictionaryContextData;
#else
var dict = envContextData as CaseSensitiveDictionaryContextData;
#endif
foreach (var pair in dict)
{
envContext[pair.Key] = pair.Value;
}
}

step.ExecutionContext.ExpressionValues["env"] = envContext;

bool evaluateStepEnvFailed = false;
if (step is IActionRunner actionStep)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -160,8 +160,7 @@ public String EvaluateStepDisplayName(
}

public List<ActionStep> LoadCompositeSteps(
TemplateToken token
)
TemplateToken token)
{
var result = default(List<ActionStep>);
if (token != null && token.Type != TokenType.Null)
Expand Down
30 changes: 15 additions & 15 deletions src/Test/L0/Worker/StepsRunnerL0.cs
Original file line number Diff line number Diff line change
Expand Up @@ -426,11 +426,11 @@ public async Task StepEnvOverrideJobEnvContext()
Assert.Equal(TaskResult.Succeeded, _ec.Object.Result ?? TaskResult.Succeeded);

#if OS_WINDOWS
Assert.Equal("100", _ec.Object.ExpressionValues["env"].AssertDictionary("env")["env1"].AssertString("100"));
Assert.Equal("github_actions", _ec.Object.ExpressionValues["env"].AssertDictionary("env")["env2"].AssertString("github_actions"));
Assert.Equal("100", step1.Object.ExecutionContext.ExpressionValues["env"].AssertDictionary("env")["env1"].AssertString("100"));
Assert.Equal("github_actions", step1.Object.ExecutionContext.ExpressionValues["env"].AssertDictionary("env")["env2"].AssertString("github_actions"));
#else
Assert.Equal("100", _ec.Object.ExpressionValues["env"].AssertCaseSensitiveDictionary("env")["env1"].AssertString("100"));
Assert.Equal("github_actions", _ec.Object.ExpressionValues["env"].AssertCaseSensitiveDictionary("env")["env2"].AssertString("github_actions"));
Assert.Equal("100", step1.Object.ExecutionContext.ExpressionValues["env"].AssertCaseSensitiveDictionary("env")["env1"].AssertString("100"));
Assert.Equal("github_actions", step1.Object.ExecutionContext.ExpressionValues["env"].AssertCaseSensitiveDictionary("env")["env2"].AssertString("github_actions"));
#endif
}
}
Expand Down Expand Up @@ -463,13 +463,13 @@ public async Task PopulateEnvContextForEachStep()
// Assert.
Assert.Equal(TaskResult.Succeeded, _ec.Object.Result ?? TaskResult.Succeeded);
#if OS_WINDOWS
Assert.Equal("1000", _ec.Object.ExpressionValues["env"].AssertDictionary("env")["env1"].AssertString("1000"));
Assert.Equal("github_actions", _ec.Object.ExpressionValues["env"].AssertDictionary("env")["env3"].AssertString("github_actions"));
Assert.False(_ec.Object.ExpressionValues["env"].AssertDictionary("env").ContainsKey("env2"));
Assert.Equal("1000", step2.Object.ExecutionContext.ExpressionValues["env"].AssertDictionary("env")["env1"].AssertString("1000"));
Assert.Equal("github_actions", step2.Object.ExecutionContext.ExpressionValues["env"].AssertDictionary("env")["env3"].AssertString("github_actions"));
Assert.False(step2.Object.ExecutionContext.ExpressionValues["env"].AssertDictionary("env").ContainsKey("env2"));
#else
Assert.Equal("1000", _ec.Object.ExpressionValues["env"].AssertCaseSensitiveDictionary("env")["env1"].AssertString("1000"));
Assert.Equal("github_actions", _ec.Object.ExpressionValues["env"].AssertCaseSensitiveDictionary("env")["env3"].AssertString("github_actions"));
Assert.False(_ec.Object.ExpressionValues["env"].AssertCaseSensitiveDictionary("env").ContainsKey("env2"));
Assert.Equal("1000", step2.Object.ExecutionContext.ExpressionValues["env"].AssertCaseSensitiveDictionary("env")["env1"].AssertString("1000"));
Assert.Equal("github_actions", step2.Object.ExecutionContext.ExpressionValues["env"].AssertCaseSensitiveDictionary("env")["env3"].AssertString("github_actions"));
Assert.False(step2.Object.ExecutionContext.ExpressionValues["env"].AssertCaseSensitiveDictionary("env").ContainsKey("env2"));
#endif
}
}
Expand Down Expand Up @@ -501,11 +501,11 @@ public async Task PopulateEnvContextAfterSetupStepsContext()
// Assert.
Assert.Equal(TaskResult.Succeeded, _ec.Object.Result ?? TaskResult.Succeeded);
#if OS_WINDOWS
Assert.Equal("1000", _ec.Object.ExpressionValues["env"].AssertDictionary("env")["env1"].AssertString("1000"));
Assert.Equal("something", _ec.Object.ExpressionValues["env"].AssertDictionary("env")["env2"].AssertString("something"));
Assert.Equal("1000", step2.Object.ExecutionContext.ExpressionValues["env"].AssertDictionary("env")["env1"].AssertString("1000"));
Assert.Equal("something", step2.Object.ExecutionContext.ExpressionValues["env"].AssertDictionary("env")["env2"].AssertString("something"));
#else
Assert.Equal("1000", _ec.Object.ExpressionValues["env"].AssertCaseSensitiveDictionary("env")["env1"].AssertString("1000"));
Assert.Equal("something", _ec.Object.ExpressionValues["env"].AssertCaseSensitiveDictionary("env")["env2"].AssertString("something"));
Assert.Equal("1000", step2.Object.ExecutionContext.ExpressionValues["env"].AssertCaseSensitiveDictionary("env")["env1"].AssertString("1000"));
Assert.Equal("something", step2.Object.ExecutionContext.ExpressionValues["env"].AssertCaseSensitiveDictionary("env")["env2"].AssertString("something"));
#endif
}
}
Expand Down Expand Up @@ -602,7 +602,7 @@ private Mock<IActionRunner> CreateStep(TestHostContext hc, TaskResult result, st
stepContext.Setup(x => x.WriteDebug).Returns(true);
stepContext.Setup(x => x.Variables).Returns(_variables);
stepContext.Setup(x => x.EnvironmentVariables).Returns(_env);
stepContext.Setup(x => x.ExpressionValues).Returns(_contexts);
stepContext.Setup(x => x.ExpressionValues).Returns(new DictionaryContextData());
stepContext.Setup(x => x.ExpressionFunctions).Returns(new List<IFunctionInfo>());
stepContext.Setup(x => x.JobContext).Returns(_jobContext);
stepContext.Setup(x => x.StepsContext).Returns(_stepContext);
Expand Down