XcodeGen icon indicating copy to clipboard operation
XcodeGen copied to clipboard

Source an environment within the preGenCommand or include .env.yml file and use variables through the script

Open dcarmo-tribalscale opened this issue 2 years ago • 2 comments

Hello all,

I was looking for a way to be able to source a local .env file from within the project.yml so that it doesn't need to be done on a per terminal/added to .bash_profile on the users machine. I was hoping the following would work but it doesn't.

.env

ENVIRONMENT=local

project.yml

...
options:
  # Command that runs before creating the xcproject
  preGenCommand: |
    source .env

...

targets:
  TARGET_NAME:
    scheme:
      environmentVariables:
        ENVIRONMENT: ${ENVIRONMENT}

Should this be possible? It seems like the preGenCommand runs in it's own container and doesn't run in the same container that is used for the environment.

I also looked at using a separate yml file for the environment but the variables aren't working either.

.env.yml

ENVIRONMENT: local

project.yml

...
include:
  - .env.yml

...

targets:
  TARGET_NAME:
    scheme:
      environmentVariables:
        ENVIRONMENT: ${ENVIRONMENT}

but the variable doesn't fill in either instance. Any thoughts on this would be greatly appreciated.

xcodegen --version
Version: 2.24.0

dcarmo-tribalscale avatar Sep 03 '21 15:09 dcarmo-tribalscale

Interesting, have you found a work around?

kkharji avatar Mar 10 '22 07:03 kkharji

@kkharji I have not found any way around this. I even tried just declaring the values at the top of the project.yml instead of using the include and it still doesn't pick up the variable.

e.g.

...

ENVIRONMENT: local

...

targets:
  TARGET_NAME:
    scheme:
      environmentVariables:
        ENVIRONMENT: ${ENVIRONMENT}

Still doesn't pick up and replace the ${ENVIRONMENT}

have you had any success with anything similar?

dcarmo-tribalscale avatar Jul 12 '22 18:07 dcarmo-tribalscale