SERVER-104312: git age check (#43161)
GitOrigin-RevId: f869e75af91c4619fe7d5be74933023c873213a7
This commit is contained in:
parent
e527cbab13
commit
833eb3ad0d
@ -7,6 +7,7 @@ py_library(
|
||||
"compiledb.py",
|
||||
"engflow_check.py",
|
||||
"generate_common_bes_bazelrc.py",
|
||||
"git_age_check.py",
|
||||
"install_modules.py",
|
||||
"lint.py",
|
||||
"plus_interface.py",
|
||||
|
||||
51
bazel/wrapper_hook/git_age_check.py
Normal file
51
bazel/wrapper_hook/git_age_check.py
Normal file
@ -0,0 +1,51 @@
|
||||
import datetime
|
||||
import os
|
||||
import pathlib
|
||||
import platform
|
||||
import subprocess
|
||||
import sys
|
||||
import time
|
||||
|
||||
REPO_ROOT = str(pathlib.Path(__file__).parent.parent.parent)
|
||||
sys.path.append(REPO_ROOT)
|
||||
|
||||
from bazel.wrapper_hook.wrapper_debug import wrapper_debug
|
||||
|
||||
|
||||
def check():
|
||||
"""Check if the git branch is older than 7 weeks."""
|
||||
|
||||
wrapper_debug(f"Checking git branch age {REPO_ROOT}")
|
||||
|
||||
if os.environ.get("CI") is None and platform.machine().lower() not in {"ppc64le", "s390x"}:
|
||||
try:
|
||||
git_log_output = subprocess.check_output(
|
||||
["git", "log", '--pretty=format:"%ad"', "master..HEAD"], cwd=REPO_ROOT
|
||||
)
|
||||
wrapper_debug(f"Git log output: {git_log_output}")
|
||||
git_dates = git_log_output.decode("utf-8").strip().split("\n")
|
||||
if not git_dates or git_dates == [""]:
|
||||
wrapper_debug("No new commits found on the current branch compared to master.")
|
||||
return
|
||||
latest_commit_date_str = git_dates[-1]
|
||||
latest_commit_date_str = latest_commit_date_str.strip('"')
|
||||
wrapper_debug(f"Latest commit date string: {latest_commit_date_str}")
|
||||
latest_commit_date = datetime.datetime.strptime(
|
||||
latest_commit_date_str, "%a %b %d %H:%M:%S %Y %z"
|
||||
)
|
||||
current_date = datetime.datetime.now(datetime.timezone.utc)
|
||||
wrapper_debug(f"Current date: {current_date}")
|
||||
age_in_weeks = (current_date - latest_commit_date).days / 7
|
||||
wrapper_debug(f"Age in weeks: {age_in_weeks}")
|
||||
wrapper_debug(
|
||||
f"Latest commit date: {latest_commit_date_str}, Age in weeks: {age_in_weeks:.2f}"
|
||||
)
|
||||
if age_in_weeks > 2:
|
||||
print(
|
||||
f"WARNING: The current git branch is {age_in_weeks:.2f} weeks old. "
|
||||
"Please rebase onto the latest master branch to ensure up-to-date code and fast builds.",
|
||||
)
|
||||
time.sleep(2)
|
||||
except subprocess.CalledProcessError as e:
|
||||
wrapper_debug(f"Failed to get git log: {e}")
|
||||
return
|
||||
@ -23,6 +23,7 @@ def main():
|
||||
from bazel.wrapper_hook.autogenerated_targets import autogenerate_targets
|
||||
from bazel.wrapper_hook.engflow_check import engflow_auth
|
||||
from bazel.wrapper_hook.generate_common_bes_bazelrc import write_workstation_bazelrc
|
||||
from bazel.wrapper_hook.git_age_check import check as git_age_check
|
||||
from bazel.wrapper_hook.lint import LinterFail
|
||||
from bazel.wrapper_hook.plus_interface import check_bazel_command_type, test_runner_interface
|
||||
from bazel.wrapper_hook.set_mongo_variables import write_mongo_variables_bazelrc
|
||||
@ -55,6 +56,7 @@ def main():
|
||||
engflow_auth(args)
|
||||
write_workstation_bazelrc(args)
|
||||
write_mongo_variables_bazelrc(args)
|
||||
git_age_check()
|
||||
|
||||
try:
|
||||
args = test_runner_interface(
|
||||
|
||||
Loading…
Reference in New Issue
Block a user