Files
computer-playbook/cli/meta/runtime/__init__.py
T
kevinveenbirkenbach d2694566e5 feat(runtime): add development runtime marker and unified runtime detection
- introduce env.development marker for local dev runtime
- add cli.meta.runtime module with library API and CLI entrypoint
- detect runtime via ACT/GitHub/marker with explicit RUNTIME override
- use env.development as docker-compose env override
- pass RUNTIME=dev into development inventory generation
- add make setup-development helper

https://chatgpt.com/share/69720fd6-a1c8-800f-b1e2-6909aa63643a
2026-01-22 12:53:42 +01:00

61 lines
1.5 KiB
Python

from __future__ import annotations
import os
from pathlib import Path
def get_project_root() -> Path:
"""
Return the project root based on the location of this file.
Assumes this file lives in:
<project-root>/cli/meta/runtime/__init__.py
Therefore:
project-root = parents[3]
"""
return Path(__file__).resolve().parents[3]
def detect_runtime(project_root: Path | None = None) -> str:
"""
Detect the current execution runtime.
Returns one of:
- "act" : local GitHub Actions emulation (act)
- "github" : real GitHub Actions runner
- "dev" : local development compose stack
- "host" : native host execution (default)
Precedence:
1) RUNTIME (explicit override)
2) act (must come before github because act sets GITHUB_ACTIONS=true)
3) github
4) dev (marker relative to project root)
5) host
"""
# 1) explicit override wins
v = (os.getenv("RUNTIME") or "").strip()
if v:
return v
# 2) act (must be before GitHub)
if os.getenv("ACT") == "true" or os.getenv("ACT_RUNNER"):
return "act"
# 3) GitHub Actions
if (
os.getenv("GITHUB_ACTIONS") == "true"
or os.getenv("RUNNING_ON_GITHUB") == "true"
):
return "github"
# 4) local dev compose stack (project-root relative marker)
root = project_root or get_project_root()
if (root / "env.development").exists():
return "dev"
# 5) default
return "host"