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

enable steps to define environment variables #1918

Merged
merged 2 commits into from
Mar 4, 2022

Conversation

devigned
Copy link
Member

@devigned devigned commented Feb 19, 2022

What does this change

This change add the ability for steps to add environment variables to be added to the env when executing the command for a step.

This change is related to getporter/az-mixin#38. With this change, the mixin could add the user-agent env var to the command.

Notes for the reviewer

This is my first contribution here, so please let me know if I missed / misunderstood something.

Checklist

  • Did you write tests?
  • Did you write documentation?
  • Did you change porter.yaml or a storage document record? Update the corresponding schema file.
  • If this is your first pull request, please add your name to the bottom of our Contributors list. Thank you for making Porter better! 🙇‍♀️

Reviewer Checklist

  • Comment with /azp run test-porter-release if a magefile or build script was modified
  • Comment with /azp run porter-integration if it's a non-trivial PR

@devigned devigned force-pushed the env-step-vars branch 2 times, most recently from 575f4d0 to 120cf77 Compare February 19, 2022 16:03
@carolynvs carolynvs self-assigned this Feb 20, 2022
Copy link
Member

@carolynvs carolynvs left a comment

Choose a reason for hiding this comment

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

This looks great! Just a couple things need to be addressed first:

  • main is for our stable release, v0.38, and we are only merging high priority patches into that branch. Pull requests with new features should target release/v1.
  • This adds support for allowing mixins to set environment variables but at this point a user couldn't actually try out the feature yet. What we normally do is have the exec mixin implement new features added to the builder package, demonstrating how it works and vetting the implementation.
  • We also need documentation showing how it works, this is usually what the mixin authors will copy when they look at the exec mixin and incorporate the changes necessary to support a new feature (like setting env vars). Here's the exec mixin page that should be updated to include how to set an env var in its supported syntax section.

pkg/exec/builder/execute_test.go Outdated Show resolved Hide resolved
@devigned devigned changed the base branch from main to release/v1 March 3, 2022 14:41
Copy link
Member

@carolynvs carolynvs left a comment

Choose a reason for hiding this comment

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

Thanks for the fix!

_, err := ExecuteStep(c.Context, step)
require.NoError(t, err, "Execute Step failed")
containsEnv := strings.Contains(c.GetOutput(), "SOME_VAR_123=foo")
// use assert.True rather than assert.Contains so that the env vars are not all sent to the test output. There might
Copy link
Member

Choose a reason for hiding this comment

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

I hadn't considered that, good call! 👍

@@ -72,6 +72,13 @@
"type": "string"
}
},
"envs": {
Copy link
Member

Choose a reason for hiding this comment

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

A million brownie points for remembering to update the schema that VS Code uses to do autocomplete 💯

@carolynvs
Copy link
Member

You can fix the broken unit test by running mage UpdateTestFiles

@devigned
Copy link
Member Author

devigned commented Mar 3, 2022

You can fix the broken unit test by running mage UpdateTestFiles

Yep. Thank you for having the prompt in test failure output. That was super helpful.

@devigned
Copy link
Member Author

devigned commented Mar 3, 2022

/azp run porter-integration

@azure-pipelines
Copy link

Commenter does not have sufficient privileges for PR 1918 in repo getporter/porter

@carolynvs carolynvs merged commit 02aaca9 into getporter:release/v1 Mar 4, 2022
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