Composite Actions: Support Env Flow#557
Conversation
…bles => but it doesn't 'stick'
src/Runner.Worker/action_yaml.json
Outdated
| "mapping": { | ||
| "properties": { | ||
| "using": "non-empty-string", | ||
| "env": "runs-env", |
There was a problem hiding this comment.
Since, container-runs-env's structure is used by both composite actions and container actions, I decided to change the name so that both types of runs can use it.
Moreover, to support this change, I made sure to look at all files that contained container-runs-env and replace it with `run-env'
…actions/runner into users/ethanchewy/compositeenv
|
Nevermind, in both the composite action and workflow steps, the environment contexts are evaluated correctly: https://github.com/ethanchewy/testing-actions/runs/795652488?check_suite_focus=true |
|
Ready for review! |
|
TODO: Remove only top level env token support. I need to remove most of my changes from the PR |
src/Runner.Worker/ActionManager.cs
Outdated
| public override bool HasPre => false; | ||
| public override bool HasPost => false; | ||
| public List<Pipelines.ActionStep> Steps { get; set; } | ||
| public MappingToken Environment { get; set; } |
src/Runner.Worker/ActionManager.cs
Outdated
| var compositeAction = definition.Data.Execution as CompositeActionExecutionData; | ||
| Trace.Info($"Load {compositeAction.Steps.Count} action steps."); | ||
| Trace.Verbose($"Details: {StringUtil.ConvertToJson(compositeAction.Steps)}"); | ||
| Trace.Info($"Load: {compositeAction.Environment} environment steps"); |
|
|
||
| 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); |
| } | ||
|
|
||
| var actionMapping = token.AssertMapping("action manifest root"); | ||
| var envComposite = default(MappingToken); |
| envData[env.Key] = env.Value; | ||
| } | ||
| // Overwrite with current env | ||
| foreach (var env in compositeEnvData) |
There was a problem hiding this comment.
Remove for now since we don't need to supprot outputs in action
| // 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 | ||
| var compositeEnvData = manifestManager.EvaluateCompositeActionEnvironment(ExecutionContext, Data.Environment, extraExpressionValues); |
There was a problem hiding this comment.
Remove Data.Environment
|
Removed all of my code that supported the Updated Description above to reflect this. |
|
lets make sure to test this: steps:
- uses: myorg/mycompositeaction@v1
env:
foo: this is foo
- run: printenv|sort # prints baz
# my composite action
steps:
- env:
bar: this is bar
run: |
echo '::set-env name=baz::this is baz'
printenv|sort # prints foo and bar
|
|
let's go with this behavior |
|
First test works as intended: Second test works as intended as well: As discussed with Ting and Eric, we will most likely have to refactor this in the future. See above comments by Eric for reference. Pushing changes soon. |
ericsciple
left a comment
There was a problem hiding this comment.
lgtm
we'll figure out how to simplify w/ nested composite steps runner (when we solve timeout)
* 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
This is branched off of my previous PR #549
In this PR, I build in support for environment variables for a Composite Action and its steps as described in the ADR: https://github.com/actions/runner/blob/users/ethanchewy/compositeADR/docs/adrs/0549-composite-run-steps.md#environment
action.ymlworkflow.ymlDemo: https://github.com/ethanchewy/testing-actions/runs/846467581?check_suite_focus=true
This is an experimental feature that can only be turned on via turning the feature flag on:
export TESTING_COMPOSITE_ACTIONS_ALPHA=1./run.sh