11# Telemetry functionality for sharing benchmark results
22
3+ """
4+ get_gh_command()
5+
6+ Get the gh command, preferring the system-installed version if available,
7+ falling back to the JLL-provided version.
8+ """
9+ function get_gh_command ()
10+ # First check if gh is installed on the system
11+ if ! isnothing (Sys. which (" gh" ))
12+ return ` gh`
13+ else
14+ # Use the JLL-provided gh
15+ return ` $(gh_cli_jll. gh ()) `
16+ end
17+ end
18+
319"""
420 setup_github_authentication(; auto_login::Bool = true)
521
@@ -8,21 +24,22 @@ If auto_login is true and no authentication is found, will prompt to run gh auth
824Returns an authentication method indicator if successful, nothing if setup fails.
925"""
1026function setup_github_authentication (; auto_login:: Bool = true )
11- # 1. Check for `gh` CLI
12- if ! isnothing (Sys. which (" gh" ))
13- try
14- # Suppress output of gh auth status check
15- if success (pipeline (` gh auth status` ; stdout = devnull , stderr = devnull ))
16- # Check if logged in to github.com
17- auth_status_output = read (` gh auth status` , String)
18- if contains (auth_status_output, " Logged in to github.com" )
19- println (" ✅ Found active `gh` CLI session. Will use it for upload." )
20- return (:gh_cli , " GitHub CLI" )
21- end
27+ # 1. Check for `gh` CLI (system or JLL)
28+ gh_cmd = get_gh_command ()
29+
30+ # First check if already authenticated
31+ try
32+ # Suppress output of gh auth status check
33+ if success (pipeline (` $gh_cmd auth status` ; stdout = devnull , stderr = devnull ))
34+ # Check if logged in to github.com
35+ auth_status_output = read (` $gh_cmd auth status` , String)
36+ if contains (auth_status_output, " Logged in to github.com" )
37+ println (" ✅ Found active `gh` CLI session. Will use it for upload." )
38+ return (:gh_cli , " GitHub CLI" )
2239 end
23- catch e
24- @debug " gh CLI check failed: $e "
2540 end
41+ catch e
42+ @debug " gh CLI auth status check failed: $e "
2643 end
2744
2845 # 2. Check for GITHUB_TOKEN environment variable
@@ -34,8 +51,8 @@ function setup_github_authentication(; auto_login::Bool = true)
3451 end
3552 end
3653
37- # 3. If auto_login is enabled and gh is installed , offer to authenticate
38- if auto_login && ! isnothing (Sys . which ( " gh " ))
54+ # 3. If auto_login is enabled, offer to authenticate
55+ if auto_login
3956 println (" \n 🔐 GitHub authentication not found." )
4057 println (" To share results with the community, authentication is required." )
4158 println (" \n Would you like to authenticate with GitHub now? (y/n)" )
@@ -48,12 +65,12 @@ function setup_github_authentication(; auto_login::Bool = true)
4865 println (" Please follow the prompts to complete authentication.\n " )
4966
5067 try
51- # Run gh auth login interactively
52- run (` gh auth login` )
68+ # Run gh auth login interactively (using system gh or JLL)
69+ run (` $gh_cmd auth login` )
5370
5471 # Check if authentication succeeded
55- if success (pipeline (` gh auth status` ; stdout = devnull , stderr = devnull ))
56- auth_status_output = read (` gh auth status` , String)
72+ if success (pipeline (` $gh_cmd auth status` ; stdout = devnull , stderr = devnull ))
73+ auth_status_output = read (` $gh_cmd auth status` , String)
5774 if contains (auth_status_output, " Logged in to github.com" )
5875 println (" \n ✅ Authentication successful! You can now share results." )
5976 return (:gh_cli , " GitHub CLI" )
@@ -569,6 +586,7 @@ function upload_plots_to_gist_gh(plot_files::Union{Nothing, Tuple, Dict}, eltype
569586 end
570587
571588 try
589+ gh_cmd = get_gh_command ()
572590 # Handle different plot_files formats
573591 files_to_upload = if isa (plot_files, Tuple)
574592 # Legacy format: (png_file, pdf_file)
@@ -622,7 +640,7 @@ The PNG images can be viewed directly in the browser. Click on any `.png` file a
622640 # Create initial gist with README
623641 out = Pipe ()
624642 err = Pipe ()
625- run (pipeline (` gh gist create -d $gist_desc -p $readme_file ` , stdout = out, stderr = err))
643+ run (pipeline (` $gh_cmd gist create -d $gist_desc -p $readme_file ` , stdout = out, stderr = err))
626644 close (out. in)
627645 close (err. in)
628646
@@ -640,7 +658,7 @@ The PNG images can be viewed directly in the browser. Click on any `.png` file a
640658 temp_dir = mktempdir ()
641659 try
642660 # Clone the gist
643- run (` gh gist clone $gist_id $temp_dir ` )
661+ run (` $gh_cmd gist clone $gist_id $temp_dir ` )
644662
645663 # Copy all plot files to the gist directory
646664 for (name, filepath) in existing_files
@@ -659,7 +677,7 @@ The PNG images can be viewed directly in the browser. Click on any `.png` file a
659677
660678 # Get username for constructing raw URLs
661679 username_out = Pipe ()
662- run (pipeline (` gh api user --jq .login` , stdout = username_out))
680+ run (pipeline (` $gh_cmd api user --jq .login` , stdout = username_out))
663681 close (username_out. in)
664682 username = strip (read (username_out, String))
665683
@@ -710,13 +728,14 @@ function comment_on_issue_gh(target_repo, issue_number, body)
710728 err_str = " "
711729 out_str = " "
712730 try
731+ gh_cmd = get_gh_command ()
713732 # Use a temporary file for the body to avoid command line length limits
714733 mktemp () do path, io
715734 write (io, body)
716735 flush (io)
717736
718737 # Construct and run the gh command
719- cmd = ` gh issue comment $issue_number --repo $target_repo --body-file $path `
738+ cmd = ` $gh_cmd issue comment $issue_number --repo $target_repo --body-file $path `
720739
721740 out = Pipe ()
722741 err = Pipe ()
@@ -762,13 +781,14 @@ function create_benchmark_issue_gh(target_repo, title, body)
762781 err_str = " "
763782 out_str = " "
764783 try
784+ gh_cmd = get_gh_command ()
765785 # Use a temporary file for the body to avoid command line length limits
766786 mktemp () do path, io
767787 write (io, body)
768788 flush (io)
769789
770790 # Construct and run the gh command
771- cmd = ` gh issue create --repo $target_repo --title $title --body-file $path --label benchmark-data`
791+ cmd = ` $gh_cmd issue create --repo $target_repo --title $title --body-file $path --label benchmark-data`
772792
773793 out = Pipe ()
774794 err = Pipe ()
0 commit comments