Skip to content

Commit e970f68

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 6abda9e commit e970f68

File tree

2 files changed

+63
-22
lines changed

2 files changed

+63
-22
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: 41 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,13 @@ 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)
2728
try
2829
gh_cmd = get_gh_command()
@@ -48,7 +49,44 @@ function setup_github_authentication()
4849
end
4950
end
5051

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

0 commit comments

Comments
 (0)