LucianoPAlmeida / variable-injector

Continuous Integration Tool for Swift Projects
MIT License
100 stars 20 forks source link

Injector don´t work in Xcode 11.3 #12

Closed jpipearagon closed 4 years ago

jpipearagon commented 4 years ago

i run the script in terminal

variable-injector --file ${SRCROOT}TestInjector/SwiftInjector/CI.swift --verbose

but it only prints

`======================================================================

FILE: CI.swift

======================================================================

// // CI.swift // TestInjector // // Created by Felipe Aragon on 22/04/20. // Copyright © 2020 Felipe Aragon. All rights reserved. //

import Foundation

struct CI { static var rappiPayCountry: String = "$(COUNTRY)" } ` and the set of the variable is not done

Screen Shot 2020-04-22 at 7 00 06 PM

I don't know what happens....

LucianoPAlmeida commented 4 years ago

Hey @jpipearagon :)

Humm, the variable to be replaced has to be set on your system via terminal or .bash_profile initialization(and optionally if you want are GUI or CLI processes to see those variables, make sure to set those variables on lauchctl and then restart Xcode process).

Those Xcode Environment Variable parameters you have set are passed to the Process (App) at launch time and not at compile time. Meaning that you launch the process with those arguments, that you are only going to have those values if you run the project with Xcode.

With that said to be able to run the variable injector on the terminal and see the replacement, you would have to set those variables in your system, not on Xcode.

jpipearagon commented 4 years ago

Ok thanks! I already worked on the terminal.

But in Xcode it doesn't work for me, Add Run script before compiling:

Screen Shot 2020-04-23 at 12 10 12 PM

and also add environment variable:

Screen Shot 2020-04-23 at 12 11 41 PM

my code looks like this:

struct CI { static var country: String = "$(RPPAY_COUNTRY)" }

when I run from xcode it works, but when I run the compile it looks like this:

Simulator Screen Shot - iPhone 8 - 2020-04-23 at 12 15 16

I need to add the variable somewhere to make it work in Xcode?

LucianoPAlmeida commented 4 years ago

Ahh, Xcode is what we call GUI process so to have environment variables available to the Xcode process, you have to make sure to set those variables on lauchctl and then restart Xcode process. You can see more details on this SO thread. I should probably highlight this on the article :)

jpipearagon commented 4 years ago

Yes, you are a "crack" :) I already worked with your reference. Yes, it would be good if you added the reference to the article.

Lastly I want to ask you the last question in bitrise it would only work by adding the environment variables or the variables have to be secret variables:

Screen Shot 2020-04-23 at 3 20 50 PM

something like that in bitrise.yml:

`envs:

LucianoPAlmeida commented 4 years ago

Lastly I want to ask you the last question in bitrise it would only work by adding the environment > variables or the variables have to be secret variables:

I think it doesn't make any difference, in this case, both secrets and env var are set as an environment variable when the build launches, the only difference is access level, secrets are encrypted and more constrained(they are only visible at the time of builds).

jpipearagon commented 4 years ago

thanks, I already made the changes, but it doesn't work in bitrise:

add the variable:

Screen Shot 2020-04-23 at 9 39 52 PM

but the script log:

Screen Shot 2020-04-23 at 9 40 42 PM

any ideas, can i check something?

LucianoPAlmeida commented 4 years ago

Are you using the lastest version? For XCode 11.3 try to downgrade to the version before that... that’s the only thing I can think now

jpipearagon commented 4 years ago

Awesome thanks, i just had to downgrade the version.