diff --git a/lint-workflow-v2/src/bitwarden_workflow_linter/actions.py b/lint-workflow-v2/src/bitwarden_workflow_linter/actions.py index f62456a0..ebe48c43 100644 --- a/lint-workflow-v2/src/bitwarden_workflow_linter/actions.py +++ b/lint-workflow-v2/src/bitwarden_workflow_linter/actions.py @@ -158,7 +158,7 @@ def save_actions(self, updated_actions: dict[str, Action], filename: str) -> Non json.dumps(converted_updated_actions, indent=2, sort_keys=True) ) - def add(self, new_action_name: str, filename: str) -> None: + def add(self, new_action_name: str, filename: str) -> int: """Sub-command to add a new Action to the list of approved Actions. 'actions add' will add an Action and all of its metadata and dump all @@ -175,8 +175,9 @@ def add(self, new_action_name: str, filename: str) -> None: updated_actions[latest.name] = latest self.save_actions(updated_actions, filename) + return 0 - def update(self, filename: str) -> None: + def update(self, filename: str) -> int: """Sub-command to update all of the versions of the approved actions. 'actions update' will update all of the approved to the newest version @@ -201,3 +202,4 @@ def update(self, filename: str) -> None: updated_actions[action.name] = latest_release self.save_actions(updated_actions, filename) + return 0 diff --git a/lint-workflow-v2/src/bitwarden_workflow_linter/cli.py b/lint-workflow-v2/src/bitwarden_workflow_linter/cli.py index a8c16840..930b0519 100644 --- a/lint-workflow-v2/src/bitwarden_workflow_linter/cli.py +++ b/lint-workflow-v2/src/bitwarden_workflow_linter/cli.py @@ -3,6 +3,8 @@ import argparse import sys +from typing import List, Optional + from .actions import ActionsCmd from .utils import Settings from .lint import LinterCmd @@ -11,7 +13,7 @@ local_settings = Settings.factory() -def main(input_args: list[str] = None) -> int: +def main(input_args: Optional[List[str]] = None) -> int: """CLI utility to lint GitHub Action Workflows. A CLI utility to enforce coding standards on GitHub Action workflows. The diff --git a/lint-workflow-v2/src/bitwarden_workflow_linter/load.py b/lint-workflow-v2/src/bitwarden_workflow_linter/load.py index 8817f79f..4dc52b3b 100644 --- a/lint-workflow-v2/src/bitwarden_workflow_linter/load.py +++ b/lint-workflow-v2/src/bitwarden_workflow_linter/load.py @@ -55,7 +55,7 @@ def __build_workflow(cls, loaded_yaml: CommentedMap) -> Workflow: """ return Workflow.init("", loaded_yaml) - #return Workflow.from_dict( + # return Workflow.from_dict( # { # **loaded_yaml, # "jobs": { @@ -72,7 +72,7 @@ def __build_workflow(cls, loaded_yaml: CommentedMap) -> Workflow: # for job_key, job in loaded_yaml["jobs"].items() # }, # } - #) + # ) @classmethod def build( diff --git a/lint-workflow-v2/src/bitwarden_workflow_linter/models/job.py b/lint-workflow-v2/src/bitwarden_workflow_linter/models/job.py index 78e1e35c..b9ac9081 100644 --- a/lint-workflow-v2/src/bitwarden_workflow_linter/models/job.py +++ b/lint-workflow-v2/src/bitwarden_workflow_linter/models/job.py @@ -38,7 +38,7 @@ def init(cls: Self, key: str, data: CommentedMap) -> Self: "key": key, "name": data["name"] if "name" in data else None, "runs-on": data["runs-on"] if "runs-on" in data else None, - "env": data["env"] if "env" in data else None + "env": data["env"] if "env" in data else None, } new_job = cls.from_dict(init_data) @@ -53,5 +53,4 @@ def init(cls: Self, key: str, data: CommentedMap) -> Self: if "@" in new_job.uses: new_job.uses_path, new_job.uses_ref = new_job.uses.split("@") - return new_job diff --git a/lint-workflow-v2/src/bitwarden_workflow_linter/models/workflow.py b/lint-workflow-v2/src/bitwarden_workflow_linter/models/workflow.py index dbcb382f..761f9f0c 100644 --- a/lint-workflow-v2/src/bitwarden_workflow_linter/models/workflow.py +++ b/lint-workflow-v2/src/bitwarden_workflow_linter/models/workflow.py @@ -32,7 +32,7 @@ def init(cls: Self, key: str, data: CommentedMap) -> Self: init_data = { "key": key, "name": data["name"] if "name" in data else None, - "on": data["on"] if "on" in data else None + "on": data["on"] if "on" in data else None, } new_workflow = cls.from_dict(init_data) diff --git a/lint-workflow-v2/src/bitwarden_workflow_linter/utils.py b/lint-workflow-v2/src/bitwarden_workflow_linter/utils.py index afc4c9e5..4d1cf2ee 100644 --- a/lint-workflow-v2/src/bitwarden_workflow_linter/utils.py +++ b/lint-workflow-v2/src/bitwarden_workflow_linter/utils.py @@ -7,7 +7,7 @@ from dataclasses import dataclass from enum import Enum -from typing import Optional, Self +from typing import Optional, Self, TypeVar from ruamel.yaml import YAML @@ -107,6 +107,9 @@ class SettingsError(Exception): pass +SettingsFromFactory = TypeVar("SettingsFromFactory", bound="Settings") + + class Settings: """Class that contains configuration-as-code for any portion of the app.""" @@ -117,7 +120,7 @@ def __init__( self, enabled_rules: Optional[list[str]] = None, approved_actions: Optional[dict[str, dict[str, str]]] = None, - ): + ) -> None: """Settings object that can be overriden in settings.py. Args: @@ -140,7 +143,7 @@ def __init__( } @staticmethod - def factory() -> Self: + def factory() -> SettingsFromFactory: with ( importlib.resources.files("bitwarden_workflow_linter") .joinpath("default_settings.yaml") diff --git a/lint-workflow-v2/tests/test_load.py b/lint-workflow-v2/tests/test_load.py index 9de3b1f7..98640af4 100644 --- a/lint-workflow-v2/tests/test_load.py +++ b/lint-workflow-v2/tests/test_load.py @@ -38,6 +38,7 @@ def fixture_simple_workflow_yaml(): """ ) + @pytest.fixture(name="complex_workflow_yaml") def fixture_complex_workflow_yaml(): return yaml.load( diff --git a/lint-workflow-v2/tests/test_workflow.py b/lint-workflow-v2/tests/test_workflow.py index e862d3c8..0c8b2d44 100644 --- a/lint-workflow-v2/tests/test_workflow.py +++ b/lint-workflow-v2/tests/test_workflow.py @@ -32,6 +32,7 @@ def fixture_simple_workflow_yaml(): """ ) + @pytest.fixture(name="complex_workflow_yaml") def fixture_complex_workflow_yaml(): return yaml.load(