From f73d499a5746b893609b1c89c997aa70559a4cb0 Mon Sep 17 00:00:00 2001 From: hordunlarmy Date: Thu, 29 Jan 2026 21:00:29 +0100 Subject: [PATCH] refactor(config): Streamline environment variable retrieval --- action.yml | 33 + changelogs/2026-01-29_20-26-44.md | 2 +- coverage.xml | 1176 ++++++++--------- src/config.py | 11 +- .../file_path_secret/.env.database | 2 +- .../file_path_secret/.env.redis | 2 +- .../generated_envs/file_path_secret/.env.s3 | 2 +- 7 files changed, 623 insertions(+), 605 deletions(-) diff --git a/action.yml b/action.yml index ed59b6b..16ad4b1 100644 --- a/action.yml +++ b/action.yml @@ -169,3 +169,36 @@ runs: run: | cd ${{ github.action_path }} poetry run python main.py + env: + GIT_URL: ${{ inputs.git_url }} + GIT_AUTH_METHOD: ${{ inputs.git_auth_method }} + GIT_TOKEN: ${{ inputs.git_token }} + GIT_USER: ${{ inputs.git_user }} + GITHUB_REPOSITORY: ${{ github.repository }} + GITHUB_ACTOR: ${{ github.actor }} + GIT_SSH_KEY: ${{ inputs.git_ssh_key }} + DEPLOYMENT_TYPE: ${{ inputs.deployment_type }} + ENVIRONMENT: ${{ inputs.environment }} + REMOTE_USER: ${{ inputs.remote_user }} + REMOTE_HOST: ${{ inputs.remote_host }} + REMOTE_DIR: ${{ inputs.remote_dir }} + SSH_KEY: ${{ inputs.ssh_key }} + REMOTE_PASSWORD: ${{ inputs.remote_password }} + REGISTRY_TYPE: ${{ inputs.registry_type }} + REGISTRY_USERNAME: ${{ inputs.registry_username }} + REGISTRY_PASSWORD: ${{ inputs.registry_password }} + AWS_REGION: ${{ inputs.aws_region }} + AWS_ACCOUNT_ID: ${{ inputs.aws_account_id }} + PROFILE: ${{ inputs.profile }} + DEPLOY_COMMAND: ${{ inputs.deploy_command }} + K8S_MANIFEST_PATH: ${{ inputs.k8s_manifest_path }} + K8S_NAMESPACE: ${{ inputs.k8s_namespace }} + USE_SUDO: ${{ inputs.use_sudo }} + ENV_FILES_GENERATE: ${{ inputs.env_files_generate }} + ENV_FILES_STRUCTURE: ${{ inputs.env_files_structure }} + ENV_FILES_PATH: ${{ inputs.env_files_path }} + ENV_FILES_PATTERNS: ${{ inputs.env_files_patterns }} + ENV_FILES_CREATE_ROOT: ${{ inputs.env_files_create_root }} + ENV_FILES_FORMAT: ${{ inputs.env_files_format }} + COPY_ARTIFACTS: ${{ inputs.copy_artifacts }} + GITHUB_WORKSPACE: ${{ github.workspace }} diff --git a/changelogs/2026-01-29_20-26-44.md b/changelogs/2026-01-29_20-26-44.md index ae2518e..f875f6e 100644 --- a/changelogs/2026-01-29_20-26-44.md +++ b/changelogs/2026-01-29_20-26-44.md @@ -3,4 +3,4 @@ ## [Unreleased] ### Changed -- Improved the execution of `sudo` commands for remote connections. Commands are now wrapped in `bash -c` to ensure `sudo` correctly applies to the entire command, including pipelines and chained commands, preventing partial execution failures. \ No newline at end of file +- Improved the execution of `sudo` commands for remote connections. Commands are now wrapped in `bash -c` to ensure `sudo` correctly applies to the entire command, including pipelines and chained commands, preventing partial execution failures. diff --git a/coverage.xml b/coverage.xml index 8781109..a599b74 100644 --- a/coverage.xml +++ b/coverage.xml @@ -1,12 +1,12 @@ - + /workspace/personal/MetalDeploy/src - + @@ -14,7 +14,7 @@ - + @@ -27,69 +27,63 @@ - - - - - - - + + + + + + + + - - - + + - - - - - + + + + - - - + + + + + - - - - - - - - - - - - + + + + + - - - + - - - - - - + + + + + - - - - + + + + + + + - + @@ -97,79 +91,79 @@ - - - - - + + + + + - - - - - - + + + + + + - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + - - - - - - - - - - - + + + + + + + + + + + - - - - - - + + + + + + - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + - + @@ -181,279 +175,279 @@ - - - - - - - + + + + + + + - - - - - - - + + + + + + + - - - - - + + + + + - - - - - - - + + + + + + + - - - - - + + + + + - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + - - - - - - - - - - - - - + + + + + + + + + + + + + - - - - - - - - + + + + + + + + - + - - - - - - - - - - - - - - + + + + + + + + + + + + + + - - - - - - - - - - + + + + + + + + + + - - - - - + + + + + - + - - - - - - - - - - - + + + + + + + + + + + - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + - - - + + + - - - - - - + + + + + + - - - - - - - + + + + + + + - - - - - - - - - - - + + + + + + + + + + + - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + - - - - - - - - - - - - + + + + + + + + + + + + - + - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + - + - - - - + + + + - + - - - - - + + + + + - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + @@ -461,7 +455,7 @@ - + @@ -471,58 +465,58 @@ - - + + - - - - - + + + + + - - - + + + - - - - - - - - - - - + + + + + + + + + + + - - + + - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + @@ -532,11 +526,11 @@ - - - - - + + + + + @@ -544,18 +538,18 @@ - - - - - - - - - + + + + + + + + + - + @@ -571,96 +565,96 @@ - - - - - - + + + + + + - - - - - - - - + + + + + + + + - - - - - - + + + + + + - - - - - - - - - + + + + + + + + + - + - - - - - - - - - - + + + + + + + + + + - - - + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -668,73 +662,73 @@ - + - + - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + - + - + - + - - - - - - - - + + + + + + + + - + - + @@ -753,17 +747,17 @@ - - - - - + + + + + - + - + @@ -798,67 +792,67 @@ - - + + - - - - - - + + + + + + - - - - - - + + + + + + - - - + + + - - - - - - - + + + + + + + - + - + - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + @@ -867,50 +861,50 @@ - + - - - - - - + + + + + + - - - - + + + + - + - - - - - - - + + + + + + + - - - - - - - + + + + + + + - - - + + + - - - + + + diff --git a/src/config.py b/src/config.py index d030691..34be74e 100644 --- a/src/config.py +++ b/src/config.py @@ -14,16 +14,7 @@ def get_bool_env(name, default="false"): return str(val).lower() == "true" def get_env(name, default=None): - # 1. Check overrides - val = overrides.get(name) - if val is not None: - return val - # 2. Check direct environment - val = os.getenv(name) - if val is not None: - return val - # 3. Check GitHub Action Input (INPUT_NAME) - return os.getenv(f"INPUT_{name.upper()}") or default + return overrides.get(name) or os.getenv(name, default) # Configuration from environment variables self.GIT_URL_ENV = get_env("GIT_URL", "").strip() diff --git a/tests/integration/generated_envs/file_path_secret/.env.database b/tests/integration/generated_envs/file_path_secret/.env.database index 6e4aa32..0e9ff08 100644 --- a/tests/integration/generated_envs/file_path_secret/.env.database +++ b/tests/integration/generated_envs/file_path_secret/.env.database @@ -1,4 +1,4 @@ -/tmp/pytest-of-horduntech/pytest-67/test_env_exhaustive_file_path_0/jenkins_secret.json +/tmp/pytest-of-horduntech/pytest-78/test_env_exhaustive_file_path_0/jenkins_secret.json FILE_DB_USER=file-user-admin FILE_DB_PASS=file-secret-pass \ No newline at end of file diff --git a/tests/integration/generated_envs/file_path_secret/.env.redis b/tests/integration/generated_envs/file_path_secret/.env.redis index 0acd49e..98065c6 100644 --- a/tests/integration/generated_envs/file_path_secret/.env.redis +++ b/tests/integration/generated_envs/file_path_secret/.env.redis @@ -1,4 +1,4 @@ -/tmp/pytest-of-horduntech/pytest-67/test_env_exhaustive_file_path_0/jenkins_secret.yaml +/tmp/pytest-of-horduntech/pytest-78/test_env_exhaustive_file_path_0/jenkins_secret.yaml HOST=yaml-file-host PORT=6379 \ No newline at end of file diff --git a/tests/integration/generated_envs/file_path_secret/.env.s3 b/tests/integration/generated_envs/file_path_secret/.env.s3 index fee40f8..7822a4d 100644 --- a/tests/integration/generated_envs/file_path_secret/.env.s3 +++ b/tests/integration/generated_envs/file_path_secret/.env.s3 @@ -1,4 +1,4 @@ -/tmp/pytest-of-horduntech/pytest-67/test_env_exhaustive_file_path_0/jenkins_secret.env +/tmp/pytest-of-horduntech/pytest-78/test_env_exhaustive_file_path_0/jenkins_secret.env BUCKET=file-bucket REGION=us-east-1 \ No newline at end of file