Skip to content

Commit ac92705

Browse files
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.
1 parent fb35143 commit ac92705

File tree

2 files changed

+62
-22
lines changed

2 files changed

+62
-22
lines changed

lib/LinearSolveAutotune/src/LinearSolveAutotune.jl

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

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

306316
# Extract from AutotuneResults
@@ -313,20 +323,12 @@ function share_results(results::AutotuneResults)
313323
# Categorize results
314324
categories = categorize_results(results_df)
315325

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

322-
github_auth = setup_github_authentication()
329+
github_auth = setup_github_authentication(; auto_login = auto_login)
323330

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

lib/LinearSolveAutotune/src/telemetry.jl

Lines changed: 40 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
# Telemetry functionality for sharing benchmark results
22

33
"""
4-
setup_github_authentication()
4+
setup_github_authentication(; auto_login::Bool = true)
55
66
Set up GitHub authentication for telemetry uploads.
7+
If auto_login is true and no authentication is found, will prompt to run gh auth login.
78
Returns an authentication method indicator if successful, nothing if setup fails.
89
"""
9-
function setup_github_authentication()
10+
function setup_github_authentication(; auto_login::Bool = true)
1011
# 1. Check for `gh` CLI
1112
if !isnothing(Sys.which("gh"))
1213
try
@@ -33,7 +34,43 @@ function setup_github_authentication()
3334
end
3435
end
3536

36-
# 3. No authentication available - return nothing
37+
# 3. If auto_login is enabled and gh is installed, offer to authenticate
38+
if auto_login && !isnothing(Sys.which("gh"))
39+
println("\n🔐 GitHub authentication not found.")
40+
println(" To share results with the community, authentication is required.")
41+
println("\nWould you like to authenticate with GitHub now? (y/n)")
42+
print("> ")
43+
response = readline()
44+
45+
if lowercase(strip(response)) in ["y", "yes"]
46+
println("\n📝 Starting GitHub authentication...")
47+
println(" This will open your browser to authenticate with GitHub.")
48+
println(" Please follow the prompts to complete authentication.\n")
49+
50+
try
51+
# Run gh auth login interactively
52+
run(`gh auth login`)
53+
54+
# Check if authentication succeeded
55+
if success(pipeline(`gh auth status`; stdout=devnull, stderr=devnull))
56+
auth_status_output = read(`gh auth status`, String)
57+
if contains(auth_status_output, "Logged in to github.com")
58+
println("\n✅ Authentication successful! You can now share results.")
59+
return (:gh_cli, "GitHub CLI")
60+
end
61+
end
62+
catch e
63+
println("\n❌ Authentication failed: $e")
64+
println(" You can try again later or use a GitHub token instead.")
65+
end
66+
else
67+
println("\n📝 Skipping authentication. You can authenticate later by:")
68+
println(" 1. Running: gh auth login")
69+
println(" 2. Or setting: ENV[\"GITHUB_TOKEN\"] = \"your_token\"")
70+
end
71+
end
72+
73+
# 4. No authentication available - return nothing
3774
return (nothing, nothing)
3875
end
3976

0 commit comments

Comments
 (0)