@@ -58,45 +58,58 @@ def extract_timestamp(file_path: Path) -> str:
5858 self .runs = benchmark_runs
5959
6060 def create_run (self , name : str , results : list [Result ]) -> BenchmarkRun :
61- try :
62- script_dir = os .path .dirname (os .path .abspath (__file__ ))
63- result = run ("git rev-parse --short HEAD" , cwd = script_dir )
64- git_hash = result .stdout .decode ().strip ()
65-
66- # Get the GitHub repo URL from git remote
67- remote_result = run ("git remote get-url origin" , cwd = script_dir )
68- remote_url = remote_result .stdout .decode ().strip ()
69-
70- # Convert SSH or HTTPS URL to owner/repo format
71- if remote_url .
startswith (
"[email protected] :" ):
72- # SSH format: [email protected] :owner/repo.git 73- github_repo = remote_url .
split (
"[email protected] :" )[
1 ].
rstrip (
".git" )
74- elif remote_url .startswith ("https://github.com/" ):
75- # HTTPS format: https://github.com/owner/repo.git
76- github_repo = remote_url .split ("https://github.com/" )[1 ].rstrip (".git" )
77- else :
61+
62+ def git_info_from_path (path : Path ) -> (str , str ):
63+ """
64+ Derives git repo, commit information from git repo located in path.
65+
66+ Returns:
67+ (str, str): git_hash, github_repo
68+ """
69+ try :
70+ result = run ("git rev-parse --short HEAD" , cwd = path )
71+ git_hash = result .stdout .decode ().strip ()
72+
73+ # Get the GitHub repo URL from git remote
74+ remote_result = run ("git remote get-url origin" , cwd = path )
75+ remote_url = remote_result .stdout .decode ().strip ()
76+
77+ # Convert SSH or HTTPS URL to owner/repo format
78+ if remote_url .
startswith (
"[email protected] :" ):
79+ # SSH format: [email protected] :owner/repo.git 80+ github_repo = remote_url .
split (
"[email protected] :" )[
1 ].
rstrip (
".git" )
81+ elif remote_url .startswith ("https://github.com/" ):
82+ # HTTPS format: https://github.com/owner/repo.git
83+ github_repo = remote_url .split ("https://github.com/" )[1 ].rstrip (".git" )
84+ else :
85+ github_repo = None
86+
87+ except :
88+ git_hash = "unknown"
7889 github_repo = None
90+
91+ return git_hash , github_repo
7992
80- except :
81- git_hash = "unknown"
82- github_repo = None
93+ if options .sycl_commit is None or options .sycl_github_repo is None :
94+ git_hash , github_repo = git_info_from_path (os .path .dirname (os .path .abspath (__file__ )))
95+ else :
96+ git_hash , github_repo = options .sycl_commit , options .sycl_github_repo
8397
8498 # Check if RUNNER_NAME environment variable has been declared.
8599 #
86- # RUNNER_NAME is always present in github runner environments. Because
87- # github runners obfusicate hostnames, using socket.gethostname()
88- # produces different hostnames when ran on the same machine multiple
89- # times. Thus, we rely on the RUNNER_NAME variable when running on
90- # github runners.
100+ # Github runners obfusicate hostnames, thus running socket.gethostname()
101+ # twice produces two different hostnames. Since github runners always
102+ # define a RUNNER_NAME variable, use RUNNER_NAME instead if it exists:
91103 hostname = os .getenv ("RUNNER_NAME" )
92104 if hostname is None :
93105 hostname = socket .gethostname ()
94- elif not Validate .runner_name (hostname ):
95- # However, nothing stops github runner env variables (including
96- # RUNNER_NAME) from being modified by external actors. Ensure
97- # RUNNER_NAME contains nothing malicious:
106+ else :
107+ # Ensure RUNNER_NAME has not been tampered with:
98108 # TODO is this overkill?
99- raise ValueError ("Illegal characters found in specified RUNNER_NAME." )
109+ Validate .runner_name (
110+ hostname ,
111+ throw = ValueError ("Illegal characters found in specified RUNNER_NAME." )
112+ )
100113
101114 return BenchmarkRun (
102115 name = name ,
0 commit comments