Skip to content

Commit 372b9e5

Browse files
authored
Merge pull request #67 from padovan/refactor-results-build
Refactor 'results --action=builds'
2 parents adcd7ec + c54a46c commit 372b9e5

File tree

3 files changed

+74
-34
lines changed

3 files changed

+74
-34
lines changed

docs/results.md

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,10 @@ Unfortunately the Dashboard API doesn't support git tags as parameters yet.
3333

3434
Return results for the latest commit for the tree.
3535

36+
### --status
37+
38+
Filter results by the status: "all", "pass", "fail" or "inconclusive"
39+
3640
## Results actions
3741

3842
### --action=trees
@@ -56,14 +60,14 @@ Example:
5660
kci-dev results --giturl 'https://git.kernel.org/pub/scm/linux/kernel/git/next/linux-next.git' --branch master --commit d1486dca38afd08ca279ae94eb3a397f10737824 --action=summary
5761
```
5862

59-
### --action=failed-builds
63+
### --action=builds
6064

61-
List failed builds.
65+
List builds.
6266

6367
Example:
6468

6569
```sh
66-
kci-dev results --giturl 'https://git.kernel.org/pub/scm/linux/kernel/git/next/linux-next.git' --branch master --commit d1486dca38afd08ca279ae94eb3a397f10737824 --action failed-builds
70+
kci-dev results --giturl 'https://git.kernel.org/pub/scm/linux/kernel/git/next/linux-next.git' --branch master --commit d1486dca38afd08ca279ae94eb3a397f10737824 --action builds
6771
```
6872

6973
## Downloading logs

kcidev/libs/common.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ def load_toml(settings):
3636
return config
3737

3838

39-
def kci_print(content):
39+
def kci_msg(content):
4040
click.echo(content)
4141

4242

@@ -58,3 +58,7 @@ def kci_msg_red_nonl(content):
5858

5959
def kci_msg_yellow_nonl(content):
6060
click.secho(content, fg="bright_yellow", nl=False)
61+
62+
63+
def kci_msg_cyan_nonl(content):
64+
click.secho(content, fg="cyan", nl=False)

kcidev/subcommands/results.py

Lines changed: 62 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ def sum_inconclusive_results(results):
7878

7979

8080
def cmd_summary(data):
81-
kci_print("pass/fail/inconclusive")
81+
kci_msg("pass/fail/inconclusive")
8282

8383
builds = data["buildsSummary"]["builds"]
8484
print_summary("builds", builds["valid"], builds["invalid"], builds["null"])
@@ -100,35 +100,59 @@ def cmd_list_trees(origin):
100100
trees = fetch_tree_fast(origin)
101101
for t in trees:
102102
kci_msg_green_nonl(f"- {t['tree_name']}/{t['git_repository_branch']}:\n")
103-
kci_print(f" giturl: {t['git_repository_url']}")
104-
kci_print(f" latest: {t['git_commit_hash']} ({t['git_commit_name']})")
105-
kci_print(f" latest: {t['start_time']}")
103+
kci_msg(f" giturl: {t['git_repository_url']}")
104+
kci_msg(f" latest: {t['git_commit_hash']} ({t['git_commit_name']})")
105+
kci_msg(f" latest: {t['start_time']}")
106106

107107

108-
def cmd_failed_builds(data, download_logs):
109-
kci_print("Failed builds:")
108+
def cmd_builds(data, commit, download_logs, status):
109+
if status == "inconclusive":
110+
kci_msg("No information about inconclusive builds.")
111+
return
112+
110113
for build in data["builds"]:
111-
if not build["valid"]:
112-
log_path = build["log_url"]
113-
if download_logs:
114-
try:
115-
log_gz = requests.get(build["log_url"])
116-
log = gzip.decompress(log_gz.content)
117-
log_file = f"{build['config_name']}-{build['architecture']}-{build['compiler']}.log"
118-
with open(log_file, mode="wb") as file:
119-
file.write(log)
120-
log_path = os.path.join(os.getcwd(), log_file)
121-
except:
122-
kci_err(f"Failed to fetch log {log_file}).")
123-
pass
124-
125-
kci_print(
126-
f"- config: {build['config_name']}; arch: {build['architecture']}"
127-
)
128-
kci_print(f" compiler: {build['compiler']}")
129-
kci_print(f" config_url: {build['config_url']}")
130-
kci_print(f" log: {log_path}")
131-
kci_print(f" id: {build['id']}")
114+
if build["valid"] == None:
115+
continue
116+
117+
if not status == "all":
118+
if build["valid"] == (status == "fail"):
119+
continue
120+
121+
if not build["valid"] == (status == "pass"):
122+
continue
123+
124+
log_path = build["log_url"]
125+
if download_logs:
126+
try:
127+
log_gz = requests.get(build["log_url"])
128+
log = gzip.decompress(log_gz.content)
129+
log_file = f"{build['config_name']}-{build['architecture']}-{build['compiler']}-{commit}.log"
130+
with open(log_file, mode="wb") as file:
131+
file.write(log)
132+
log_path = "file://" + os.path.join(os.getcwd(), log_file)
133+
except:
134+
kci_err(f"Failed to fetch log {log_file}).")
135+
pass
136+
137+
kci_msg_nonl("- config:")
138+
kci_msg_cyan_nonl(build["config_name"])
139+
kci_msg_nonl(" arch: ")
140+
kci_msg_cyan_nonl(build["architecture"])
141+
kci_msg_nonl(" compiler: ")
142+
kci_msg_cyan_nonl(build["compiler"])
143+
kci_msg("")
144+
145+
kci_msg_nonl(" status:")
146+
if build["valid"]:
147+
kci_msg_green_nonl("PASS")
148+
else:
149+
kci_msg_red_nonl("FAIL")
150+
kci_msg("")
151+
152+
kci_msg(f" config_url: {build['config_url']}")
153+
kci_msg(f" log: {log_path}")
154+
kci_msg(f" id: {build['id']}")
155+
kci_msg("")
132156

133157

134158
@click.command(help=" [Experimental] Get results from the dashboard")
@@ -163,8 +187,13 @@ def cmd_failed_builds(data, download_logs):
163187
is_flag=True,
164188
help="Select latest results available",
165189
)
190+
@click.option(
191+
"--status",
192+
help="Status of test result: all, pass, fail, inconclusive",
193+
default="all",
194+
)
166195
@click.pass_context
167-
def results(ctx, origin, giturl, branch, commit, action, download_logs, latest):
196+
def results(ctx, origin, giturl, branch, commit, action, download_logs, latest, status):
168197
if action == None or action == "summary":
169198
if not giturl or not branch or not ((commit != None) ^ latest):
170199
kci_err("--giturl AND --branch AND (--commit XOR --latest) are required")
@@ -175,14 +204,17 @@ def results(ctx, origin, giturl, branch, commit, action, download_logs, latest):
175204
cmd_summary(data)
176205
elif action == "trees":
177206
cmd_list_trees(origin)
178-
elif action == "failed-builds":
207+
elif action == "builds":
179208
if not giturl or not branch or not ((commit != None) ^ latest):
180209
kci_err("--giturl AND --branch AND (--commit XOR --latest) are required")
181210
raise click.Abort()
182211
if latest:
183212
commit = get_latest_commit(origin, giturl, branch)
184213
data = fetch_full_results(origin, giturl, branch, commit)
185-
cmd_failed_builds(data, download_logs)
214+
cmd_builds(data, commit, download_logs, status)
215+
else:
216+
kci_err(f"action '{action}' does not exist.")
217+
raise click.Abort()
186218

187219

188220
if __name__ == "__main__":

0 commit comments

Comments
 (0)