1
1
# Telemetry functionality for sharing benchmark results
2
2
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
+
3
19
"""
4
20
setup_github_authentication()
5
21
6
22
Set up GitHub authentication for telemetry uploads.
7
23
Returns an authentication method indicator if successful, nothing if setup fails.
8
24
"""
9
25
function 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" )
21
36
end
22
- catch e
23
- @debug " gh CLI check failed: $e "
24
37
end
38
+ catch e
39
+ @debug " gh CLI check failed: $e "
25
40
end
26
41
27
42
# 2. Check for GITHUB_TOKEN environment variable
@@ -532,6 +547,7 @@ function upload_plots_to_gist_gh(plot_files::Union{Nothing, Tuple, Dict}, eltype
532
547
end
533
548
534
549
try
550
+ gh_cmd = get_gh_command ()
535
551
# Handle different plot_files formats
536
552
files_to_upload = if isa (plot_files, Tuple)
537
553
# 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
585
601
# Create initial gist with README
586
602
out = Pipe ()
587
603
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))
589
605
close (out. in)
590
606
close (err. in)
591
607
@@ -603,7 +619,7 @@ The PNG images can be viewed directly in the browser. Click on any `.png` file a
603
619
temp_dir = mktempdir ()
604
620
try
605
621
# Clone the gist
606
- run (` gh gist clone $gist_id $temp_dir ` )
622
+ run (` $gh_cmd gist clone $gist_id $temp_dir ` )
607
623
608
624
# Copy all plot files to the gist directory
609
625
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
622
638
623
639
# Get username for constructing raw URLs
624
640
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))
626
642
close (username_out. in)
627
643
username = strip (read (username_out, String))
628
644
@@ -673,13 +689,14 @@ function comment_on_issue_gh(target_repo, issue_number, body)
673
689
err_str = " "
674
690
out_str = " "
675
691
try
692
+ gh_cmd = get_gh_command ()
676
693
# Use a temporary file for the body to avoid command line length limits
677
694
mktemp () do path, io
678
695
write (io, body)
679
696
flush (io)
680
697
681
698
# 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 `
683
700
684
701
out = Pipe ()
685
702
err = Pipe ()
@@ -725,13 +742,14 @@ function create_benchmark_issue_gh(target_repo, title, body)
725
742
err_str = " "
726
743
out_str = " "
727
744
try
745
+ gh_cmd = get_gh_command ()
728
746
# Use a temporary file for the body to avoid command line length limits
729
747
mktemp () do path, io
730
748
write (io, body)
731
749
flush (io)
732
750
733
751
# 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`
735
753
736
754
out = Pipe ()
737
755
err = Pipe ()
0 commit comments