Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weโ€™ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Agalles/renovate actionlint v2 #72

Draft
wants to merge 39 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
a2893cd
trying windows runner
AmyLGalles Feb 14, 2025
5ac591b
running from pip rather than gh-actions
AmyLGalles Feb 14, 2025
dc9f42e
adding this workflow to the trigger list
AmyLGalles Feb 14, 2025
a5362ff
trying workaround for build install
AmyLGalles Feb 14, 2025
7f39821
trying workaround in a different place
AmyLGalles Feb 14, 2025
e7ca29e
testing without pytype
AmyLGalles Feb 14, 2025
b25c145
try running bwwl locally
AmyLGalles Feb 14, 2025
b960b97
try running bwwl locally
AmyLGalles Feb 14, 2025
5987d78
try running bwwl locally
AmyLGalles Feb 14, 2025
457e90a
adding verison control to choco
AmyLGalles Feb 14, 2025
68a985d
fixing version string
AmyLGalles Feb 14, 2025
7c375de
managing version through settings file
AmyLGalles Feb 14, 2025
49ed00b
adding windows runner to test choco install
AmyLGalles Feb 14, 2025
ea6e925
installing from source on Mac systems
AmyLGalles Feb 14, 2025
d37cf57
removing troubleshooting strings
AmyLGalles Feb 14, 2025
0e3cb39
Merge branch 'main' into agalles/renovate-actionlint-v2
AmyLGalles Feb 14, 2025
dbb285d
resolving merge conflict
AmyLGalles Feb 21, 2025
4ea1b9f
upgrading actionlint to latest version
AmyLGalles Feb 21, 2025
0565a82
removing unneccessary change
AmyLGalles Feb 12, 2025
4496374
adjusting tests for new steps
AmyLGalles Feb 12, 2025
9e12234
resolving merge conflict
AmyLGalles Feb 21, 2025
b5cb58f
removing temporary files
AmyLGalles Feb 21, 2025
5c54ffb
incorporating changes from fix-actionlint
AmyLGalles Feb 21, 2025
06b6d21
removing redundant local check
AmyLGalles Feb 21, 2025
90c9298
updating tests from troubleshooting branch
AmyLGalles Feb 21, 2025
4ac1fd2
updating tests to use settings file
AmyLGalles Feb 21, 2025
f67b560
non-working pytest
AmyLGalles Feb 24, 2025
98ca428
minor changes to make tests work
AmyLGalles Feb 25, 2025
492d4c4
newline
AmyLGalles Feb 25, 2025
9df65d3
checking that local version is correct
AmyLGalles Feb 25, 2025
a379ddb
removing broken tests
AmyLGalles Feb 25, 2025
4aaa456
adding additional try except
AmyLGalles Feb 25, 2025
bfe39a8
reenabling tests
AmyLGalles Feb 25, 2025
0ba1721
removing buggy test
AmyLGalles Feb 25, 2025
78fc8fe
removing unused import
AmyLGalles Feb 25, 2025
bb6d668
Merge branch 'main' into agalles/renovate-actionlint-v2
AmyLGalles Feb 25, 2025
60e5366
Delete .tool-versions
AmyLGalles Feb 25, 2025
7001b7c
reenable local tests
AmyLGalles Feb 25, 2025
04e2196
remove unused argument
AmyLGalles Feb 25, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 35 additions & 0 deletions .github/workflows/actionlint_windows.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
name: Test Actionlint on Windows

on:
pull_request:
branches:
- main
paths:
- "**/run_actionlint.py"
- "**/default_actions.json"
- "**/actionlint_windows.yml"

jobs:
test:
name: Windows workflow-linter (v2)
runs-on: windows-2022
steps:
- name: Check out repo
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2

- name: Set up Python
uses: actions/setup-python@42375524e23c412d93fb67b49958b491fce71c38 # v5.4.0
with:
python-version-file: ".python-version"

- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install pipenv
pipenv install --dev

- name: Install bwwl binary
run: python -m pip install --upgrade .

- name: Lint
run: bwwl lint -f .github/workflows
2 changes: 1 addition & 1 deletion Pipfile
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ pytest = "*"
coverage = "*"
pytest-cov = "*"
pylint = "*"
pytype = "*"
pytype = {version = "*", sys_platform = "!= 'win32'"}
hatchling = "*"
build = "*"

Expand Down
2 changes: 2 additions & 0 deletions src/bitwarden_workflow_linter/default_settings.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,5 @@ enabled_rules:
level: warning

