Skip to content

Commit

Permalink
drop sudo
Browse files Browse the repository at this point in the history
  • Loading branch information
Borda committed Jan 2, 2022
1 parent fc2a901 commit aa43ccb
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
2 changes: 1 addition & 1 deletion .azure/testing-template.yml
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ jobs:
displayName: 'Sanity check'
- bash: |
python actions/assistant.py prepare_env --config_file=configs/${{config}} > prepare_env.sh
python actions/assistant.py prepare_env --config_file=configs/${{config}} --drop-sudo > prepare_env.sh
cat prepare_env.sh
displayName: 'Create scripts'
Expand Down
10 changes: 6 additions & 4 deletions actions/assistant.py
Original file line number Diff line number Diff line change
Expand Up @@ -191,11 +191,13 @@ def list_env(config_file: str = "config.yaml") -> str:

@staticmethod
def before_commands(
config_file: str = "config.yaml", stage: str = "install", as_append: bool = False
config_file: str = "config.yaml", stage: str = "install", as_append: bool = False, drop_sudo: bool = False
) -> Union[str, List[str]]:
"""Parse commands for eventual custom execution before install or before testing."""
config = AssistantCLI._load_config(config_file)
cmds = config.get(f"before_{stage}", [])
if drop_sudo:
cmds = [cmd.replace("sudo ", "") for cmd in cmds]
if not as_append:
cmds = os.linesep.join(list(AssistantCLI._BASH_SCRIPT) + cmds)
return cmds
Expand All @@ -206,7 +208,7 @@ def _export_env(env: Dict[str, str]) -> List[str]:
return [f'export {name}="{val}"' for name, val in env.items()]

@staticmethod
def prepare_env(config_file: str = "config.yaml", path_root: str = _PATH_ROOT) -> str:
def prepare_env(config_file: str = "config.yaml", path_root: str = _PATH_ROOT, drop_sudo: bool = False) -> str:
"""Prepare the CI environment from given project config.
the workflow includes:
Expand All @@ -222,7 +224,7 @@ def prepare_env(config_file: str = "config.yaml", path_root: str = _PATH_ROOT) -
repo = config[AssistantCLI._FIELD_TARGET_REPO]

script += AssistantCLI._export_env(config.get("env", {}))
script += AssistantCLI.before_commands(config_file, stage="install", as_append=True)
script += AssistantCLI.before_commands(config_file, stage="install", as_append=True, drop_sudo=drop_sudo)

script += AssistantCLI._install_repo(repo, remove_dir=False)
repo_name, _ = os.path.splitext(os.path.basename(repo.get("HTTPS")))
Expand All @@ -248,7 +250,7 @@ def prepare_env(config_file: str = "config.yaml", path_root: str = _PATH_ROOT) -
for req in reqs:
script.append(AssistantCLI._install_pip(req))

script += AssistantCLI.before_commands(config_file, stage="test", as_append=True)
script += AssistantCLI.before_commands(config_file, stage="test", as_append=True, drop_sudo=drop_sudo)
return os.linesep.join(script)

@staticmethod
Expand Down

0 comments on commit aa43ccb

Please sign in to comment.