From f3e3a52e840d06eacf11c056af1ccdd5f698a06a Mon Sep 17 00:00:00 2001 From: Lukasz Sielski Date: Mon, 23 Sep 2024 09:48:37 +0200 Subject: [PATCH] extracct envs --- .github/workflows/actions/ado_tag/action.yml | 2 +- .github/workflows/deploy.yml | 2 +- scripts/envs_mapping.py | 109 +++++++++++++++++++ scripts/script.py | 5 +- 4 files changed, 114 insertions(+), 4 deletions(-) create mode 100644 scripts/envs_mapping.py diff --git a/.github/workflows/actions/ado_tag/action.yml b/.github/workflows/actions/ado_tag/action.yml index c18a259..0ca9778 100644 --- a/.github/workflows/actions/ado_tag/action.yml +++ b/.github/workflows/actions/ado_tag/action.yml @@ -20,7 +20,7 @@ runs: if: ${{ github.event_name == 'workflow_run' && github.event.workflow_run.event != 'workflow_dispatch' }} shell: bash run: | - python /home/runner/work/workflows_tests/workflows_tests/scripts/script.py --commit-sha ${{ github.event.workflow_run.head_sha }} --deploy_env ${{ inputs.deploy_env }} + python /home/runner/work/workflows_tests/workflows_tests/scripts/script.py --commit-sha ${{ github.event.workflow_run.head_sha }} --deploy-env ${{ inputs.deploy_env }} # - id: failing_step # continue-on-error: true # shell: bash diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index fcabad5..92d73a8 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -18,4 +18,4 @@ jobs: - uses: ./.github/workflows/actions/ado_tag with: azure-pat: ${{ secrets.ADO_PAT }} - deploy_env: DEV \ No newline at end of file + deploy_env: apollo-dev \ No newline at end of file diff --git a/scripts/envs_mapping.py b/scripts/envs_mapping.py new file mode 100644 index 0000000..8c4d692 --- /dev/null +++ b/scripts/envs_mapping.py @@ -0,0 +1,109 @@ +ENVS = { + "apollo-dev": { + "env": "dev", + "tag": "VNXT CL Dev" + }, + "apollo-dev-golden": { + "env": "dev", + "tag": "VNXT CL GOLDEN Dev" + }, + "apollo-dev-iot": { + "env": "dev", + "tag": "VNXT CL IOT Dev" + }, + "dev-us-east": { + "env": "dev", + "tag": "VNXT CL Dev" + }, + "dev-us-west": { + "env": "dev", + "tag": "VNXT CL Dev" + }, + "dev-iot-us-east": { + "env": "dev", + "tag": "VNXT CL IOT Dev" + }, + "dev-iot-us-west": { + "env": "dev", + "tag": "VNXT CL IOT Dev" + }, + "dev-golden-us-east": { + "env": "dev", + "tag": "VNXT CL GOLDEN Dev" + }, + "dev-golden-us-west": { + "env": "dev", + "tag": "VNXT CL GOLDEN Dev" + }, + "dev": { + "env": "dev", + "tag": "VNXT CL GOLDEN Dev" + }, + "dev-iot": { + "env": "dev", + "tag": "VNXT CL IOT Dev" + }, + "dev-golden": { + "env": "dev", + "tag": "VNXT CL GOLDEN Dev" + }, + "iot": { + "env": "dev", + "tag": "VNXT CL IOT Dev" + }, + "apollo-stage": { + "env": "stage", + "tag": "VNXT CL Stage" + }, + "apollo-stage-iot": { + "env": "stage", + "tag": "VNXT CL IOT Stage" + }, + "stage": { + "env": "stage", + "tag": "VNXT CL Stage" + }, + "stage-east": { + "env": "stage", + "tag": "VNXT CL Stage" + }, + "stage-west": { + "env": "stage", + "tag": "VNXT CL Stage" + }, + "stage-iot": { + "env": "stage", + "tag": "VNXT CL IOT Stage" + }, + "stage-ohio": { + "env": "stage", + "tag": "VNXT CL Stage" + }, + "stage-ohio": { + "env": "stage", + "tag": "VNXT CL Stage" + }, + "prod": { + "env": "prod", + "tag": "VNXT CL PROD" + }, + "prod-east": { + "env": "prod", + "tag": "VNXT CL PROD" + }, + "prod-west": { + "env": "prod", + "tag": "VNXT CL PROD" + }, + "apollo-prod": { + "env": "prod", + "tag": "VNXT CL PROD" + }, +} + +def get_tag(env: str) -> str: + try: + return ENVS[env]["tag"] + except KeyError: + print(f"Mapping for {env} to tagging value not found!") + raise Exception(f"Mapping for {env} to tagging value not found!") diff --git a/scripts/script.py b/scripts/script.py index fd3d096..9009d3c 100644 --- a/scripts/script.py +++ b/scripts/script.py @@ -1,17 +1,18 @@ import argparse from gh_cli import extract_data_by_pattern_from_pr_body, PrState from az_cli import tag_work_items +from envs_mapping import get_tag def parseArguments(): parser = argparse.ArgumentParser(description="Utility to tag ADO workitem with deployment environemnt", exit_on_error=False) parser.add_argument('--commit-sha', type=str, required=True, dest='commit_sha') - parser.add_argument('--deploy_env', type=str, required=True, dest='deploy_env') + parser.add_argument('--deploy-env', type=str, required=True, dest='deploy_env') return parser.parse_args() def main(): args = parseArguments() workItemsIds = extract_data_by_pattern_from_pr_body(args.commit_sha, PrState.MERGED, r'AB#(\d+)') - tag_work_items(workItemsIds, args.deploy_env) + tag_work_items(workItemsIds, get_tag(args.deploy_env)) if __name__ == '__main__': try: