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

Conversation

ethanchewy
Copy link
Contributor

@ethanchewy ethanchewy commented Jun 18, 2020

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.yml

runs:
    using: "composite"
    steps: 
      - run: echo Composite Action Server ${{ env.SERVER }}
      - run: echo Server changed to ${{ env.SERVER }}

workflow.yml

jobs:
  build:
    runs-on: self-hosted
    steps:
    - uses: actions/checkout@v2
    - id: composite1
      uses: ethanchewy/test-composite@env
      with:
        your_name: "Octocat"
      env:
        NAME3: testasdfasdfads
    - name: test outputs
      run: echo Server: ${{ env.SERVER }}

Demo: 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

@ethanchewy ethanchewy changed the base branch from master to users/ethanchewy/compositetest2 June 18, 2020 20:05
@@ -88,6 +88,7 @@
"mapping": {
"properties": {
"using": "non-empty-string",
"env": "runs-env",
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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'

@ethanchewy
Copy link
Contributor Author

ethanchewy commented Jun 22, 2020

TODO: We need to add context so that env variables are evaluated when Runner jobs are printed (ex: Run echo Name3 changed to $NAME3 should instead be Run echo Name3 changed to fdasdfadsf

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

@ethanchewy
Copy link
Contributor Author

Ready for review!

@ethanchewy
Copy link
Contributor Author

ethanchewy commented Jun 30, 2020

TODO: Remove only top level env token support.

I need to remove most of my changes from the PR

@@ -1285,6 +1287,7 @@ public sealed class CompositeActionExecutionData : ActionExecutionData
public override bool HasPre => false;
public override bool HasPost => false;
public List<Pipelines.ActionStep> Steps { get; set; }
public MappingToken Environment { get; set; }
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove

@@ -400,6 +400,8 @@ public Definition LoadAction(IExecutionContext executionContext, Pipelines.Actio
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");
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove these 2 lines

@@ -27,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);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove

@@ -74,6 +75,8 @@ public ActionDefinitionData Load(IExecutionContext executionContext, string mani
}

var actionMapping = token.AssertMapping("action manifest root");
var envComposite = default(MappingToken);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove

envData[env.Key] = env.Value;
}
// Overwrite with current env
foreach (var env in compositeEnvData)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove Data.Environment

@ethanchewy
Copy link
Contributor Author

Removed all of my code that supported the env token in the composite action.

Updated Description above to reflect this.

@ethanchewy ethanchewy requested a review from ericsciple July 7, 2020 19:25
@ericsciple
Copy link
Collaborator

ericsciple commented Jul 7, 2020

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

@ericsciple
Copy link
Collaborator

let's go with this behavior

steps:
  - run: echo ::set-env name=foo::this is foo 1
  - uses: myorg/mycompositeaction@v1
  
  env:

      foo: this is foo 2

# my composite action
steps:
  - printenv|sort           # should get foo 2 (more specific)
  - run: echo ::set-env name=foo::this is foo 3
  - printenv|sort           # will get foo 2 also... let's mark it as a bug and figure out how to solve w/ nested step runner

@ethanchewy
Copy link
Contributor Author

First test works as intended:
https://github.com/ethanchewy/testing-actions/runs/847543901?check_suite_focus=true

Second test works as intended as well:
https://github.com/ethanchewy/testing-actions/runs/847558293?check_suite_focus=true

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.

Copy link
Collaborator

@ericsciple ericsciple left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

we'll figure out how to simplify w/ nested composite steps runner (when we solve timeout)

@ethanchewy ethanchewy changed the base branch from users/ethanchewy/compositetest2 to master July 7, 2020 22:45
@ethanchewy ethanchewy merged commit d42c9da into master Jul 8, 2020
AdamOlech pushed a commit to antmicro/runner that referenced this pull request Jan 28, 2021
* 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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants