From f7868d3a478148dbeeb66fefb32e334eb6c66757 Mon Sep 17 00:00:00 2001 From: Jason Boutte Date: Mon, 30 Oct 2023 17:12:11 -0700 Subject: [PATCH] Adds commit hash and date to baseline files --- CIME/baselines/performance.py | 7 ++++++- CIME/tests/test_unit_system_tests.py | 11 +++++++---- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/CIME/baselines/performance.py b/CIME/baselines/performance.py index 0fcb729d1d5..fe940309b28 100644 --- a/CIME/baselines/performance.py +++ b/CIME/baselines/performance.py @@ -4,7 +4,7 @@ import gzip import logging from CIME.config import Config -from CIME.utils import expect +from CIME.utils import expect, get_src_root, get_current_commit, get_timestamp logger = logging.getLogger(__name__) @@ -238,7 +238,12 @@ def write_baseline_file(baseline_file, value): value : str Value to write. """ + commit_hash = get_current_commit(repo=get_src_root()) + + timestamp = get_timestamp(timestamp_format="%Y-%m-%d_%H:%M:%S") + with open(baseline_file, "w") as fd: + fd.write(f"# sha:{commit_hash} date: {timestamp}\n") fd.write(value) diff --git a/CIME/tests/test_unit_system_tests.py b/CIME/tests/test_unit_system_tests.py index 99486178f36..609460fe9c0 100644 --- a/CIME/tests/test_unit_system_tests.py +++ b/CIME/tests/test_unit_system_tests.py @@ -3,6 +3,7 @@ import os import tempfile import gzip +import re from re import A import unittest from unittest import mock @@ -508,14 +509,16 @@ def test_generate_baseline(self): with open(baseline_dir / "cpl-tput.log") as fd: lines = fd.readlines() - assert len(lines) == 1 - assert lines[0] == "719.635" + assert len(lines) == 2 + assert re.match("# sha:.* date:.*", lines[0]) + assert lines[1] == "719.635" with open(baseline_dir / "cpl-mem.log") as fd: lines = fd.readlines() - assert len(lines) == 1 - assert lines[0] == "1673.89" + assert len(lines) == 2 + assert re.match("# sha:.* date:.*", lines[0]) + assert lines[1] == "1673.89" def test_kwargs(self): case = mock.MagicMock()