Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix auto sheriff #1784

Merged
merged 1 commit into from
Nov 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 15 additions & 11 deletions buildkite/bazel_auto_sheriff.py
Original file line number Diff line number Diff line change
Expand Up @@ -531,10 +531,11 @@ def extract_job_info_by_key(job, info_from_command = [], info_from_job = ["name"
# Assume there is no space in each argument
args = job["command"].split(" ")
for info in info_from_command:
prefix = "--" + info + "="
for arg in args:
prefix = "--" + info + "="
if arg.startswith(prefix):
job_info[info] = arg[len(prefix):]
break
if info not in job_info:
return None

Expand Down Expand Up @@ -597,26 +598,23 @@ def get_project_state(tasks):
# }
# }
def get_downstream_result_by_project(downstream_build_info):
config_to_project = {}
for project_name, project_info in bazelci.DOWNSTREAM_PROJECTS.items():
config_to_project[project_info["http_config"]] = project_name

downstream_result = {}
jobs_per_project = {}

for job in downstream_build_info["jobs"]:
# Skip all soft failed jobs
if "soft_failed" in job and job["soft_failed"]:
continue
job_info = extract_job_info_by_key(job = job, info_from_command = ["http_config", "git_commit"])
job_info = extract_job_info_by_key(job = job, info_from_command = ["git_commit"])
if job_info:
project_name = config_to_project[job_info["http_config"]]
project_name = get_project_name_from_job(job_info)
if project_name not in downstream_result:
jobs_per_project[project_name] = []
downstream_result[project_name] = {}
downstream_result[project_name]["bazel_commit"] = downstream_build_info["commit"]
downstream_result[project_name]["build_number"] = downstream_build_info["number"]
downstream_result[project_name]["commit"] = job_info["git_commit"]
downstream_result[project_name] = {
"bazel_commit": downstream_build_info["commit"],
"build_number": downstream_build_info["number"],
"commit": job_info["git_commit"],
}
jobs_per_project[project_name].append(job_info)

for project_name in jobs_per_project:
Expand All @@ -627,6 +625,12 @@ def get_downstream_result_by_project(downstream_build_info):
return downstream_result


def get_project_name_from_job(job_info):
# This is a bit of a hack that depends on how bazelci.create_label()
# formats job names in downstream pipelines.
return job_info.get("name").partition(" (")[0]


def main(argv=None):
downstream_build_info = get_latest_downstream_build_info()
downstream_result = get_downstream_result_by_project(downstream_build_info)
Expand Down
2 changes: 2 additions & 0 deletions buildkite/bazelci.py
Original file line number Diff line number Diff line change
Expand Up @@ -3100,6 +3100,8 @@ def create_label(platform, project_name, build_only=False, test_only=False, task
)

if project_name:
# Update get_project_name_from_job in bazel_auto_sheriff.py if you change
# the expected format of "Project Foo (Task bar on OS)"
label += "{0} ({1})".format(project_name, platform_label)
else:
label += platform_label
Expand Down