Skip to content

check_workflow_names

rhiza_hooks.check_workflow_names

Script to ensure GitHub Actions workflows have the (RHIZA) prefix.

This hook checks that all rhiza workflow files have their 'name' field properly formatted with the (RHIZA) prefix in uppercase. If not, it automatically updates the file.

Migrated from: https://github.com/Jebel-Quant/rhiza/.rhiza/scripts/check_workflow_names.py

check_file(filepath)

Check if the workflow file has the correct name prefix and update if needed.

Parameters:

Name Type Description Default
filepath str

Path to the workflow file.

required

Returns:

Name Type Description
bool bool

True if file is correct, False if it was updated or has errors.

Source code in rhiza_hooks/check_workflow_names.py
def check_file(filepath: str) -> bool:
    """Check if the workflow file has the correct name prefix and update if needed.

    Args:
        filepath: Path to the workflow file.

    Returns:
        bool: True if file is correct, False if it was updated or has errors.
    """
    with open(filepath, encoding="utf-8") as f:
        try:
            content = yaml.safe_load(f)
        except yaml.YAMLError as exc:
            print(f"Error parsing YAML {filepath}: {exc}")
            return False

    if not isinstance(content, dict):
        # Empty file or not a dict
        return True

    name = content.get("name")
    if not name:
        print(f"Error: {filepath} missing 'name' field.")
        return False

    expected_name = _expected_name(name)

    if name == expected_name:
        return True

    print(f"Updating {filepath}: name '{name}' -> '{expected_name}'")
    _rewrite_workflow_name(filepath, expected_name)
    return False  # Fail so pre-commit knows files were modified

main(argv=None)

Execute the script.

Source code in rhiza_hooks/check_workflow_names.py
def main(argv: list[str] | None = None) -> int:
    """Execute the script."""
    files = argv if argv is not None else sys.argv[1:]
    failed = False  # pragma: no mutate  # equivalent: only ever read via `if failed`
    for f in files:
        if not check_file(f):
            failed = True

    return 1 if failed else 0