66a1029bd5
* Create multiple actions to make Mako easier to use * Add smoke tests for the new actions * Check if the required env vars aren't empty * Fix working directory for execute-command * Fix action_path references * Fix broken setup_git command * Add exec-ryujinx-tasks subcommand * Ensure python and pipx are installed * Improve help output * Add required environment variables to README.md * Add small script to generate subcommand sections automatically * Adjust help messages for ryujinx tasks as well * Remove required argument for positionals * Add exec-ryujinx-tasks to subcommands list * Apply black formatting * Fix event name for update-reviewers
65 lines
1.5 KiB
Python
65 lines
1.5 KiB
Python
import logging
|
|
from abc import ABC, abstractmethod
|
|
from argparse import ArgumentParser, Namespace
|
|
from typing import Any
|
|
|
|
from github import Github
|
|
from github.Auth import AppAuth
|
|
|
|
from ryujinx_mako._const import (
|
|
APP_ID,
|
|
PRIVATE_KEY,
|
|
INSTALLATION_ID,
|
|
SCRIPT_NAME,
|
|
IS_DRY_RUN,
|
|
)
|
|
|
|
|
|
class Subcommand(ABC):
|
|
_subcommands: dict[str, Any] = {}
|
|
|
|
@abstractmethod
|
|
def __init__(self, parser: ArgumentParser):
|
|
parser.set_defaults(func=self.run)
|
|
|
|
@property
|
|
def logger(self):
|
|
return logging.getLogger(SCRIPT_NAME).getChild(
|
|
type(self).name().replace("-", "_")
|
|
)
|
|
|
|
@abstractmethod
|
|
def run(self, args: Namespace):
|
|
raise NotImplementedError()
|
|
|
|
@staticmethod
|
|
@abstractmethod
|
|
def name() -> str:
|
|
raise NotImplementedError()
|
|
|
|
@staticmethod
|
|
@abstractmethod
|
|
def description() -> str:
|
|
raise NotImplementedError()
|
|
|
|
@classmethod
|
|
def get_subcommand(cls, name: str):
|
|
return cls._subcommands[name]
|
|
|
|
@classmethod
|
|
def add_subcommand(cls, name: str, subcommand):
|
|
if name in cls._subcommands.keys():
|
|
raise ValueError(f"Key '{name}' already exists in {cls}._subcommands")
|
|
cls._subcommands[name] = subcommand
|
|
|
|
|
|
class GithubSubcommand(Subcommand, ABC):
|
|
_github = (
|
|
Github(auth=AppAuth(APP_ID, PRIVATE_KEY).get_installation_auth(INSTALLATION_ID))
|
|
if not IS_DRY_RUN
|
|
else None
|
|
)
|
|
|
|
@property
|
|
def github(self):
|
|
return type(self)._github
|