Skip to content

Commit 0d99660

Browse files
Add automatic gh auth login prompt when sharing benchmark results (#689)
* Add automatic gh auth login prompt when sharing results - Modified setup_github_authentication to offer interactive gh auth login - Added auto_login parameter to control whether to prompt for authentication - If gh is not authenticated, prompts user to run gh auth login - Runs gh auth login interactively if user agrees - Updated share_results to pass through auto_login parameter - Falls back to saving results locally if authentication fails or is skipped This makes sharing results much easier - users no longer need to manually set up authentication beforehand. The function will guide them through the process when needed. * 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. --------- Co-authored-by: ChrisRackauckas <[email protected]>
1 parent 6abda9e commit 0d99660

File tree

2 files changed

+66
-24
lines changed

2 files changed

+66
-24
lines changed

lib/LinearSolveAutotune/src/LinearSolveAutotune.jl

Lines changed: 22 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -265,15 +265,25 @@ function autotune_setup(;
265265
end
266266

267267
"""
268-
share_results(results::AutotuneResults)
268+
share_results(results::AutotuneResults; auto_login::Bool = true)
269269
270270
Share your benchmark results with the LinearSolve.jl community to help improve
271271
automatic algorithm selection across different hardware configurations.
272272
273273
This function will authenticate with GitHub (using gh CLI or token) and post
274274
your results as a comment to the community benchmark collection issue.
275275
276-
# Setup Instructions
276+
If authentication is not found and `auto_login` is true, the function will
277+
offer to run `gh auth login` interactively to set up authentication.
278+
279+
# Arguments
280+
- `results`: AutotuneResults object from autotune_setup
281+
- `auto_login`: If true, prompts to authenticate if not already authenticated (default: true)
282+
283+
# Authentication Methods
284+
285+
## Automatic (New!)
286+
If gh is not authenticated, the function will offer to run authentication for you.
277287
278288
## Method 1: GitHub CLI (Recommended)
279289
1. Install GitHub CLI: https://cli.github.com/
@@ -289,19 +299,19 @@ your results as a comment to the community benchmark collection issue.
289299
5. Set environment variable: `ENV["GITHUB_TOKEN"] = "your_token_here"`
290300
6. Run this function
291301
292-
# Arguments
293-
- `results`: AutotuneResults object from autotune_setup
294-
295302
# Examples
296303
```julia
297304
# Run benchmarks
298305
results = autotune_setup()
299306
300-
# Share results with the community
307+
# Share results with automatic authentication prompt
301308
share_results(results)
309+
310+
# Share results without authentication prompt
311+
share_results(results; auto_login = false)
302312
```
303313
"""
304-
function share_results(results::AutotuneResults)
314+
function share_results(results::AutotuneResults; auto_login::Bool = true)
305315
@info "📤 Preparing to share benchmark results with the community..."
306316

307317
# Extract from AutotuneResults
@@ -314,20 +324,12 @@ function share_results(results::AutotuneResults)
314324
# Categorize results
315325
categories = categorize_results(results_df)
316326

317-
# Set up authentication
318-
@info "🔗 Setting up GitHub authentication..."
319-
@info "ℹ️ For setup instructions, see the documentation or visit:"
320-
@info " https://cli.github.com/ (for gh CLI)"
321-
@info " https://github.com/settings/tokens/new (for token)"
327+
# Set up authentication (with auto-login prompt if enabled)
328+
@info "🔗 Checking GitHub authentication..."
322329

323-
github_auth = setup_github_authentication()
330+
github_auth = setup_github_authentication(; auto_login = auto_login)
324331

325332
if github_auth === nothing || github_auth[1] === nothing
326-
@warn "❌ GitHub authentication not available."
327-
@info "📝 To share results, please set up authentication:"
328-
@info " Option 1: Install gh CLI and run: gh auth login"
329-
@info " Option 2: Create a GitHub token and set: ENV[\"GITHUB_TOKEN\"] = \"your_token\""
330-
331333
# Save results locally as fallback
332334
timestamp = replace(string(Dates.now()), ":" => "-")
333335
fallback_file = "autotune_results_$(timestamp).md"
@@ -336,7 +338,8 @@ function share_results(results::AutotuneResults)
336338
write(f, markdown_content)
337339
end
338340
@info "📁 Results saved locally to $fallback_file"
339-
@info " You can manually share this file on the issue tracker."
341+
@info " You can manually share this file on the issue tracker:"
342+
@info " https://github.com/SciML/LinearSolve.jl/issues/669"
340343
return
341344
end
342345

lib/LinearSolveAutotune/src/telemetry.jl

Lines changed: 44 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,18 @@ function get_gh_command()
1717
end
1818

1919
"""
20-
setup_github_authentication()
20+
setup_github_authentication(; auto_login::Bool = true)
2121
2222
Set up GitHub authentication for telemetry uploads.
23+
If auto_login is true and no authentication is found, will prompt to run gh auth login.
2324
Returns an authentication method indicator if successful, nothing if setup fails.
2425
"""
25-
function setup_github_authentication()
26+
function setup_github_authentication(; auto_login::Bool = true)
2627
# 1. Check for `gh` CLI (system or JLL)
28+
gh_cmd = get_gh_command()
29+
30+
# First check if already authenticated
2731
try
28-
gh_cmd = get_gh_command()
2932
# Suppress output of gh auth status check
3033
if success(pipeline(`$gh_cmd auth status`; stdout=devnull, stderr=devnull))
3134
# Check if logged in to github.com
@@ -36,7 +39,7 @@ function setup_github_authentication()
3639
end
3740
end
3841
catch e
39-
@debug "gh CLI check failed: $e"
42+
@debug "gh CLI auth status check failed: $e"
4043
end
4144

4245
# 2. Check for GITHUB_TOKEN environment variable
@@ -48,7 +51,43 @@ function setup_github_authentication()
4851
end
4952
end
5053

51-
# 3. No authentication available - return nothing
54+
# 3. If auto_login is enabled, offer to authenticate
55+
if auto_login
56+
println("\n🔐 GitHub authentication not found.")
57+
println(" To share results with the community, authentication is required.")
58+
println("\nWould you like to authenticate with GitHub now? (y/n)")
59+
print("> ")
60+
response = readline()
61+
62+
if lowercase(strip(response)) in ["y", "yes"]
63+
println("\n📝 Starting GitHub authentication...")
64+
println(" This will open your browser to authenticate with GitHub.")
65+
println(" Please follow the prompts to complete authentication.\n")
66+
67+
try
68+
# Run gh auth login interactively (using system gh or JLL)
69+
run(`$gh_cmd auth login`)
70+
71+
# Check if authentication succeeded
72+
if success(pipeline(`$gh_cmd auth status`; stdout=devnull, stderr=devnull))
73+
auth_status_output = read(`$gh_cmd auth status`, String)
74+
if contains(auth_status_output, "Logged in to github.com")
75+
println("\n✅ Authentication successful! You can now share results.")
76+
return (:gh_cli, "GitHub CLI")
77+
end
78+
end
79+
catch e
80+
println("\n❌ Authentication failed: $e")
81+
println(" You can try again later or use a GitHub token instead.")
82+
end
83+
else
84+
println("\n📝 Skipping authentication. You can authenticate later by:")
85+
println(" 1. Running: gh auth login")
86+
println(" 2. Or setting: ENV[\"GITHUB_TOKEN\"] = \"your_token\"")
87+
end
88+
end
89+
90+
# 4. No authentication available - return nothing
5291
return (nothing, nothing)
5392
end
5493

0 commit comments

Comments
 (0)