From a1eb6de19cbf9cd591e37b84acbe9900e4057071 Mon Sep 17 00:00:00 2001 From: Brian Kroth Date: Tue, 24 Jun 2025 15:38:10 +0200 Subject: [PATCH 01/14] Fixups and improvements to git info retrieval --- mlos_bench/mlos_bench/tests/util_git_test.py | 72 +++++++++- mlos_bench/mlos_bench/util.py | 142 +++++++++++++++++-- 2 files changed, 197 insertions(+), 17 deletions(-) diff --git a/mlos_bench/mlos_bench/tests/util_git_test.py b/mlos_bench/mlos_bench/tests/util_git_test.py index 77fd2779c77..8985e201e68 100644 --- a/mlos_bench/mlos_bench/tests/util_git_test.py +++ b/mlos_bench/mlos_bench/tests/util_git_test.py @@ -3,14 +3,80 @@ # Licensed under the MIT License. # """Unit tests for get_git_info utility function.""" +import os import re +import tempfile +from pathlib import Path +from subprocess import CalledProcessError -from mlos_bench.util import get_git_info +import pytest + +from mlos_bench.util import get_git_info, get_git_root, path_join def test_get_git_info() -> None: - """Check that we can retrieve git info about the current repository correctly.""" - (git_repo, git_commit, rel_path) = get_git_info(__file__) + """Check that we can retrieve git info about the current repository correctly from a + file. + """ + (git_repo, git_commit, rel_path, abs_path) = get_git_info(__file__) assert "mlos" in git_repo.lower() assert re.match(r"[0-9a-f]{40}", git_commit) is not None assert rel_path == "mlos_bench/mlos_bench/tests/util_git_test.py" + assert abs_path == path_join(__file__, abs_path=True) + + +def test_get_git_info_dir() -> None: + """Check that we can retrieve git info about the current repository correctly from a + directory. + """ + dirname = os.path.dirname(__file__) + (git_repo, git_commit, rel_path, abs_path) = get_git_info(dirname) + assert "mlos" in git_repo.lower() + assert re.match(r"[0-9a-f]{40}", git_commit) is not None + assert rel_path == "mlos_bench/mlos_bench/tests" + assert abs_path == path_join(dirname, abs_path=True) + + +def test_non_git_dir() -> None: + """Check that we can handle a non-git directory.""" + with tempfile.TemporaryDirectory() as non_git_dir: + with pytest.raises(CalledProcessError): + # This should raise an error because the directory is not a git repository. + get_git_root(non_git_dir) + + +def test_non_upstream_git() -> None: + """Check that we can handle a git directory without an upstream.""" + with tempfile.TemporaryDirectory() as non_upstream_git_dir: + non_upstream_git_dir = path_join(non_upstream_git_dir, abs_path=True) + # Initialize a new git repository. + os.system(f"git init {non_upstream_git_dir} -b main") + os.system(f"git -C {non_upstream_git_dir} config --local user.email 'pytest@example.com'") + os.system(f"git -C {non_upstream_git_dir} config --local user.name 'PyTest User'") + Path(non_upstream_git_dir).joinpath("README.md").touch() + os.system(f"git -C {non_upstream_git_dir} add README.md") + os.system(f"git -C {non_upstream_git_dir} commit -m 'Initial commit'") + # This should raise an error because the repository has no upstream. + (git_repo, _git_commit, rel_path, abs_path) = get_git_info(non_upstream_git_dir) + assert git_repo == f"file://{non_upstream_git_dir}" + assert abs_path == non_upstream_git_dir + assert rel_path == "." + + +@pytest.mark.skipif( + os.environ.get("GITHUB_ACTIONS") != "true", + reason="Not running in GitHub Actions CI.", +) +def test_github_actions_git_info() -> None: + """Test that get_git_info matches GitHub Actions environment variables if running in + CI. + """ + repo_env = os.environ.get("GITHUB_REPOSITORY") # "owner/repo" format + sha_env = os.environ.get("GITHUB_SHA") + assert repo_env, "GITHUB_REPOSITORY not set in environment." + assert sha_env, "GITHUB_SHA not set in environment." + git_repo, git_commit, _rel_path, _abs_path = get_git_info(__file__) + assert git_repo.endswith(repo_env), f"git_repo '{git_repo}' does not end with '{repo_env}'" + assert ( + git_commit == sha_env + ), f"git_commit '{git_commit}' does not match GITHUB_SHA '{sha_env}'" diff --git a/mlos_bench/mlos_bench/util.py b/mlos_bench/mlos_bench/util.py index 7cf9bc640c5..0f1e3d2ef7b 100644 --- a/mlos_bench/mlos_bench/util.py +++ b/mlos_bench/mlos_bench/util.py @@ -153,7 +153,7 @@ def path_join(*args: str, abs_path: bool = False) -> str: """ path = os.path.join(*args) if abs_path: - path = os.path.abspath(path) + path = os.path.realpath(path) return os.path.normpath(path).replace("\\", "/") @@ -274,33 +274,147 @@ def check_required_params(config: Mapping[str, Any], required_params: Iterable[s ) -def get_git_info(path: str = __file__) -> tuple[str, str, str]: +def get_git_root(path: str = __file__) -> str: """ - Get the git repository, commit hash, and local path of the given file. + Get the root dir of the git repository. + + Parameters + ---------- + path : str, optional + Path to the file in git repository. + + Raises + ------ + subprocess.CalledProcessError + If the path is not a git repository or the command fails. + + Returns + ------- + str + The absolute path to the root directory of the git repository. + """ + abspath = path_join(path, abs_path=True) + if not os.path.exists(abspath) or not os.path.isdir(abspath): + dirname = os.path.dirname(abspath) + else: + dirname = abspath + git_root = subprocess.check_output( + ["git", "-C", dirname, "rev-parse", "--show-toplevel"], + text=True, + ).strip() + return path_join(git_root, abs_path=True) + + +def get_git_remote_info(path: str, remote: str) -> str: + """ + Gets the remote URL for the given remote name in the git repository. Parameters ---------- path : str Path to the file in git repository. + remote : str + The name of the remote (e.g., "origin"). + + Raises + ------ + subprocess.CalledProcessError + If the command fails or the remote does not exist. Returns ------- - (git_repo, git_commit, git_path) : tuple[str, str, str] - Git repository URL, last commit hash, and relative file path. + str + The URL of the remote repository. """ - dirname = os.path.dirname(path) - git_repo = subprocess.check_output( - ["git", "-C", dirname, "remote", "get-url", "origin"], text=True + return subprocess.check_output( + ["git", "-C", path, "remote", "get-url", remote], text=True ).strip() + + +def get_git_repo_info(path: str) -> str: + """ + Get the git repository URL for the given git repo. + + Tries to get the upstream branch URL, falling back to the "origin" remote + if the upstream branch is not set or does not exist. If that also fails, + it returns a file URL pointing to the local path. + + Parameters + ---------- + path : str + Path to the git repository. + + Raises + ------ + subprocess.CalledProcessError + If the command fails or the git repository does not exist. + + Returns + ------- + str + The upstream URL of the git repository. + """ + # In case "origin" remote is not set, or this branch has a different + # upstream, we should handle it gracefully. + # (e.g., fallback to the first one we find?) + path = path_join(path, abs_path=True) + cmd = ["git", "-C", path, "rev-parse", "--abbrev-ref", "--symbolic-full-name", "HEAD@{u}"] + try: + git_remote = subprocess.check_output(cmd, text=True).strip() + git_remote = git_remote.split("/", 1)[0] + git_repo = get_git_remote_info(path, git_remote) + except subprocess.CalledProcessError: + git_remote = "origin" + _LOG.warning( + "Failed to get the upstream branch for %s. Falling back to '%s' remote.", + path, + git_remote, + ) + try: + git_repo = get_git_remote_info(path, git_remote) + except subprocess.CalledProcessError: + git_repo = "file://" + path + _LOG.warning( + "Failed to get the upstream branch for %s. Falling back to '%s'.", + path, + git_repo, + ) + return git_repo + + +def get_git_info(path: str = __file__) -> tuple[str, str, str, str]: + """ + Get the git repository, commit hash, and local path of the given file. + + Parameters + ---------- + path : str + Path to the file in git repository. + + Raises + ------ + subprocess.CalledProcessError + If the path is not a git repository or the command fails. + + Returns + ------- + (git_repo, git_commit, rel_path, abs_path) : tuple[str, str, str, str] + Git repository URL, last commit hash, and relative file path and current + absolute path. + """ + abspath = path_join(path, abs_path=True) + if not os.path.exists(abspath) or not os.path.isdir(abspath): + dirname = os.path.dirname(abspath) + else: + dirname = abspath + git_root = get_git_root(path=abspath) + git_repo = get_git_repo_info(git_root) git_commit = subprocess.check_output( ["git", "-C", dirname, "rev-parse", "HEAD"], text=True ).strip() - git_root = subprocess.check_output( - ["git", "-C", dirname, "rev-parse", "--show-toplevel"], text=True - ).strip() - _LOG.debug("Current git branch: %s %s", git_repo, git_commit) - rel_path = os.path.relpath(os.path.abspath(path), os.path.abspath(git_root)) - return (git_repo, git_commit, rel_path.replace("\\", "/")) + _LOG.debug("Current git branch for %s: %s %s", git_root, git_repo, git_commit) + rel_path = os.path.relpath(abspath, os.path.abspath(git_root)) + return (git_repo, git_commit, rel_path.replace("\\", "/"), abspath) # Note: to avoid circular imports, we don't specify TunableValue here. From d0f8e74ea696968cb8a6d544088d082dde44165e Mon Sep 17 00:00:00 2001 From: Brian Kroth Date: Tue, 24 Jun 2025 15:50:36 +0200 Subject: [PATCH 02/14] comments --- mlos_bench/mlos_bench/tests/util_git_test.py | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/mlos_bench/mlos_bench/tests/util_git_test.py b/mlos_bench/mlos_bench/tests/util_git_test.py index 8985e201e68..6b199a5eddf 100644 --- a/mlos_bench/mlos_bench/tests/util_git_test.py +++ b/mlos_bench/mlos_bench/tests/util_git_test.py @@ -68,9 +68,24 @@ def test_non_upstream_git() -> None: reason="Not running in GitHub Actions CI.", ) def test_github_actions_git_info() -> None: - """Test that get_git_info matches GitHub Actions environment variables if running in - CI. """ + Test that get_git_info matches GitHub Actions environment variables if + running in CI. + + Examples + -------- + Test locally with the following command: + + .. code-block:: shell + + export GITHUB_ACTIONS=true + GITHUB_SHA=$(git rev-parse HEAD) + # GITHUB_REPOSITORY should be in "owner/repo" format. + # e.g., GITHUB_REPOSITORY="bpkroth/MLOS" or "microsoft/MLOS" + GITHUB_REPOSITORY=$(git rev-parse --abbrev-ref --symbolic-full-name HEAD@{u} | cut -d/ -f1 | xargs git remote get-url | grep https://github.com | cut -d/ -f4-) + pytest -n0 mlos_bench/mlos_bench/tests/util_git_test.py + ``` + """ # pylint: disable=line-too-long # noqa: E501 repo_env = os.environ.get("GITHUB_REPOSITORY") # "owner/repo" format sha_env = os.environ.get("GITHUB_SHA") assert repo_env, "GITHUB_REPOSITORY not set in environment." From f7d91a74a76953e99075797d4ca5ad5a8ef6f282 Mon Sep 17 00:00:00 2001 From: Brian Kroth Date: Tue, 24 Jun 2025 15:53:09 +0200 Subject: [PATCH 03/14] tweaks --- mlos_bench/mlos_bench/storage/base_storage.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mlos_bench/mlos_bench/storage/base_storage.py b/mlos_bench/mlos_bench/storage/base_storage.py index 75a84bf0b2e..de81bb94d7d 100644 --- a/mlos_bench/mlos_bench/storage/base_storage.py +++ b/mlos_bench/mlos_bench/storage/base_storage.py @@ -194,7 +194,7 @@ def __init__( # pylint: disable=too-many-arguments self._tunables = tunables.copy() self._trial_id = trial_id self._experiment_id = experiment_id - (self._git_repo, self._git_commit, self._root_env_config) = get_git_info( + (self._git_repo, self._git_commit, self._root_env_config, _future_pr) = get_git_info( root_env_config ) self._description = description From 739c3cec72a552340436708650f8bde82867c2f9 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Tue, 24 Jun 2025 13:53:36 +0000 Subject: [PATCH 04/14] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- mlos_bench/mlos_bench/tests/util_git_test.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/mlos_bench/mlos_bench/tests/util_git_test.py b/mlos_bench/mlos_bench/tests/util_git_test.py index 6b199a5eddf..2d215a43323 100644 --- a/mlos_bench/mlos_bench/tests/util_git_test.py +++ b/mlos_bench/mlos_bench/tests/util_git_test.py @@ -69,8 +69,8 @@ def test_non_upstream_git() -> None: ) def test_github_actions_git_info() -> None: """ - Test that get_git_info matches GitHub Actions environment variables if - running in CI. + Test that get_git_info matches GitHub Actions environment variables if running in + CI. Examples -------- From a0dd7b70c35e807964c803874c19e98fce1a9b39 Mon Sep 17 00:00:00 2001 From: Brian Kroth Date: Tue, 24 Jun 2025 16:04:02 +0200 Subject: [PATCH 05/14] tweak --- mlos_bench/mlos_bench/tests/util_git_test.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mlos_bench/mlos_bench/tests/util_git_test.py b/mlos_bench/mlos_bench/tests/util_git_test.py index 2d215a43323..864231baa9b 100644 --- a/mlos_bench/mlos_bench/tests/util_git_test.py +++ b/mlos_bench/mlos_bench/tests/util_git_test.py @@ -84,7 +84,7 @@ def test_github_actions_git_info() -> None: # e.g., GITHUB_REPOSITORY="bpkroth/MLOS" or "microsoft/MLOS" GITHUB_REPOSITORY=$(git rev-parse --abbrev-ref --symbolic-full-name HEAD@{u} | cut -d/ -f1 | xargs git remote get-url | grep https://github.com | cut -d/ -f4-) pytest -n0 mlos_bench/mlos_bench/tests/util_git_test.py - ``` + """ # pylint: disable=line-too-long # noqa: E501 repo_env = os.environ.get("GITHUB_REPOSITORY") # "owner/repo" format sha_env = os.environ.get("GITHUB_SHA") From 942d57baa693cfccbb831c68f13707e81aebbc19 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Tue, 24 Jun 2025 14:04:31 +0000 Subject: [PATCH 06/14] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- mlos_bench/mlos_bench/tests/util_git_test.py | 1 - 1 file changed, 1 deletion(-) diff --git a/mlos_bench/mlos_bench/tests/util_git_test.py b/mlos_bench/mlos_bench/tests/util_git_test.py index 864231baa9b..6990ca6abb4 100644 --- a/mlos_bench/mlos_bench/tests/util_git_test.py +++ b/mlos_bench/mlos_bench/tests/util_git_test.py @@ -84,7 +84,6 @@ def test_github_actions_git_info() -> None: # e.g., GITHUB_REPOSITORY="bpkroth/MLOS" or "microsoft/MLOS" GITHUB_REPOSITORY=$(git rev-parse --abbrev-ref --symbolic-full-name HEAD@{u} | cut -d/ -f1 | xargs git remote get-url | grep https://github.com | cut -d/ -f4-) pytest -n0 mlos_bench/mlos_bench/tests/util_git_test.py - """ # pylint: disable=line-too-long # noqa: E501 repo_env = os.environ.get("GITHUB_REPOSITORY") # "owner/repo" format sha_env = os.environ.get("GITHUB_SHA") From 6d563a8c5e53e4725893d821d60784e310642625 Mon Sep 17 00:00:00 2001 From: Brian Kroth Date: Tue, 24 Jun 2025 19:21:33 +0200 Subject: [PATCH 07/14] refactor --- mlos_bench/mlos_bench/tests/util_git_test.py | 24 ++++++++++---------- 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/mlos_bench/mlos_bench/tests/util_git_test.py b/mlos_bench/mlos_bench/tests/util_git_test.py index 6990ca6abb4..06cfdba8f0a 100644 --- a/mlos_bench/mlos_bench/tests/util_git_test.py +++ b/mlos_bench/mlos_bench/tests/util_git_test.py @@ -7,7 +7,7 @@ import re import tempfile from pathlib import Path -from subprocess import CalledProcessError +from subprocess import CalledProcessError, check_call as run import pytest @@ -47,19 +47,19 @@ def test_non_git_dir() -> None: def test_non_upstream_git() -> None: """Check that we can handle a git directory without an upstream.""" - with tempfile.TemporaryDirectory() as non_upstream_git_dir: - non_upstream_git_dir = path_join(non_upstream_git_dir, abs_path=True) + with tempfile.TemporaryDirectory() as local_git_dir: + local_git_dir = path_join(local_git_dir, abs_path=True) # Initialize a new git repository. - os.system(f"git init {non_upstream_git_dir} -b main") - os.system(f"git -C {non_upstream_git_dir} config --local user.email 'pytest@example.com'") - os.system(f"git -C {non_upstream_git_dir} config --local user.name 'PyTest User'") - Path(non_upstream_git_dir).joinpath("README.md").touch() - os.system(f"git -C {non_upstream_git_dir} add README.md") - os.system(f"git -C {non_upstream_git_dir} commit -m 'Initial commit'") + run(["git", "init", local_git_dir, "-b", "main"]) + run(["git", "-C", local_git_dir, "config", "--local", "user.email", "pytest@example.com"]) + run(["git", "-C", local_git_dir, "config", "--local", "user.name", "PyTest User"]) + Path(local_git_dir).joinpath("README.md").touch() + run(["git", "-C", local_git_dir, "add", "README.md"]) + run(["git", "-C", local_git_dir, "commit", "-m", "Initial commit"]) # This should raise an error because the repository has no upstream. - (git_repo, _git_commit, rel_path, abs_path) = get_git_info(non_upstream_git_dir) - assert git_repo == f"file://{non_upstream_git_dir}" - assert abs_path == non_upstream_git_dir + (git_repo, _git_commit, rel_path, abs_path) = get_git_info(local_git_dir) + assert git_repo == f"file://{local_git_dir}" + assert abs_path == local_git_dir assert rel_path == "." From 4e33efb34424c21aef93a4943341020bd9d172b8 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Tue, 24 Jun 2025 17:22:06 +0000 Subject: [PATCH 08/14] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- mlos_bench/mlos_bench/tests/util_git_test.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/mlos_bench/mlos_bench/tests/util_git_test.py b/mlos_bench/mlos_bench/tests/util_git_test.py index 06cfdba8f0a..f532a1feca7 100644 --- a/mlos_bench/mlos_bench/tests/util_git_test.py +++ b/mlos_bench/mlos_bench/tests/util_git_test.py @@ -7,7 +7,8 @@ import re import tempfile from pathlib import Path -from subprocess import CalledProcessError, check_call as run +from subprocess import CalledProcessError +from subprocess import check_call as run import pytest From 8f8f0bb4c01e16d8a7e5845d231b1a0323601483 Mon Sep 17 00:00:00 2001 From: Brian Kroth Date: Tue, 24 Jun 2025 19:27:57 +0200 Subject: [PATCH 09/14] comment --- mlos_bench/mlos_bench/tests/util_git_test.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mlos_bench/mlos_bench/tests/util_git_test.py b/mlos_bench/mlos_bench/tests/util_git_test.py index f532a1feca7..1956c501e5a 100644 --- a/mlos_bench/mlos_bench/tests/util_git_test.py +++ b/mlos_bench/mlos_bench/tests/util_git_test.py @@ -57,7 +57,7 @@ def test_non_upstream_git() -> None: Path(local_git_dir).joinpath("README.md").touch() run(["git", "-C", local_git_dir, "add", "README.md"]) run(["git", "-C", local_git_dir, "commit", "-m", "Initial commit"]) - # This should raise an error because the repository has no upstream. + # This should have slightly different behavior when there is no upstream. (git_repo, _git_commit, rel_path, abs_path) = get_git_info(local_git_dir) assert git_repo == f"file://{local_git_dir}" assert abs_path == local_git_dir From 2257e17e9b9b6c7e526d83d3799566b240db72a7 Mon Sep 17 00:00:00 2001 From: Brian Kroth Date: Tue, 24 Jun 2025 19:30:13 +0200 Subject: [PATCH 10/14] format --- mlos_bench/mlos_bench/util.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/mlos_bench/mlos_bench/util.py b/mlos_bench/mlos_bench/util.py index 0f1e3d2ef7b..4d42100b8c7 100644 --- a/mlos_bench/mlos_bench/util.py +++ b/mlos_bench/mlos_bench/util.py @@ -299,8 +299,7 @@ def get_git_root(path: str = __file__) -> str: else: dirname = abspath git_root = subprocess.check_output( - ["git", "-C", dirname, "rev-parse", "--show-toplevel"], - text=True, + ["git", "-C", dirname, "rev-parse", "--show-toplevel"], text=True ).strip() return path_join(git_root, abs_path=True) From 01e844a484851000dd8e1e40ad397c33cdce1aac Mon Sep 17 00:00:00 2001 From: Brian Kroth Date: Tue, 24 Jun 2025 19:33:44 +0200 Subject: [PATCH 11/14] comments --- mlos_bench/mlos_bench/util.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/mlos_bench/mlos_bench/util.py b/mlos_bench/mlos_bench/util.py index 4d42100b8c7..945143defce 100644 --- a/mlos_bench/mlos_bench/util.py +++ b/mlos_bench/mlos_bench/util.py @@ -413,9 +413,13 @@ def get_git_info(path: str = __file__) -> tuple[str, str, str, str]: ).strip() _LOG.debug("Current git branch for %s: %s %s", git_root, git_repo, git_commit) rel_path = os.path.relpath(abspath, os.path.abspath(git_root)) + # TODO: return the branch too? return (git_repo, git_commit, rel_path.replace("\\", "/"), abspath) +# TODO: Add support for checking out the branch locally. + + # Note: to avoid circular imports, we don't specify TunableValue here. def try_parse_val(val: str | None) -> int | float | str | None: """ From 0357849867717d07a289f686ae674c8cb4940471 Mon Sep 17 00:00:00 2001 From: Brian Kroth Date: Tue, 24 Jun 2025 20:18:34 +0200 Subject: [PATCH 12/14] fixup --- mlos_bench/mlos_bench/util.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mlos_bench/mlos_bench/util.py b/mlos_bench/mlos_bench/util.py index 945143defce..006e0e0a544 100644 --- a/mlos_bench/mlos_bench/util.py +++ b/mlos_bench/mlos_bench/util.py @@ -280,7 +280,7 @@ def get_git_root(path: str = __file__) -> str: Parameters ---------- - path : str, optional + path : Optional[str] Path to the file in git repository. Raises From c7245a2fbebf28d0192e4f73ff3b4fc7225498c3 Mon Sep 17 00:00:00 2001 From: Brian Kroth Date: Tue, 24 Jun 2025 20:23:36 +0200 Subject: [PATCH 13/14] fix docs --- mlos_bench/mlos_bench/tests/util_git_test.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/mlos_bench/mlos_bench/tests/util_git_test.py b/mlos_bench/mlos_bench/tests/util_git_test.py index 1956c501e5a..88fae7c7f40 100644 --- a/mlos_bench/mlos_bench/tests/util_git_test.py +++ b/mlos_bench/mlos_bench/tests/util_git_test.py @@ -80,10 +80,10 @@ def test_github_actions_git_info() -> None: .. code-block:: shell export GITHUB_ACTIONS=true - GITHUB_SHA=$(git rev-parse HEAD) + export GITHUB_SHA=$(git rev-parse HEAD) # GITHUB_REPOSITORY should be in "owner/repo" format. # e.g., GITHUB_REPOSITORY="bpkroth/MLOS" or "microsoft/MLOS" - GITHUB_REPOSITORY=$(git rev-parse --abbrev-ref --symbolic-full-name HEAD@{u} | cut -d/ -f1 | xargs git remote get-url | grep https://github.com | cut -d/ -f4-) + export GITHUB_REPOSITORY=$(git rev-parse --abbrev-ref --symbolic-full-name HEAD@{u} | cut -d/ -f1 | xargs git remote get-url | grep https://github.com | cut -d/ -f4-) pytest -n0 mlos_bench/mlos_bench/tests/util_git_test.py """ # pylint: disable=line-too-long # noqa: E501 repo_env = os.environ.get("GITHUB_REPOSITORY") # "owner/repo" format From 9fc529f94806614e9995b1189db4a453a78a364c Mon Sep 17 00:00:00 2001 From: Brian Kroth Date: Wed, 2 Jul 2025 17:18:45 -0500 Subject: [PATCH 14/14] Update mlos_bench/mlos_bench/util.py Co-authored-by: Sergiy Matusevych --- mlos_bench/mlos_bench/util.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/mlos_bench/mlos_bench/util.py b/mlos_bench/mlos_bench/util.py index 006e0e0a544..fe09a013fd1 100644 --- a/mlos_bench/mlos_bench/util.py +++ b/mlos_bench/mlos_bench/util.py @@ -402,10 +402,10 @@ def get_git_info(path: str = __file__) -> tuple[str, str, str, str]: absolute path. """ abspath = path_join(path, abs_path=True) - if not os.path.exists(abspath) or not os.path.isdir(abspath): - dirname = os.path.dirname(abspath) - else: + if os.path.exists(abspath) and os.path.isdir(abspath): dirname = abspath + else: + dirname = os.path.dirname(abspath) git_root = get_git_root(path=abspath) git_repo = get_git_repo_info(git_root) git_commit = subprocess.check_output(