Files
zeekay 1b367e2b62 chore: rebase the tree onto upstream master
The tree was a debranded snapshot of upstream taken around 2026-02-20, and
upstream has moved about five months since. This replaces it with upstream
master, mechanically re-derived: bin/debrand does the rename, and the
pipeline and squashed migrations are restored from the shipped tree.

Not a merge. The previous import replaced the tree wholesale in a single
commit, so there is no shared content history to merge against. Reproducing
the rename on the new tree is what actually converges.

What survives: .hanzo/workflows, the Dockerfiles and bin/docker* entrypoints,
compose files, LLM.md, and insights/migrations. The squashed initial
migration is load-bearing — the live database records it by name, so
upstream's ~918 individual migrations cannot come back.

Nine products are dropped as unreferenced. Twenty-one more that we do not run
are kept anyway because the core app still imports them; unpicking those is a
refactor and does not belong in a rebase.

This base does not build yet, and the reasons are not in the rename:
upstream now wants Python 3.13.13 against our 3.12.12 and Django 5.2 against
our 4.2, and the dependency manifests still name upstream packages that we
republish under our own names. Those are decisions, not renames.
2026-08-01 15:44:40 -07:00

103 lines
3.4 KiB
Python

"""Click entrypoint for ``lint:workflows``.
Wired into the insightscli CLI via the ``click:`` manifest entry in ``insightscli.yaml``;
the lazy loader resolves this module only when the command actually runs.
"""
from __future__ import annotations
import os
from pathlib import Path
import click
from insightscli.manifest import REPO_ROOT
from .check import Issue, WorkflowCheck
from .checks import CHECKS, get_check
from .model import Workflow, WorkflowParseError, read_workflows
_IN_GH_ACTIONS = os.environ.get("GITHUB_ACTIONS") == "true"
def _gh_annotation(level: str, check_label: str, issue: Issue) -> None:
if not _IN_GH_ACTIONS:
return
file_part = f" file={issue.file}" if issue.file else ""
click.echo(f"::{level}{file_part} title=lint:workflows ({check_label})::{issue.render()}")
def _run_one(check: WorkflowCheck, workflows: list[Workflow]) -> int:
"""Run a single check, print results, return the issue count."""
click.echo(f" {check.id} ({check.label})...")
result = check.run(workflows)
for issue in result.issues:
click.echo(f" ✗ {issue.render()}")
_gh_annotation("error", check.label, issue)
if not result.issues:
click.echo(" ✓ ok")
return len(result.issues)
def _default_workflows_dir() -> Path:
return REPO_ROOT / ".github" / "workflows"
@click.command(
name="lint:workflows",
help="Lint .github/workflows/** for repo conventions",
)
@click.option(
"--check",
"check_id",
metavar="ID",
help="Run only the check with the given id (full id or WF### prefix, e.g. WF001 or WF001-job-timeouts)",
)
@click.option("--list", "list_checks", is_flag=True, help="List registered checks and exit")
@click.option(
"--workflows-dir",
type=click.Path(exists=True, file_okay=False, path_type=Path),
default=None,
show_default=False,
help="Workflows directory (defaults to <repo>/.github/workflows)",
)
def cmd_lint_workflows(check_id: str | None, list_checks: bool, workflows_dir: Path | None) -> None:
if list_checks:
for check in CHECKS:
click.echo(f"{check.id}\t{check.label} — {check.description}")
return
if check_id is not None:
target = get_check(check_id)
if target is None:
raise click.UsageError(f"Unknown check id '{check_id}'. Run with --list to see registered checks.")
selected: list[WorkflowCheck] = [target]
else:
selected = list(CHECKS)
resolved_dir = workflows_dir or _default_workflows_dir()
try:
workflows = list(read_workflows(resolved_dir))
except WorkflowParseError as exc:
click.echo(f"✗ {exc}", err=True)
raise SystemExit(1) from exc
click.echo(f"Linting {len(workflows)} workflow(s) with {len(selected)} check(s):\n")
total_issues = 0
failing_checks: list[WorkflowCheck] = []
for check in selected:
issues = _run_one(check, workflows)
total_issues += issues
if issues:
failing_checks.append(check)
click.echo("")
if failing_checks:
for check in failing_checks:
if check.fix_hint:
click.echo(f"Fix for {check.id}:\n{check.fix_hint}\n")
click.echo(f"✗ {total_issues} issue(s) across {len(failing_checks)} check(s)")
raise SystemExit(1)
click.echo(f"✓ All {len(selected)} check(s) passed across {len(workflows)} workflow(s)")