From 07c488f9b76551604888c1a8e7c5e616fce20c7b Mon Sep 17 00:00:00 2001 From: Amy Galles <9685081+AmyLGalles@users.noreply.github.com> Date: Tue, 31 Dec 2024 08:45:31 -0800 Subject: [PATCH] adding error messages --- .../rules/run_actionlint.py | 27 ++++++++++--------- 1 file changed, 14 insertions(+), 13 deletions(-) diff --git a/src/bitwarden_workflow_linter/rules/run_actionlint.py b/src/bitwarden_workflow_linter/rules/run_actionlint.py index 5ed5a9e..99cafe1 100644 --- a/src/bitwarden_workflow_linter/rules/run_actionlint.py +++ b/src/bitwarden_workflow_linter/rules/run_actionlint.py @@ -10,7 +10,7 @@ from ..utils import LintLevels, Settings -def check_actionlint(): +def check_actionlint() -> Tuple[bool, str]: """Check if the actionlint is in the system's PATH. If actionlint is not installed, detects OS platform @@ -26,29 +26,29 @@ def check_actionlint(): if Platform.startswith('Linux'): try: subprocess.run(['sudo', 'apt-get', 'install', '-y', 'actionlint'], check=True) - return True + return [True, ""] except subprocess.CalledProcessError: - print(f"Failed to install Actionlint. Please check your package manager or manually install it.") - return False + error = "Failed to install Actionlint. Please check your package manager or manually install it." + return [False, error] elif Platform == 'Darwin': try: subprocess.run(['brew', 'install', 'actionlint'], check=True) - return True + return [True, ""] except subprocess.CalledProcessError: - print(f"Failed to install Actionlint. Please check your Homebrew installation or manually install it.") - return False + error = "Failed to install Actionlint. Please check your Homebrew installation or manually install it." + return [False, error] elif Platform == 'Win32': try: subprocess.run(['choco', 'install', 'actionlint', '-y'], check=True) - return True + return [True, ""] except subprocess.CalledProcessError: - print(f"Failed to install Actionlint. Please check your Chocolatey installation or manually install it.") - return False + error = "Failed to install Actionlint. Please check your Chocolatey installation or manually install it." + return [False, error] class RunActionlint(Rule): """Rule to run actionlint as part of workflow linter V2. """ - + def __init__(self, settings: Optional[Settings] = None) -> None: self.message = "Actionlint must pass without errors" self.on_fail = LintLevels.WARNING @@ -56,7 +56,8 @@ def __init__(self, settings: Optional[Settings] = None) -> None: self.settings = settings def fn(self, obj: Job) -> Tuple[bool, str]: - if check_actionlint(): + installed, install_error = check_actionlint() + if installed: result = subprocess.run(["actionlint"], capture_output=True, text=True) if result.returncode == 1: print(result.stdout) @@ -65,5 +66,5 @@ def fn(self, obj: Job) -> Tuple[bool, str]: return False, result.stderr return True, "" else: - print(f"Actionlint could not be installed.") + print(install_error) return False, ""