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
Add EnvironmentVariable struct as a RunAction's Arguments' parameter #3320
Conversation
There was a problem hiding this 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:
- The documentation can be updated to reflect the changes the environment type - those can be found here https://github.com/tuist/tuist/blob/main/projects/docs/docs/manifests/project.md
- We can possibly extend one of the fixtures (e.g. https://github.com/tuist/tuist/blob/main/projects/tuist/fixtures/ios_app_with_custom_scheme/App/Project.swift to leverage the new environment properties)
- In the changelog we can mark this change as Breaking to help clarify this is a breaking change in 2.0
@@ -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 = [ |
There was a problem hiding this comment.
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 :/
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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 :)
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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 } |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
let rawEnvironments: [EnvironmentVariable: Bool] = arguments.environmentVariables.reduce(into: [:]) { _, _ in } | ||
let rawEnvironmenstManifest = manifest.environmentVariables.reduce(into: [:]) { _, _ in } |
There was a problem hiding this comment.
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)
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added!
Could you try to rebase from |
Will do. |
972fe72
to
ce09149
Compare
It seems like it's getting worse :). I believe you mean to try to rebase my working branch onto the main branch @fortmarek. |
Hey @setoelkahfi π Could you change your target branch to What is more I believe that some of CI problems will be resolved once you rebase onto I will try to help you with others once CI re-run. |
Hey @laxmorek, |
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. |
Resolves #3257
Request for comments document (if applies):
Short description π
Checklist β
CHANGELOG.md
has been updated to reflect the changes. In case of a breaking change, it's been flagged as such.