forked from BasedHardware/omi
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcheck_runner_cost_policy.py
More file actions
39 lines (30 loc) · 1.21 KB
/
Copy pathcheck_runner_cost_policy.py
File metadata and controls
39 lines (30 loc) · 1.21 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#!/usr/bin/env python3
"""Reject paid GitHub-hosted runner labels in this public repository."""
from __future__ import annotations
import argparse
from pathlib import Path
PAID_RUNNER_LABELS = ("ubuntu-latest-m",)
def validate(root: Path) -> list[str]:
workflows = root / ".github" / "workflows"
errors: list[str] = []
for path in sorted((*workflows.glob("*.yml"), *workflows.glob("*.yaml"))):
for line_number, line in enumerate(path.read_text(encoding="utf-8").splitlines(), start=1):
for label in PAID_RUNNER_LABELS:
if label in line:
errors.append(
f"{path.relative_to(root)}:{line_number}: paid runner label {label!r} "
"is forbidden; public-repository jobs must use a standard runner"
)
return errors
def main() -> int:
parser = argparse.ArgumentParser()
parser.add_argument("--root", type=Path, default=Path.cwd())
args = parser.parse_args()
errors = validate(args.root.resolve())
if errors:
print("\n".join(errors))
return 1
print("GitHub runner cost policy check passed.")
return 0
if __name__ == "__main__":
raise SystemExit(main())