Skip to content

Commit

Permalink
Add ability to dump test env vars to file
Browse files Browse the repository at this point in the history
  • Loading branch information
sfodagain committed Dec 12, 2023
1 parent 8091250 commit 5780dd1
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion builder/actions/setup_cross_ci_crt_environment.py
Original file line number Diff line number Diff line change
Expand Up @@ -423,8 +423,11 @@ def _common_setup(self, env):
pass

def run(self, env):
# A special environment variable indicating that we want to dump test environment variables to a specified file.
env_dump_file = env.shell.getenv("SETUP_CROSSS_CRT_TEST_ENVIRONMENT_DUMP_FILE")

# Bail if not running tests
if not env.project.needs_tests(env):
if not env.project.needs_tests(env) and not env_dump_file:
print('Tests not needed for project. Skipping setting test environment variables')
return

Expand Down Expand Up @@ -475,3 +478,10 @@ def run(self, env):
print(f"Detected whether on Codebuild: {self.is_codebuild}")

self._common_setup(env)

# Create a temporary file with all environment variables.
# Useful for running tests locally.
if env_dump_file:
with open(file=env_dump_file, mode='w+') as file:
for env_name, env_value in env.project.config['test_env'].items():
file.write(f"export {env_name}={env_value}\n")

0 comments on commit 5780dd1

Please sign in to comment.