diff --git a/contest/results-faker.py b/contest/results-faker.py deleted file mode 100755 index d2c6528..0000000 --- a/contest/results-faker.py +++ /dev/null @@ -1,102 +0,0 @@ -#!/usr/bin/env python3 -# SPDX-License-Identifier: GPL-2.0 - -import configparser -import datetime -import json -import os - - -""" -Combined test runner and collector. -It generates fake data for the UI to display. -It holds no history, only live branches will show up. - -Config: - -[input] -branches=/path/to/branches.json,/path/to/branches2.json -infos=/path/to/infos.json,/path/to/infos2.json -[output] -dir=/path/to/output -url_pfx=relative/within/server -info=/path/to/info.json -""" - -def combine_infos(config): - paths = config.get("input", "infos", fallback="").split(',') - if not paths: - return - - infos = {} - for path in paths: - with open(path, "r") as fp: - infos.update(json.load(fp)) - - # atomic write needed - path = config.get("output", "info") - tmp = path + '.new' - with open(tmp, 'w') as fp: - json.dump(infos, fp) - os.rename(tmp, path) - - -def main() -> None: - config = configparser.ConfigParser() - config.read(['faker.config']) - - combine_infos(config) - - branches = [] - paths = config.get("input", "branches") - for path in paths.split(','): - with open(path, "r") as fp: - branches += json.load(fp) - - branches = sorted(branches, key=lambda x: x["date"]) - - url = config.get("output", "url_pfx") - if url[-1] != '/': - url += '/' - directory = config.get("output", "dir") - - used_cookies = set() - results = [] - for br in branches: - br_dt = datetime.datetime.fromisoformat(br["date"]) - run_id_cookie = int(br_dt.timestamp() / 60) % 1000000 - while run_id_cookie in used_cookies: - run_id_cookie += 1 - used_cookies.add(run_id_cookie) - fname = f"results-{run_id_cookie}.json" - - data = {'url': url + fname, - 'branch': br["branch"], - 'executor': "brancher"} - results.append(data) - - run = {'branch': br["branch"], 'executor': "brancher"} - br_dt += datetime.timedelta(seconds=1) - run["start"] = br_dt.isoformat() - br_dt += datetime.timedelta(seconds=3) - run["end"] = br_dt.isoformat() - - tail = br["url"].find('.git ') - if br["url"].startswith('https://github.com') and tail > 0: - br_url = br["url"][:tail] + "/commits/" + br["url"][tail + 5:] - else: - br_url = "https://netdev.bots.linux.dev/contest/branches.json" - - run["results"] = [ - {"test": "branch-created", "group": "---", "result": "pass", "link": br_url} - ] - - with open(os.path.join(directory, fname), "w") as fp: - json.dump(run, fp) - - with open(os.path.join(directory, 'results.json'), "w") as fp: - json.dump(results, fp) - - -if __name__ == "__main__": - main() diff --git a/pw_brancher.py b/pw_brancher.py index b2013e6..5a544dd 100755 --- a/pw_brancher.py +++ b/pw_brancher.py @@ -390,10 +390,7 @@ def dump_branches(config, state) -> None: "url": pub_url + " " + name}) write_json_atomic(config.get("output", "branches"), data) - - info = config.get("output", "info") - with open(info, 'w') as fp: - json.dump(state["info"], fp) + write_json_atomic(config.get("output", "info"), state["info"]) log_end_sec() diff --git a/pw_contest.py b/pw_contest.py index f118bb1..3629639 100755 --- a/pw_contest.py +++ b/pw_contest.py @@ -27,6 +27,8 @@ patch_state=state.json [www] contest=https://server-with-ui/contest.html +[patchwork] +check_name=contest """ class Codes: @@ -191,7 +193,7 @@ def patch_state_compute(state: dict, branches: dict, branch_outcome: dict) -> No series_state = state["series"] pr_state = state["prs"] for name, branch in branches.items(): - # branch got tagged but faker didn't add it to results, yet + # branch got tagged but no results, yet if name not in branch_outcome: continue @@ -223,16 +225,16 @@ def skip_update(outcome) -> bool: return False -def update_one(pw, patch_id, outcome, link): +def update_one(pw, patch_id, outcome, link, check_name): description = outcome['branch'] if outcome["code"] >= 0: description += f' (tests: {outcome["cnt"]})' url = link + '?pw-n=0&branch=' + outcome['branch'] - pw.post_check(patch_id, name="contest", state=code_to_pw[outcome["code"]], + pw.post_check(patch_id, name=check_name, state=code_to_pw[outcome["code"]], url=url, desc=description) -def _patch_state_update(pw, state: dict, link: str): +def _patch_state_update(pw, state: dict, link: str, check_name: str): update_cnt = 0 for series_id, outcome in state["series"].items(): if skip_update(outcome): @@ -242,7 +244,7 @@ def _patch_state_update(pw, state: dict, link: str): log_open_sec('Updating series ' + series_id) series_pw = pw.get("series", series_id) for patch in series_pw["patches"]: - update_one(pw, patch["id"], outcome, link) + update_one(pw, patch["id"], outcome, link, check_name) update_cnt += 1 del outcome["update"] @@ -255,7 +257,7 @@ def _patch_state_update(pw, state: dict, link: str): try: log_open_sec('Updating PR ' + pr_id) - update_one(pw, pr_id, outcome, link) + update_one(pw, pr_id, outcome, link, check_name) update_cnt += 1 del outcome["update"] @@ -265,10 +267,10 @@ def _patch_state_update(pw, state: dict, link: str): print("Updated", update_cnt, "pw things") -def patch_state_update(pw, state: dict, link: str): +def patch_state_update(pw, state: dict, link: str, check_name: str): log_open_sec('Updating patch states') try: - _patch_state_update(pw, state, link) + _patch_state_update(pw, state, link, check_name) finally: log_end_sec() @@ -291,7 +293,8 @@ def main_loop(pw) -> int: results_by_branch = results_pivot(filters, results) branch_outcome = branch_summarize(filters, results_by_branch) patch_state_compute(patch_state, branches, branch_outcome) - patch_state_update(pw, patch_state, config.get('www', 'contest')) + patch_state_update(pw, patch_state, config.get('www', 'contest'), + config.get('patchwork', 'check_name', fallback='contest')) rbb = config.get('output', 'results_by_branch', fallback=None) if rbb: