SERVER-102675 Bundle up codeowners tooling into bazel rule (#33854)
GitOrigin-RevId: f164862110f362cb2daee5cb41e39ce184ea5d27
This commit is contained in:
committed by
MongoDB Bot
parent
697b9a1105
commit
831fd48363
49
buildscripts/bazel_rules_mongo/codeowners/validate_codeowners.py
Executable file
49
buildscripts/bazel_rules_mongo/codeowners/validate_codeowners.py
Executable file
@@ -0,0 +1,49 @@
|
||||
#!/usr/bin/env python3
|
||||
"""Script for validating CODEOWNERS file."""
|
||||
|
||||
import os
|
||||
import subprocess
|
||||
import sys
|
||||
|
||||
|
||||
def get_validator_env() -> dict:
|
||||
"""Prepare the environment for the codeowners-validator."""
|
||||
env = os.environ.copy()
|
||||
|
||||
env.update(
|
||||
{
|
||||
"REPOSITORY_PATH": ".",
|
||||
"CHECKS": "duppatterns,syntax",
|
||||
"EXPERIMENTAL_CHECKS": "avoid-shadowing",
|
||||
}
|
||||
)
|
||||
return env
|
||||
|
||||
|
||||
def run_validator(validator_path: str) -> int:
|
||||
"""Run the codeowners validation."""
|
||||
|
||||
if not os.path.isfile(validator_path):
|
||||
raise RuntimeError(f"Validator was not found at input path: {validator_path}")
|
||||
|
||||
print(f"Using validator at: {validator_path}")
|
||||
env = get_validator_env()
|
||||
|
||||
try:
|
||||
result = subprocess.run(
|
||||
[validator_path], env=env, check=True, capture_output=True, text=True
|
||||
)
|
||||
if result.stdout:
|
||||
print(result.stdout)
|
||||
return 0
|
||||
except subprocess.CalledProcessError as exc:
|
||||
if exc.stdout:
|
||||
print(exc.stdout, file=sys.stderr)
|
||||
if exc.stderr:
|
||||
print(exc.stderr, file=sys.stderr)
|
||||
return exc.returncode
|
||||
except FileNotFoundError:
|
||||
print("Error: Failed to run codeowners-validator after installation", file=sys.stderr)
|
||||
return 1
|
||||
except Exception:
|
||||
raise
|
||||
Reference in New Issue
Block a user