approved_actions_path: default_actions.json

actionlint_version: "1.7.7"
53 changes: 30 additions & 23 deletions src/bitwarden_workflow_linter/rules/run_actionlint.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,69 +4,76 @@
import subprocess
import platform
import urllib.request
import os

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


def install_actionlint(platform_system: str) -> Tuple[bool, str]:
def install_actionlint(platform_system: str, version: str) -> Tuple[bool, str]:
"""If actionlint is not installed, detects OS platform
and installs actionlint"""

error = f"An error occurred when installing Actionlint on {platform_system}"

if platform_system.startswith("Linux"):
return install_actionlint_source(error)
return install_actionlint_source(error, version)
elif platform_system == "Darwin":
try:
subprocess.run(["brew", "install", "actionlint"], check=True)
return True, ""
except (FileNotFoundError, subprocess.CalledProcessError):
return False, f"{error} : check Brew installation"
return install_actionlint_source(error, version) # Homebrew does not maintain previous versions of Actionlint
elif platform_system.startswith("Win"):
try:
subprocess.run(["choco", "install", "actionlint", "-y"], check=True)
subprocess.run(["choco", "install", "actionlint", "-y", f"--version='{version}'"], check=True)
return True, ""
except (FileNotFoundError, subprocess.CalledProcessError):
return False, f"{error} : check Choco installation"
return False, error


def install_actionlint_source(error) -> Tuple[bool, str]:
def install_actionlint_source(error, version) -> Tuple[bool, str]:
"""Install Actionlint Binary from provided script"""
url = "https://raw.githubusercontent.com/rhysd/actionlint/main/scripts/download-actionlint.bash"
version = "1.6.17"
version = version
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()
return True, "./actionlint"
except (FileNotFoundError, subprocess.CalledProcessError):
return False, error


def check_actionlint(platform_system: str) -> Tuple[bool, str]:
def check_actionlint(platform_system: str, version: str) -> Tuple[bool, str]:
"""Check if the actionlint is in the system's PATH."""
try:
subprocess.run(
installed = subprocess.run(
["actionlint", "--version"],
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
check=True,
)
return True, ""
)
if version in f"{installed}":
return True, ""
else:
return install_actionlint(platform_system, version)

except subprocess.CalledProcessError:
return (
False,
"Failed to install Actionlint, \
please check your package installer or manually install it",
)
except FileNotFoundError:
return install_actionlint(platform_system)

try:
installed = subprocess.run(
["./actionlint", "--version"],
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
check=True,
)
if version in f"{installed}":
return True, "./actionlint"
else:
return install_actionlint(platform_system, version)
except FileNotFoundError:
return install_actionlint(platform_system, version)

class RunActionlint(Rule):
"""Rule to run actionlint as part of workflow linter V2."""
Expand All @@ -83,11 +90,11 @@ def fn(self, obj: Workflow) -> Tuple[bool, str]:
"Running actionlint without a filename is not currently supported"
)

installed, location = check_actionlint(platform.system())
installed, location = check_actionlint(platform.system(), self.settings.actionlint_version)
if installed:
if location:
result = subprocess.run(
[location + "/actionlint", obj.filename],
[location, obj.filename],
capture_output=True,
text=True,
check=False,
Expand Down
7 changes: 7 additions & 0 deletions src/bitwarden_workflow_linter/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,11 +113,13 @@ class Settings:

enabled_rules: list[dict[str, str]]
approved_actions: dict[str, Action]
actionlint_version = str

def __init__(
self,
enabled_rules: Optional[list[dict[str, str]]] = None,
approved_actions: Optional[dict[str, dict[str, str]]] = None,
actionlint_version: Optional[str] = None,
) -> None:
"""Settings object that can be overridden in settings.py.

Expand All @@ -135,6 +137,10 @@ def __init__(
if approved_actions is None:
approved_actions = {}

if actionlint_version is None:
actionlint_version = ""

self.actionlint_version = actionlint_version
self.enabled_rules = enabled_rules
self.approved_actions = {
name: Action(**action) for name, action in approved_actions.items()
Expand Down Expand Up @@ -175,4 +181,5 @@ def factory() -> SettingsFromFactory:
return Settings(
enabled_rules=settings["enabled_rules"],
approved_actions=settings["approved_actions"],
actionlint_version=settings["actionlint_version"],
)
Loading