Skip to content

Commit

Permalink
tests: allow running outside of a git repository
Browse files Browse the repository at this point in the history
Make the git information for metrics optional. Useful when running
outside of a classic git repository, for example extracted from a
tarball or a git worktree.

Signed-off-by: Pablo Barbáchano <[email protected]>
  • Loading branch information
pb8o committed Oct 5, 2023
1 parent c5bbc07 commit 304d809
Showing 1 changed file with 16 additions and 4 deletions.
20 changes: 16 additions & 4 deletions tests/framework/properties.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,13 +72,19 @@ def __init__(self):
self.os = get_os_version()
self.host_os = get_host_os()
self.libc_ver = "-".join(platform.libc_ver())
self.git_commit_id = run_cmd("git rev-parse HEAD")
self.git_branch = run_cmd("git show -s --pretty=%D HEAD")
self.git_origin_url = run_cmd("git config --get remote.origin.url")
self.rust_version = run_cmd("rustc --version |awk '{print $2}'")
self.buildkite_pipeline_slug = os.environ.get("BUILDKITE_PIPELINE_SLUG")
self.buildkite_build_number = os.environ.get("BUILDKITE_BUILD_NUMBER")

if self._in_git_repo():
self.git_commit_id = run_cmd("git rev-parse HEAD")
self.git_branch = run_cmd("git show -s --pretty=%D HEAD")
self.git_origin_url = run_cmd("git config --get remote.origin.url")
else:
self.git_commit_id = None
self.git_branch = None
self.git_origin_url = None

self.environment = self._detect_environment()
if self.is_ec2:
self.instance = imdsv2_get("/meta-data/instance-type")
Expand All @@ -105,6 +111,12 @@ def _detect_environment(self):
except Exception:
return "local"

def _in_git_repo(self):
try:
run_cmd("git rev-parse --show-toplevel")
except subprocess.CalledProcessError:
return False
return True


global_props = GlobalProps()
# TBD could do a props fixture for tests to use...

0 comments on commit 304d809

Please sign in to comment.