import pathlib
import sys
try:
import yaml
except ImportError: print("PyYAML not installed; skipping workflow syntax check")
sys.exit(0)
status = 0
for path in sorted(pathlib.Path(".github/workflows").glob("*.yml")):
try:
document = yaml.safe_load(path.read_text())
except yaml.YAMLError as error:
print(f"{path}: {error}", file=sys.stderr)
status = 1
continue
if not isinstance(document, dict):
print(f"{path}: not a mapping", file=sys.stderr)
status = 1
continue
triggers = document.get("on", document.get(True))
if not triggers:
print(f"{path}: no triggers; GitHub would never run this", file=sys.stderr)
status = 1
continue
if not document.get("jobs"):
print(f"{path}: no jobs", file=sys.stderr)
status = 1
continue
print(f" ok {path.name}: {', '.join(triggers)}")
sys.exit(status)