Created
March 30, 2025 16:06
-
-
Save saumalya75/132edce8f5f614a0b4e3e480cc8fad3f to your computer and use it in GitHub Desktop.
AWS Environment Detection
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| - name: Detect Environment and Set Environent Variables | |
| id: detect-env-and-set-env-vars | |
| run: | | |
| import os | |
| github_event_name = os.environ['GITHUB_EVENT_NAME'] | |
| if github_event_name == 'pull_request': | |
| target_branch_name = os.environ['GITHUB_BASE_REF'] | |
| elif github_event_name == 'push': | |
| target_branch_name = os.environ['GITHUB_REF_NAME'] | |
| print(f"Github Event Name: {github_event_name}") | |
| print(f"Target Branch Name: {target_branch_name}") | |
| with open(os.environ['GITHUB_OUTPUT'], 'a') as f: | |
| if target_branch_name.startswith('feature/'): | |
| target_env = 'dev' | |
| elif target_branch_name == 'develop': | |
| target_env = 'tst' | |
| elif target_branch_name == 'main': | |
| target_env = 'prd' | |
| if github_event_name == 'pull_request': | |
| action_type = 'validation' | |
| sts_role_arn_secret_var_name = f'MLOPS_PLTF_AWS_{target_env.upper()}_IAM_GITHUB_PR_ROLE' | |
| elif github_event_name == 'push': | |
| action_type = 'validation_and_deployment' | |
| sts_role_arn_secret_var_name = f'MLOPS_PLTF_AWS_{target_env.upper()}_IAM_GITHUB_PUSH_ROLE' | |
| f.write(f'action_type="{action_type}"\n') | |
| f.write(f'target_env={target_env}\n') | |
| f.write(f'sts_role_arn_secret_var_name={sts_role_arn_secret_var_name}\n') | |
| f.write(f'backend_config_file="../backend_configs/{target_env}.config"\n') | |
| f.write(f'env_specific_param_file="../env_specific_vars/{target_env}.tfvars"') | |
| print(f"Target Enrironment: {target_env}.") | |
| print(f"Action Type: {action_type}.") | |
| shell: python |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment