diff options
author | Lars Wirzenius <liw@liw.fi> | 2023-12-27 09:36:20 +0200 |
---|---|---|
committer | Lars Wirzenius <liw@liw.fi> | 2023-12-27 09:36:20 +0200 |
commit | c2d886b5957fe5199cd8138164b24abace7f26d1 (patch) | |
tree | dc0f6535dfca3f246a88bf407f91ab835ba0d8b2 | |
parent | dd95c2b380c6259fe38a6cb6113812fdcea96445 (diff) | |
download | wumpus-hunter-c2d886b5957fe5199cd8138164b24abace7f26d1.tar.gz |
feat: log success/fail of run
Signed-off-by: Lars Wirzenius <liw@liw.fi>
-rwxr-xr-x | wumpus-hunter | 40 |
1 files changed, 35 insertions, 5 deletions
diff --git a/wumpus-hunter b/wumpus-hunter index 53e1607..492d772 100755 --- a/wumpus-hunter +++ b/wumpus-hunter @@ -11,6 +11,7 @@ HEARTWOOD_REF = "master" CLONE_DIR = os.path.expanduser("~/src") TEST_CMD = "timeout 600s cargo test" LOG_FILE = os.path.expanduser("~/log.txt") +STATS_FILE = os.path.expanduser("~/stats.txt") def parse_args(): @@ -24,6 +25,9 @@ def parse_args(): ) p.add_argument("--test", default=TEST_CMD, help="Command to run tests") p.add_argument("--log", default=LOG_FILE, help="Write log file") + p.add_argument( + "--stats", default=STATS_FILE, help="Write statistics of results to file" + ) return p.parse_args() @@ -47,6 +51,7 @@ def get_code(url, ref, dirname): git_reset(dirname, ref) git_status(dirname) git_show_head(dirname) + return get_commit(dirname) def git_clone(url, dirname): @@ -84,8 +89,15 @@ def git_show_head(dirname): git("--no-pager", "show", "HEAD", cwd=dirname) +def get_commit(dirname): + logging.info(f"get HEAD commit in {dirname}") + commit = git("rev-parse", "HEAD", cwd=dirname).strip() + logging.info(f"HEAD is {commit}") + return commit + + def git(*args, cwd=None): - run(["git"] + list(args), cwd=cwd) + return run(["git"] + list(args), cwd=cwd) def run(argv, cwd=None): @@ -96,6 +108,7 @@ def run(argv, cwd=None): logging.info(f"exit code {p.returncode}") if p.returncode != 0: return Exception(f"command {argv} failed") + return p.stdout.decode() def log_output(stream, output): @@ -115,16 +128,33 @@ def run_tests(dirname, cmd): run(["bash", "-c", cmd], cwd=dirname) +def record_success(filename, commit): + record(filename, commit, "SUCCESS") + + +def record_failure(filename, commit): + record(filename, commit, "FAILURE") + + +def record(filename, commit, result): + with open(filename, "a") as f: + f.write(f"{commit} {result}\n") + + def main(): args = parse_args() setup_logging(args.log) logging.debug(f"url: {args.url}") logging.debug(f"ref: {args.ref}") logging.debug(f"dir: {args.dir}") - get_code(args.url, args.ref, args.dir) - build(args.dir) - run_tests(args.dir, args.test) - print("RESULT: ALL OK") + commit = get_code(args.url, args.ref, args.dir) + try: + build(args.dir) + run_tests(args.dir, args.test) + record_success(args.stats, commit) + except Exception as e: + logging.error(f"{e}", exc_info=True) + record_failure(args.stats, commit) main() |