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()
521
622Set up GitHub authentication for telemetry uploads.
723Returns an authentication method indicator if successful, nothing if setup fails.
824"""
925function setup_github_authentication ()
10- # 1. Check for `gh` CLI
11- if ! isnothing (Sys. which (" gh" ))
12- try
13- # Suppress output of gh auth status check
14- if success (pipeline (` gh auth status` ; stdout = devnull , stderr = devnull ))
15- # Check if logged in to github.com
16- auth_status_output = read (` gh auth status` , String)
17- if contains (auth_status_output, " Logged in to github.com" )
18- println (" ✅ Found active `gh` CLI session. Will use it for upload." )
19- return (:gh_cli , " GitHub CLI" )
20- end
26+ # 1. Check for `gh` CLI (system or JLL)
27+ try
28+ gh_cmd = get_gh_command ()
29+ # Suppress output of gh auth status check
30+ if success (pipeline (` $gh_cmd auth status` ; stdout = devnull , stderr = devnull ))
31+ # Check if logged in to github.com
32+ auth_status_output = read (` $gh_cmd auth status` , String)
33+ if contains (auth_status_output, " Logged in to github.com" )
34+ println (" ✅ Found active `gh` CLI session. Will use it for upload." )
35+ return (:gh_cli , " GitHub CLI" )
2136 end
22- catch e
23- @debug " gh CLI check failed: $e "
2437 end
38+ catch e
39+ @debug " gh CLI check failed: $e "
2540 end
2641
2742 # 2. Check for GITHUB_TOKEN environment variable
@@ -532,6 +547,7 @@ function upload_plots_to_gist_gh(plot_files::Union{Nothing, Tuple, Dict}, eltype
532547 end
533548
534549 try
550+ gh_cmd = get_gh_command ()
535551 # Handle different plot_files formats
536552 files_to_upload = if isa (plot_files, Tuple)
537553 # Legacy format: (png_file, pdf_file)
@@ -585,7 +601,7 @@ The PNG images can be viewed directly in the browser. Click on any `.png` file a
585601 # Create initial gist with README
586602 out = Pipe ()
587603 err = Pipe ()
588- run (pipeline (` gh gist create -d $gist_desc -p $readme_file ` , stdout = out, stderr = err))
604+ run (pipeline (` $gh_cmd gist create -d $gist_desc -p $readme_file ` , stdout = out, stderr = err))
589605 close (out. in)
590606 close (err. in)
591607
@@ -603,7 +619,7 @@ The PNG images can be viewed directly in the browser. Click on any `.png` file a
603619 temp_dir = mktempdir ()
604620 try
605621 # Clone the gist
606- run (` gh gist clone $gist_id $temp_dir ` )
622+ run (` $gh_cmd gist clone $gist_id $temp_dir ` )
607623
608624 # Copy all plot files to the gist directory
609625 for (name, filepath) in existing_files
@@ -622,7 +638,7 @@ The PNG images can be viewed directly in the browser. Click on any `.png` file a
622638
623639 # Get username for constructing raw URLs
624640 username_out = Pipe ()
625- run (pipeline (` gh api user --jq .login` , stdout = username_out))
641+ run (pipeline (` $gh_cmd api user --jq .login` , stdout = username_out))
626642 close (username_out. in)
627643 username = strip (read (username_out, String))
628644
@@ -673,13 +689,14 @@ function comment_on_issue_gh(target_repo, issue_number, body)
673689 err_str = " "
674690 out_str = " "
675691 try
692+ gh_cmd = get_gh_command ()
676693 # Use a temporary file for the body to avoid command line length limits
677694 mktemp () do path, io
678695 write (io, body)
679696 flush (io)
680697
681698 # Construct and run the gh command
682- cmd = ` gh issue comment $issue_number --repo $target_repo --body-file $path `
699+ cmd = ` $gh_cmd issue comment $issue_number --repo $target_repo --body-file $path `
683700
684701 out = Pipe ()
685702 err = Pipe ()
@@ -725,13 +742,14 @@ function create_benchmark_issue_gh(target_repo, title, body)
725742 err_str = " "
726743 out_str = " "
727744 try
745+ gh_cmd = get_gh_command ()
728746 # Use a temporary file for the body to avoid command line length limits
729747 mktemp () do path, io
730748 write (io, body)
731749 flush (io)
732750
733751 # Construct and run the gh command
734- cmd = ` gh issue create --repo $target_repo --title $title --body-file $path --label benchmark-data`
752+ cmd = ` $gh_cmd issue create --repo $target_repo --title $title --body-file $path --label benchmark-data`
735753
736754 out = Pipe ()
737755 err = Pipe ()
0 commit comments