Skip to content

Commit

Permalink
works but wonky
Browse files Browse the repository at this point in the history
  • Loading branch information
AmyLGalles committed Jan 7, 2025
1 parent 3ae7b8e commit dd6e1ef
Showing 1 changed file with 46 additions and 40 deletions.
86 changes: 46 additions & 40 deletions src/bitwarden_workflow_linter/rules/run_actionlint.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,34 @@
import subprocess
import platform
import urllib.request
import os

from ..rule import Rule
from ..models.workflow import Workflow
from ..utils import LintLevels, Settings

def check_actionlint():
"""Check if the actionlint is in the system's PATH.
def install_actionlint_package():
"""If actionlint is not installed, detects OS platform
and installs actionlint"""

def install_actionlint_source():
"""Install Actionlint Binary from provided script"""
url = "https://raw.githubusercontent.com/rhysd/actionlint/main/scripts/download-actionlint.bash"
version = '1.6.17'
request = urllib.request.urlopen(url)
with open('download-actionlint.bash', 'wb+') as fp:
fp.write(request.read())
try:
subprocess.run(
['bash', 'download-actionlint.bash', version], check=True)
return True, "", os.getcwd()
except (FileNotFoundError, subprocess.CalledProcessError):
error = "Failed to install Actionlint. \
Please check your package manager or manually install it."
return False, error, ""

If actionlint is not installed, detects OS platform
and installs actionlint
"""
def check_actionlint():
"""Check if the actionlint is in the system's PATH."""
platform_system = platform.system()
error = f"An unknown error occurred on platform {platform_system}"
try:
Expand All @@ -24,7 +41,7 @@ def check_actionlint():
stderr=subprocess.PIPE,
check=True,
)
return True, ""
return True, "", ""
except subprocess.CalledProcessError:
return (
False,
Expand All @@ -33,44 +50,25 @@ def check_actionlint():
)
except FileNotFoundError:
if platform_system.startswith("Linux"):
url = "https://raw.githubusercontent.com/rhysd/actionlint/main/scripts/download-actionlint.bash"
version = '1.6.17'
request = urllib.request.urlopen(url)
try:
with open('download-actionlint.bash', 'wb+') as fp:
fp.write(request.read())
print("got to with open")
result = subprocess.run(
['install-actionlint.bash', version], check=True, capture_output=True,
text=True,)
print('******')
print(result.stdout)
print('******')
return True, ""
except (FileNotFoundError, subprocess.CalledProcessError):
print('******')
print(result.stdout)
print('******')
error = "Failed to install Actionlint1. \
Please check your package manager or manually install it."
return False, error
return install_actionlint_source()
elif platform_system == "Darwin":
try:
subprocess.run(["brew", "install", "actionlint"], check=True)
return True, ""
except (FileNotFoundError, subprocess.CalledProcessError):
error = "Failed to install Actionlint. \
Please check your Homebrew installation or manually install it."
return False, error
return install_actionlint_source()
# try:
# subprocess.run(["brew", "install", "actionlint"], check=True)
# return True, ""
# except (FileNotFoundError, subprocess.CalledProcessError):
# error = "Failed to install Actionlint. \
# Please check your Homebrew installation or manually install it."
# return False, error
elif platform_system.startswith("Win"):
try:
subprocess.run(["choco", "install", "actionlint", "-y"], check=True)
return True, ""
return True, "", ""
except (FileNotFoundError, subprocess.CalledProcessError):
error = "Failed to install Actionlint. \
Please check your Chocolatey installation or manually install it."
return False, error
return False, 'whoops'
return False, error, ""
return False, error, ""


class RunActionlint(Rule):
Expand All @@ -85,14 +83,22 @@ def __init__(self, settings: Optional[Settings] = None) -> None:
def fn(self, obj: Workflow) -> Tuple[bool, str]:
if not obj.filename:
raise NotImplementedError("Running actionlint without a filename is not currently supported")
installed, install_error = check_actionlint()
installed, install_error, location = check_actionlint()
if installed:
result = subprocess.run(
["actionlint", obj.filename],
if location:
result = subprocess.run(
[location + "/actionlint", obj.filename],
capture_output=True,
text=True,
check=False,
)
else:
result = subprocess.run(
["actionlint", obj.filename],
capture_output=True,
text=True,
check=False,
)
if result.returncode == 1:
print(result.stdout)
return False, self.message
Expand Down

0 comments on commit dd6e1ef

Please sign in to comment.