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(; auto_login::Bool = true)
5
21
@@ -8,21 +24,22 @@ If auto_login is true and no authentication is found, will prompt to run gh auth
8
24
Returns an authentication method indicator if successful, nothing if setup fails.
9
25
"""
10
26
function 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" )
22
39
end
23
- catch e
24
- @debug " gh CLI check failed: $e "
25
40
end
41
+ catch e
42
+ @debug " gh CLI auth status check failed: $e "
26
43
end
27
44
28
45
# 2. Check for GITHUB_TOKEN environment variable
@@ -34,8 +51,8 @@ function setup_github_authentication(; auto_login::Bool = true)
34
51
end
35
52
end
36
53
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
39
56
println (" \n 🔐 GitHub authentication not found." )
40
57
println (" To share results with the community, authentication is required." )
41
58
println (" \n Would you like to authenticate with GitHub now? (y/n)" )
@@ -48,12 +65,12 @@ function setup_github_authentication(; auto_login::Bool = true)
48
65
println (" Please follow the prompts to complete authentication.\n " )
49
66
50
67
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` )
53
70
54
71
# 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)
57
74
if contains (auth_status_output, " Logged in to github.com" )
58
75
println (" \n ✅ Authentication successful! You can now share results." )
59
76
return (:gh_cli , " GitHub CLI" )
@@ -569,6 +586,7 @@ function upload_plots_to_gist_gh(plot_files::Union{Nothing, Tuple, Dict}, eltype
569
586
end
570
587
571
588
try
589
+ gh_cmd = get_gh_command ()
572
590
# Handle different plot_files formats
573
591
files_to_upload = if isa (plot_files, Tuple)
574
592
# 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
622
640
# Create initial gist with README
623
641
out = Pipe ()
624
642
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))
626
644
close (out. in)
627
645
close (err. in)
628
646
@@ -640,7 +658,7 @@ The PNG images can be viewed directly in the browser. Click on any `.png` file a
640
658
temp_dir = mktempdir ()
641
659
try
642
660
# Clone the gist
643
- run (` gh gist clone $gist_id $temp_dir ` )
661
+ run (` $gh_cmd gist clone $gist_id $temp_dir ` )
644
662
645
663
# Copy all plot files to the gist directory
646
664
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
659
677
660
678
# Get username for constructing raw URLs
661
679
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))
663
681
close (username_out. in)
664
682
username = strip (read (username_out, String))
665
683
@@ -710,13 +728,14 @@ function comment_on_issue_gh(target_repo, issue_number, body)
710
728
err_str = " "
711
729
out_str = " "
712
730
try
731
+ gh_cmd = get_gh_command ()
713
732
# Use a temporary file for the body to avoid command line length limits
714
733
mktemp () do path, io
715
734
write (io, body)
716
735
flush (io)
717
736
718
737
# 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 `
720
739
721
740
out = Pipe ()
722
741
err = Pipe ()
@@ -762,13 +781,14 @@ function create_benchmark_issue_gh(target_repo, title, body)
762
781
err_str = " "
763
782
out_str = " "
764
783
try
784
+ gh_cmd = get_gh_command ()
765
785
# Use a temporary file for the body to avoid command line length limits
766
786
mktemp () do path, io
767
787
write (io, body)
768
788
flush (io)
769
789
770
790
# 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`
772
792
773
793
out = Pipe ()
774
794
err = Pipe ()
0 commit comments