Skip to content

Commit

Permalink
adding error messages
Browse files Browse the repository at this point in the history
  • Loading branch information
AmyLGalles committed Dec 31, 2024
1 parent b19c121 commit 07c488f
Showing 1 changed file with 14 additions and 13 deletions.
27 changes: 14 additions & 13 deletions src/bitwarden_workflow_linter/rules/run_actionlint.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -26,37 +26,38 @@ 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
self.compatibility = [Workflow]
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)
Expand All @@ -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, ""

0 comments on commit 07c488f

Please sign in to comment.