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

Add EnvironmentVariable struct as a RunAction's Arguments' parameter #3320

Conversation

setoelkahfi
Copy link
Contributor

@setoelkahfi setoelkahfi commented Aug 22, 2021

Resolves #3257
Request for comments document (if applies):

Short description πŸ“

  • Add the ability to enable or disable environment variables that are passed when running a scheme.

Checklist βœ…

  • The code architecture and patterns are consistent with the rest of the codebase.
  • The changes have been tested following the documented guidelines.
  • The CHANGELOG.md has been updated to reflect the changes. In case of a breaking change, it's been flagged as such.
  • In case the PR introduces changes that affect users, the documentation has been updated.

Copy link
Collaborator

@kwridan kwridan left a comment

Choose a reason for hiding this comment

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

Nice work @setoelkahfi! thanks for submitting this.

A few small tidbits are still needed:

@@ -85,7 +85,6 @@ public final class TargetContentHasher: TargetContentHashing {
let coreDataModelHash = try coreDataModelsContentHasher.hash(coreDataModels: graphTarget.target.coreDataModels)
let targetActionsHash = try targetActionsContentHasher.hash(targetActions: graphTarget.target.actions)
let dependenciesHash = try dependenciesContentHasher.hash(graphTarget: graphTarget, hashedTargets: &hashedTargets)
let environmentHash = try contentHasher.hash(graphTarget.target.environment)
var stringsToHash = [
Copy link
Collaborator

Choose a reason for hiding this comment

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

is this intended? To maintain the previous behaviour we'd need to continue hashing the environment values :/

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No.
I was just trying to make it build successfully. I guess try contentHasher.hash(graphTarget.target.environmentVariables.map { $0.value }) should be fine?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Let's make EnvironmentVariable conform to hashable so it is synthesized by the compiler and we do not need the map here :)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Let's make EnvironmentVariable conform to hashable so it is synthesized by the compiler and we do not need the map here :)

Oh yeah, I missed that one.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hey @adellibovi,
I don't think I understand this. So, I got the graphTarget.target.environmentVariables.hashValue by conforming the EnvironmentVariable to the Hashable protocol. Where should I put it?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Oops, you are right @setoelkahfi, that is not needed, got confused by Swift hash vs our Content hash.
Though it seems to me we would need to hash all three properties instead of just name, as changing one of those should invalidate the cache, @kwridan can you confirm?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@adellibovi What I can think of right now is to convert the environment variable array into a single string and then hash it with the content hasher.

XCScheme.EnvironmentVariable(variable: key, value: value, enabled: true)
private func environmentVariables(_ environments: [EnvironmentVariable]) -> [XCScheme.EnvironmentVariable] {
environments.map { environment in
XCScheme.EnvironmentVariable(variable: environment.key, value: environment.value, enabled: environment.isEnabled)
}.sorted { $0.variable < $1.variable }
Copy link
Collaborator

Choose a reason for hiding this comment

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

I suspect we no longer need to sort as we'll now have a stable order as we'll persist the user defined order.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I removed calling the sorted function.

Comment on lines 173 to 174
let rawEnvironments: [EnvironmentVariable: Bool] = arguments.environmentVariables.reduce(into: [:]) { _, _ in }
let rawEnvironmenstManifest = manifest.environmentVariables.reduce(into: [:]) { _, _ in }
Copy link
Collaborator

Choose a reason for hiding this comment

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

The goal here is to compare the raw values of the manifest types and the model types, this can be achieved in any number of ways. We can do something along the lines of:

XCTAssertEqual(arguments.environmentVariables.count, manifest.environmentVariables.count)
zip(arguments.environmentVariables, manifest.environmentVariables).forEach { model, manifest in
   XCTAssertEqual(model.isEnabled, manifest.isEnabled)
   XCTAssertEqual(model.key, manifest.key)
   XCTAssertEqual(model.value, manifest.value)
}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added!

@setoelkahfi setoelkahfi marked this pull request as ready for review August 26, 2021 21:27
@fortmarek
Copy link
Member

Could you try to rebase from main to fix the CI? πŸ™

@setoelkahfi
Copy link
Contributor Author

Could you try to rebase from main to fix the CI? πŸ™

Will do.

@setoelkahfi setoelkahfi force-pushed the feature/add-environment-variable-struct branch from 972fe72 to ce09149 Compare August 29, 2021 18:48
@setoelkahfi
Copy link
Contributor Author

It seems like it's getting worse :). I believe you mean to try to rebase my working branch onto the main branch @fortmarek.

@setoelkahfi setoelkahfi changed the title Add EnvironmentVariable struct Add EnvironmentVariable struct as a RunAction's Arguments' parameter Aug 29, 2021
@laxmorek
Copy link
Collaborator

laxmorek commented Aug 30, 2021

Hey @setoelkahfi πŸ‘‹

Could you change your target branch to main? We've decided to continue 2.0 development on main.

What is more I believe that some of CI problems will be resolved once you rebase onto main and change target branch.

I will try to help you with others once CI re-run.

@setoelkahfi setoelkahfi changed the base branch from release-2.0 to main August 30, 2021 06:45
@setoelkahfi
Copy link
Contributor Author

setoelkahfi commented Aug 30, 2021

Hey @setoelkahfi πŸ‘‹

Could you change your target branch to main? We've decided to continue 2.0 development on main.

What is more I believe that some of CI problems will be resolved once you rebase onto main and change target branch.

I will try to help you with others once CI re-run.

Hey @laxmorek,
I changed the target branch to main.

@laxmorek laxmorek changed the base branch from main to release-2.0 August 30, 2021 07:29
@laxmorek
Copy link
Collaborator

I'm very sorry, we reconsider our approach and decided to keep release-2.0 branch live.

From Slack:
Zrzut ekranu 2021-08-30 o 09 30 52

We consider your branch as breaking so Ive update target branch one more time. It should be release-2.0 (like you did before).

Again, sorry for being misleading.

@laxmorek laxmorek mentioned this pull request Aug 30, 2021
4 tasks
@setoelkahfi
Copy link
Contributor Author

I'm very sorry, we reconsider our approach and decided to keep release-2.0 branch live.

From Slack:
Zrzut ekranu 2021-08-30 o 09 30 52

We consider your branch as breaking so Ive update target branch one more time. It should be release-2.0 (like you did before).

Again, sorry for being misleading.

No worries. Thanks for clarifying.

@github-actions
Copy link
Contributor

github-actions bot commented Oct 2, 2021

This PR has been marked as stale because it's been opened for more than 30 days. If no action is taken, it'll be closed in 5 days.

@pepicrft pepicrft deleted the branch tuist:release-2.0 October 2, 2021 10:23
@pepicrft pepicrft closed this Oct 2, 2021
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.

None yet

7 participants