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

Pass system environment variables when executing custom command #4611

Merged
merged 7 commits into from
Jul 22, 2022

Conversation

woohyunjin06
Copy link
Contributor

@woohyunjin06 woohyunjin06 commented Jul 14, 2022

Short description 📝

This PR allows sub process (e.g. Plugin) to have access to system environment variables

How to test the changes locally 🧐

Run custom command that require environment variables, run unit test

Checklist ✅

  • The code architecture and patterns are consistent with the rest of the codebase.
  • The changes have been tested following the documented guidelines.
  • The PR includes the label changelog:added, changelog:fixed, or changelog:changed, whenever it should be included in the “Added”, “Fixed” or “Changed” section of the CHANGELOG. Note: when included in the CHANGELOG, the title of the PR will be used as entry, please make sure it is clear and suitable.
  • In case the PR introduces changes that affect users, the documentation has been updated.
  • In case the PR introduces changes that affect how the cache artifact is generated starting from the TuistGraph.Target, the Constants.cacheVersion has been updated.

@@ -9,12 +9,21 @@ public final class MockSystem: Systeming {

// swiftlint:disable:next large_tuple
public var stubs: [String: (stderror: String?, stdout: String?, exitstatus: Int?)] = [:]
public var requiredEnvironmentVariables: [String: [String: String]] = [:]
Copy link
Member

Choose a reason for hiding this comment

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

I'm not sure about writing so much code to MockSystem for testing a very specific thing. I would rather use E2E tests for this:

  • Define a new step here for adding a custom env variable
  • Update or create a new plugin inside this example repository. A new release will need to be made (I can do this for you if you ping me)
  • Invoke that command here - make sure it would fail if the env variable was not passed.

Given the E2E flow for plugins is not as straightforward as I want it to be, I am personally ok for now to merge this without any additional tests. Or if you could simplify the unit test without introducing too much code in MockSystem. I will leave that up to you, let me know 🙂

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks @fortmarek !

As you suggested, I updated create-file plugin in this repository to retrieve content string from the environment variable. And implemented E2E test cases.

My ExampleTuistPlugin implementation is currently in my forked repository and if there is no problem with this change, I will create PR in tuist organization's repository

Copy link
Member

Choose a reason for hiding this comment

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

This is great! Please, create a PR against the tuist's ExampleTuistPlugin repo and I'll do a review there 👍

@danieleformichelli
Copy link
Collaborator

@woohyunjin06 I have updated the PR to use the new plugin, could you please have a look that everything is ok?

@woohyunjin06
Copy link
Contributor Author

Thanks @danyf90

The test scenario currently written cannot be completed successfully without tuist-create-file executable file.
So I changed scenario to execute create-file task in the project directory.

I don't know the exact intension of executing create-file task in the current directory, so could you check if it is ok?

@danieleformichelli danieleformichelli merged commit 3675383 into tuist:main Jul 22, 2022
@danieleformichelli danieleformichelli added the changelog:fixed PR will be listed in the Fixed section of CHANGELOG label Jul 30, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
changelog:fixed PR will be listed in the Fixed section of CHANGELOG
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants