Skip to content

Commit

Permalink
feat(action): Implement correct handling of repo root and action file…
Browse files Browse the repository at this point in the history
…s path
  • Loading branch information
Noahnc committed Nov 29, 2023
1 parent 46a50ba commit 1902b4e
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 8 deletions.
5 changes: 5 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ runs:
run: |
python -m pip install --upgrade pip
pip install -r requirements.txt
working-directory: ${{ env.GITHUB_ACTION_PATH }}
shell: bash

- name: Configure git
Expand All @@ -81,7 +82,9 @@ runs:
git config --global user.email "${{ inputs.git_email }}"
- name: Run InfraPatch Action

shell: bash
working-directory: ${{ env.GITHUB_ACTION_PATH }}
run: |
module="infrapatch.action"
arguments=()
Expand All @@ -99,6 +102,8 @@ runs:
WORKING_DIRECTORY_RELATIVE: ${{ inputs.working_directory_relative }}
ENABLED_PROVIDERS: ${{ inputs.enabled_providers }}

REPOSITORY_ROOT: ${{ github.workspace }}

# Calculated config from other steps
HEAD_BRANCH: ${{ steps.branch.outputs.head }}
TARGET_BRANCH: ${{ steps.branch.outputs.target }}
Expand Down
2 changes: 1 addition & 1 deletion infrapatch/action/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ def main(debug: bool):
raise Exception("No providers enabled. Please enable at least one provider.")

builder = ProviderHandlerBuilder(config.working_directory)
builder.with_git_integration()
builder.with_git_integration(config.repository_root)
if "terraform_modules" in config.enabled_providers or "terraform_providers" in config.enabled_providers:
builder.add_terraform_registry_configuration(config.default_registry_domain, config.terraform_registry_secrets)
if "terraform_modules" in config.enabled_providers:
Expand Down
2 changes: 1 addition & 1 deletion infrapatch/action/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ def __init__(self) -> None:
self.head_branch = _get_value_from_env("HEAD_BRANCH")
self.target_branch = _get_value_from_env("TARGET_BRANCH")
self.repository_name = _get_value_from_env("REPOSITORY_NAME")
self.repository_root = Path(os.getcwd())
self.repository_root = Path(_get_value_from_env("REPOSITORY_ROOT"))
self.enabled_providers = _get_value_from_env("ENABLED_PROVIDERS", default="").split(",")
self.working_directory = self.repository_root.joinpath(_get_value_from_env("WORKING_DIRECTORY_RELATIVE", default=""))
self.default_registry_domain = _get_value_from_env("DEFAULT_REGISTRY_DOMAIN")
Expand Down
10 changes: 4 additions & 6 deletions infrapatch/core/provider_handler_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ def __init__(self, working_directory: Path) -> None:
self.providers = []
self.working_directory = working_directory
self.registry_handler = None
self.git_integration = False
self.git_repo = None
pass

def add_terraform_registry_configuration(self, default_registry_domain: str, credentials: dict[str, str]) -> Self:
Expand All @@ -45,16 +45,14 @@ def with_terraform_provider_provider(self) -> Self:
self.providers.append(tf_module_provider)
return self

def with_git_integration(self) -> Self:
def with_git_integration(self, git_working_directory: Path) -> Self:
log.debug("Enabling Git integration.")
self.git_integration = True
self.git_repo = Repo(git_working_directory)
return self

def build(self) -> ProviderHandler:
if len(self.providers) == 0:
raise Exception("No providers added to ProviderHandlerBuilder.")
statistics_file = self.working_directory.joinpath(f"{cs.APP_NAME}_Statistics.json")
git_repo = None
if self.git_integration:
git_repo = Repo(self.working_directory)
return ProviderHandler(providers=self.providers, console=Console(width=const.CLI_WIDTH), statistics_file=statistics_file, repo=git_repo)
return ProviderHandler(providers=self.providers, console=Console(width=const.CLI_WIDTH), statistics_file=statistics_file, repo=self.git_repo)

0 comments on commit 1902b4e

Please sign in to comment.