Skip to content

Commit 73d2ac1

Browse files
committed
Fix update-checkout error reporting
In the event of a failure, update-checkout wouldn't always fail very gracefully. As a result the actual failure wasn't always printed, which makes it really difficult to figure out what's going on. In my case, I'm jumping between 5.6 and main branches, so the `swift-cmark-gfm` is causing update-checkout to hiccup since it's not in the `main` configuration file scheme for `main`, but is in the 5.6 repository. You wouldn't know that though, since it would complain about `repo_path` not being in the error message before crashing. I've gone ahead and done some cleanups, reporting what the problem is at the point of failure beyond the "key error 'swift-cmark-cfg'. Modernized the error reporter a bit, so it should be a smidge easier to read.
1 parent 23e5143 commit 73d2ac1

File tree

1 file changed

+45
-26
lines changed

1 file changed

+45
-26
lines changed

utils/update_checkout/update_checkout/update_checkout.py

Lines changed: 45 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -60,18 +60,33 @@ def check_parallel_results(results, op):
6060
parallel implementation.
6161
"""
6262

63-
fail_count = 0
6463
if results is None:
6564
return 0
65+
66+
# Remove non-errors
67+
results = [r for r in results if r]
68+
69+
if results:
70+
print(f"======{op} FAILURES======", file=sys.stderr)
71+
72+
messages = []
6673
for r in results:
67-
if r is not None:
68-
if fail_count == 0:
69-
print("======%s FAILURES======" % op)
70-
print("%s failed (ret=%d): %s" % (r.repo_path, r.ret, r))
71-
fail_count += 1
72-
if r.stderr:
73-
print(r.stderr)
74-
return fail_count
74+
try:
75+
raise r
76+
except KeyError as e:
77+
messages.append(f"Failed to look up {e} in scheme\n")
78+
except Exception:
79+
path = getattr(r, 'repo_path', '')
80+
reason = getattr(r, 'stderr', '')
81+
if path:
82+
message = f"{path} failed"
83+
if reason:
84+
message += f"\n```\n{reason}\n```"
85+
message += f"\n{r}"
86+
if message:
87+
messages.append(message + '\n')
88+
print('---\n\n'.join(messages), file=sys.stderr)
89+
return len(results)
7590

7691

7792
def confirm_tag_in_repo(tag, repo_name):
@@ -100,20 +115,25 @@ def get_branch_for_repo(config, repo_name, scheme_name, scheme_map,
100115
cross_repo = False
101116
repo_branch = scheme_name
102117
if scheme_map:
103-
scheme_branch = scheme_map[repo_name]
104-
repo_branch = scheme_branch
105-
remote_repo_id = config['repos'][repo_name]['remote']['id']
106-
if remote_repo_id in cross_repos_pr:
107-
cross_repo = True
108-
pr_id = cross_repos_pr[remote_repo_id]
109-
repo_branch = "ci_pr_{0}".format(pr_id)
110-
shell.run(["git", "checkout", scheme_branch],
111-
echo=True)
112-
shell.capture(["git", "branch", "-D", repo_branch],
113-
echo=True, allow_non_zero_exit=True)
114-
shell.run(["git", "fetch", "origin",
115-
"pull/{0}/merge:{1}"
116-
.format(pr_id, repo_branch), "--tags"], echo=True)
118+
try:
119+
scheme_branch = scheme_map[repo_name]
120+
repo_branch = scheme_branch
121+
remote_repo_id = config['repos'][repo_name]['remote']['id']
122+
if remote_repo_id in cross_repos_pr:
123+
cross_repo = True
124+
pr_id = cross_repos_pr[remote_repo_id]
125+
repo_branch = "ci_pr_{0}".format(pr_id)
126+
shell.run(["git", "checkout", scheme_branch],
127+
echo=True)
128+
shell.capture(["git", "branch", "-D", repo_branch],
129+
echo=True, allow_non_zero_exit=True)
130+
shell.run(["git", "fetch", "origin",
131+
"pull/{0}/merge:{1}"
132+
.format(pr_id, repo_branch), "--tags"], echo=True)
133+
except KeyError as e:
134+
print(f"Failed to look up {repo_name} in scheme", file=sys.stderr)
135+
raise e
136+
exit(1)
117137
return repo_branch, cross_repo
118138

119139

@@ -634,10 +654,9 @@ def main():
634654

635655
update_results = update_all_repositories(args, config, scheme,
636656
cross_repos_pr)
637-
fail_count = 0
638-
fail_count += check_parallel_results(clone_results, "CLONE")
657+
fail_count = check_parallel_results(clone_results, "CLONE")
639658
fail_count += check_parallel_results(update_results, "UPDATE")
640-
if fail_count > 0:
659+
if fail_count:
641660
print("update-checkout failed, fix errors and try again")
642661
else:
643662
print("update-checkout succeeded")

0 commit comments

Comments
 (0)