Skip to content

Commit 94b9a6f

Browse files
Use gh_cli_jll for automatic authentication
- Added gh_cli_jll as a dependency - Implemented get_gh_command() to select between system gh and JLL gh - Updated all gh CLI calls to use the wrapper function - Auto-login now works even when gh is not installed on the system - Falls back to JLL-provided gh binary automatically This ensures the auto-authentication feature works on all systems, regardless of whether gh CLI is installed.
1 parent ac92705 commit 94b9a6f

File tree

3 files changed

+47
-24
lines changed

3 files changed

+47
-24
lines changed

lib/LinearSolveAutotune/Project.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ Base64 = "2a0f44e3-6c83-55bd-87e4-b1978d98bd5f"
1010
CPUSummary = "2a0fbf3d-bb9c-48f3-b0a9-814d99fd7ab9"
1111
DataFrames = "a93c6f00-e57d-5684-b7b6-d8193f3e46c0"
1212
GitHub = "bc5e4493-9b4d-5f90-b8aa-2b2bcaad7a26"
13+
gh_cli_jll = "5d31d589-30fb-542f-b82d-10325e863e38"
1314
Plots = "91a5bcdd-55d7-5caf-9e0b-520d859cae80"
1415
PrettyTables = "08abe8d2-0d0c-5749-adfa-8a2ac140af0d"
1516
Preferences = "21216c6a-2e73-6563-6e65-726566657250"
@@ -33,6 +34,7 @@ Base64 = "1"
3334
CPUSummary = "0.2"
3435
DataFrames = "1"
3536
GitHub = "5"
37+
gh_cli_jll = "2"
3638
Plots = "1"
3739
PrettyTables = "2"
3840
Preferences = "1"

lib/LinearSolveAutotune/src/LinearSolveAutotune.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ using Metal
2424

2525
# Optional dependencies for telemetry and plotting
2626
using GitHub
27+
using gh_cli_jll
2728
using Plots
2829

2930
export autotune_setup, share_results, AutotuneResults, plot

lib/LinearSolveAutotune/src/telemetry.jl

Lines changed: 44 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,21 @@
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
824
Returns an authentication method indicator if successful, nothing if setup fails.
925
"""
1026
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")
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("\nWould 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

Comments
 (0)