Skip to content

Commit

Permalink
Fix auto sheriff (#1784)
Browse files Browse the repository at this point in the history
#1776 removed
http_config entries for downstream projects, which caused auto sheriff
to fail. With this change we no longer use "http_config : project name"
mappings. Instead we extract the project name from the job label, which
is a bit of a hack.
  • Loading branch information
fweikert authored Nov 13, 2023
1 parent e7dbd5a commit 3808e8b
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 11 deletions.
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

0 comments on commit 3808e8b

Please sign in to comment.