mirror of
https://github.com/kuhyx/utils.git
synced 2026-11-10 20:07:18 +01:00
Some checks are pending
dependency freshness / dependencies on newest stable (push) Waiting to run
file length / file-length (push) Waiting to run
md-naming / markdown naming convention (push) Waiting to run
palette drift / palette (push) Waiting to run
repo-contract / repo contract (push) Waiting to run
shared gate tests / gate unit tests (push) Waiting to run
scripts/check_no_gms_signin.sh fails when a pubspec.lock or android gradle file pulls google_sign_in / play-services-auth / googleid, or a built APK (--apk) carries GMS auth classes, and names google_account_token as the fix. install_repo_contract_gate.sh now installs its shim and an always-run hook in Flutter Android repos. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01WzxdWVQE5pYiASpRGgA3Kg
63 lines
2.3 KiB
Python
63 lines
2.3 KiB
Python
"""The no-GMS-sign-in half of the installer: Flutter Android apps get the gate.
|
|
|
|
Why it rides on install_repo_contract_gate.sh: that installer is the one step
|
|
every new repo gets after `git init`, so a new Flutter app cannot come out of
|
|
scaffolding able to re-add google_sign_in (13 apps were migrated off it onto
|
|
utils/google_account_token in November 2026). Pieces: the
|
|
scripts/check_no_gms_signin.sh delegate and an always-run pre-commit hook.
|
|
Only repos with a pubspec.yaml next to an android/ dir (at the root or one
|
|
level down, e.g. tutor/app) get it; utils itself holds the real gate.
|
|
"""
|
|
|
|
from __future__ import annotations
|
|
|
|
from pathlib import Path
|
|
|
|
from repo_contract.precommit import PRECOMMIT, needs_hook, write_hook
|
|
|
|
TEMPLATES = Path(__file__).resolve().parent / "templates"
|
|
SHIM = Path("scripts/check_no_gms_signin.sh")
|
|
HOOK_ID = "no-gms-signin"
|
|
HOOK_PIECE = f"{PRECOMMIT} ({HOOK_ID} hook)"
|
|
SHIM_TEMPLATE = "check_no_gms_signin.shim.sh"
|
|
|
|
|
|
def _template(name: str) -> str:
|
|
return (TEMPLATES / name).read_text(encoding="utf-8")
|
|
|
|
|
|
def is_flutter_android(repo: Path) -> bool:
|
|
"""A pubspec.yaml beside an android/ dir, at the root or one level down."""
|
|
if (repo / "repo_contract" / "check.py").is_file():
|
|
return False # utils: SHIM is the real gate, never a delegate
|
|
pubspecs = [repo / "pubspec.yaml", *repo.glob("*/pubspec.yaml")]
|
|
return any(p.is_file() and (p.parent / "android").is_dir() for p in pubspecs)
|
|
|
|
|
|
def plan_gms(repo: Path) -> list[str]:
|
|
"""Which no-GMS-sign-in gate pieces are missing or drifted."""
|
|
if not is_flutter_android(repo):
|
|
return []
|
|
todo = []
|
|
shim = repo / SHIM
|
|
if not shim.is_file() or shim.read_text(encoding="utf-8") != _template(
|
|
SHIM_TEMPLATE
|
|
):
|
|
todo.append(str(SHIM))
|
|
if needs_hook(repo, HOOK_ID):
|
|
todo.append(HOOK_PIECE)
|
|
return todo
|
|
|
|
|
|
def install_gms(repo: Path) -> list[str]:
|
|
"""Write every missing or drifted no-GMS-sign-in piece. Returns them."""
|
|
todo = plan_gms(repo)
|
|
if str(SHIM) in todo:
|
|
target = repo / SHIM
|
|
target.parent.mkdir(parents=True, exist_ok=True)
|
|
target.write_text(_template(SHIM_TEMPLATE), encoding="utf-8")
|
|
target.chmod(0o755)
|
|
if HOOK_PIECE in todo:
|
|
write_hook(repo, _template("no-gms-signin-hook.yaml"))
|
|
return todo
|