From 8f5d0a77b0d9e988018a5f09d2ace90280a41c71 Mon Sep 17 00:00:00 2001 From: Anas Nashif Date: Sat, 5 Nov 2022 13:42:26 -0400 Subject: [PATCH] twister: set both commit and run date in json report Version is not enough, we need the run date but also the commit date, to ease reporting and use in dashboards. Signed-off-by: Anas Nashif --- scripts/pylib/twister/twisterlib/environment.py | 12 ++++++++++++ scripts/pylib/twister/twisterlib/reports.py | 4 +++- 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/scripts/pylib/twister/twisterlib/environment.py b/scripts/pylib/twister/twisterlib/environment.py index 5e2b3a24a5a..d94cd3ab233 100644 --- a/scripts/pylib/twister/twisterlib/environment.py +++ b/scripts/pylib/twister/twisterlib/environment.py @@ -13,6 +13,7 @@ import subprocess import shutil import re import argparse +from datetime import datetime, timezone logger = logging.getLogger('twister') logger.setLevel(logging.DEBUG) @@ -662,6 +663,8 @@ class TwisterEnv: def __init__(self, options=None) -> None: self.version = None self.toolchain = None + self.commit_date = None + self.run_date = None self.options = options if options and options.ninja: self.generator_cmd = "ninja" @@ -690,6 +693,7 @@ class TwisterEnv: def discover(self): self.check_zephyr_version() self.get_toolchain() + self.run_date = datetime.now(timezone.utc).isoformat(timespec='seconds') def check_zephyr_version(self): try: @@ -708,6 +712,14 @@ class TwisterEnv: except OSError: logger.info("Cannot read zephyr version.") + subproc = subprocess.run(["git", "show", "-s", "--format=%cI", "HEAD"], + stdout=subprocess.PIPE, + universal_newlines=True, + cwd=ZEPHYR_BASE) + if subproc.returncode == 0: + self.commit_date = subproc.stdout.strip() + else: + self.commit_date = "Unknown" @staticmethod def run_cmake_script(args=[]): diff --git a/scripts/pylib/twister/twisterlib/reports.py b/scripts/pylib/twister/twisterlib/reports.py index 70c64d5f0ed..c9686e2a6df 100644 --- a/scripts/pylib/twister/twisterlib/reports.py +++ b/scripts/pylib/twister/twisterlib/reports.py @@ -237,7 +237,9 @@ class Reporting: report = {} report["environment"] = {"os": os.name, "zephyr_version": version, - "toolchain": self.env.toolchain + "toolchain": self.env.toolchain, + "commit_date": self.env.commit_date, + "run_date": self.env.run_date } suites = []