From 2244eb644170bad86e0a505143abbb1a9fa3f7c0 Mon Sep 17 00:00:00 2001 From: hordunlarmy Date: Thu, 29 Jan 2026 20:19:00 +0100 Subject: [PATCH] refactor: Streamline GitHub Actions input parsing --- action.yml | 33 ------------------------------- changelogs/2026-01-29_20-04-22.md | 2 +- changelogs/2026-01-29_20-18-38.md | 10 ++++++++++ src/config.py | 11 ++++++++++- src/env_manager.py | 10 +++++----- 5 files changed, 26 insertions(+), 40 deletions(-) create mode 100644 changelogs/2026-01-29_20-18-38.md diff --git a/action.yml b/action.yml index 16ad4b1..ed59b6b 100644 --- a/action.yml +++ b/action.yml @@ -169,36 +169,3 @@ 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-04-22.md b/changelogs/2026-01-29_20-04-22.md index 67bb950..c24409f 100644 --- a/changelogs/2026-01-29_20-04-22.md +++ b/changelogs/2026-01-29_20-04-22.md @@ -12,4 +12,4 @@ - **Documentation Updates**: The `README.md` and `docs/env-generation.md` have been updated to reflect the new environment variable management approach and the removal of the `env_blob` input. ### Removed -- The `env_blob` input from `action.yml` has been removed. Its functionality is now superseded by the enhanced capabilities of the `ENV` secret for passing raw environment variable blocks and templating. \ No newline at end of file +- The `env_blob` input from `action.yml` has been removed. Its functionality is now superseded by the enhanced capabilities of the `ENV` secret for passing raw environment variable blocks and templating. diff --git a/changelogs/2026-01-29_20-18-38.md b/changelogs/2026-01-29_20-18-38.md new file mode 100644 index 0000000..75c81a6 --- /dev/null +++ b/changelogs/2026-01-29_20-18-38.md @@ -0,0 +1,10 @@ +# Changelog + +## [Unreleased] + +### Changed +- **Improved Configuration Input Handling**: The action's core script now directly retrieves GitHub Action inputs using their standard `INPUT_` prefix (e.g., `inputs.git_url` is accessed as `INPUT_GIT_URL`). This refactoring simplifies the `action.yml` definition and makes the input parsing more direct and robust. +- **Internal Refactoring**: An internal variable (`env_blob_key` to `comp_env_key`) within the environment variable merging logic was renamed for improved clarity and maintainability. This change does not alter user-facing behavior. + +### Removed +- Explicit environment variable mappings for action inputs from `action.yml`. This removal is a direct consequence of the improved configuration input handling, as inputs are now read directly by the action's script. \ No newline at end of file diff --git a/src/config.py b/src/config.py index 34be74e..d030691 100644 --- a/src/config.py +++ b/src/config.py @@ -14,7 +14,16 @@ def get_bool_env(name, default="false"): return str(val).lower() == "true" def get_env(name, default=None): - return overrides.get(name) or os.getenv(name, default) + # 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 # Configuration from environment variables self.GIT_URL_ENV = get_env("GIT_URL", "").strip() diff --git a/src/env_manager.py b/src/env_manager.py index 3827f27..6b55309 100644 --- a/src/env_manager.py +++ b/src/env_manager.py @@ -351,15 +351,15 @@ def merge_env_vars_by_priority( merged[key] = v # D. Env Specific Blob (e.g. ENV_PROD_APP) - env_blob_key = f"ENV_{env_upper}_{file_base}" - if env_blob_key in all_env_vars: - parsed = parse_all_in_one_secret(all_env_vars[env_blob_key], config.ENV_FILES_FORMAT) + comp_env_key = f"ENV_{env_upper}_{file_base}" + if comp_env_key in all_env_vars: + parsed = parse_all_in_one_secret(all_env_vars[comp_env_key], config.ENV_FILES_FORMAT) if parsed: for pk, pv in parsed.items(): p_key = pk[len(f"{file_base}_") :] if pk.startswith(f"{file_base}_") else pk merged[p_key] = pv - elif all_env_vars[env_blob_key].strip(): - merged[file_base] = all_env_vars[env_blob_key] + elif all_env_vars[comp_env_key].strip(): + merged[file_base] = all_env_vars[comp_env_key] return merged