diff --git a/lib/LinearSolveAutotune/src/LinearSolveAutotune.jl b/lib/LinearSolveAutotune/src/LinearSolveAutotune.jl index 85140f0fa..f735bc35c 100644 --- a/lib/LinearSolveAutotune/src/LinearSolveAutotune.jl +++ b/lib/LinearSolveAutotune/src/LinearSolveAutotune.jl @@ -265,7 +265,7 @@ function autotune_setup(; end """ - share_results(results::AutotuneResults) + share_results(results::AutotuneResults; auto_login::Bool = true) Share your benchmark results with the LinearSolve.jl community to help improve automatic algorithm selection across different hardware configurations. @@ -273,7 +273,17 @@ automatic algorithm selection across different hardware configurations. This function will authenticate with GitHub (using gh CLI or token) and post your results as a comment to the community benchmark collection issue. -# Setup Instructions +If authentication is not found and `auto_login` is true, the function will +offer to run `gh auth login` interactively to set up authentication. + +# Arguments +- `results`: AutotuneResults object from autotune_setup +- `auto_login`: If true, prompts to authenticate if not already authenticated (default: true) + +# Authentication Methods + +## Automatic (New!) +If gh is not authenticated, the function will offer to run authentication for you. ## Method 1: GitHub CLI (Recommended) 1. Install GitHub CLI: https://cli.github.com/ @@ -289,19 +299,19 @@ your results as a comment to the community benchmark collection issue. 5. Set environment variable: `ENV["GITHUB_TOKEN"] = "your_token_here"` 6. Run this function -# Arguments -- `results`: AutotuneResults object from autotune_setup - # Examples ```julia # Run benchmarks results = autotune_setup() -# Share results with the community +# Share results with automatic authentication prompt share_results(results) + +# Share results without authentication prompt +share_results(results; auto_login = false) ``` """ -function share_results(results::AutotuneResults) +function share_results(results::AutotuneResults; auto_login::Bool = true) @info "šŸ“¤ Preparing to share benchmark results with the community..." # Extract from AutotuneResults @@ -314,20 +324,12 @@ function share_results(results::AutotuneResults) # Categorize results categories = categorize_results(results_df) - # Set up authentication - @info "šŸ”— Setting up GitHub authentication..." - @info "ā„¹ļø For setup instructions, see the documentation or visit:" - @info " https://cli.github.com/ (for gh CLI)" - @info " https://github.com/settings/tokens/new (for token)" + # Set up authentication (with auto-login prompt if enabled) + @info "šŸ”— Checking GitHub authentication..." - github_auth = setup_github_authentication() + github_auth = setup_github_authentication(; auto_login = auto_login) if github_auth === nothing || github_auth[1] === nothing - @warn "āŒ GitHub authentication not available." - @info "šŸ“ To share results, please set up authentication:" - @info " Option 1: Install gh CLI and run: gh auth login" - @info " Option 2: Create a GitHub token and set: ENV[\"GITHUB_TOKEN\"] = \"your_token\"" - # Save results locally as fallback timestamp = replace(string(Dates.now()), ":" => "-") fallback_file = "autotune_results_$(timestamp).md" @@ -336,7 +338,8 @@ function share_results(results::AutotuneResults) write(f, markdown_content) end @info "šŸ“ Results saved locally to $fallback_file" - @info " You can manually share this file on the issue tracker." + @info " You can manually share this file on the issue tracker:" + @info " https://github.com/SciML/LinearSolve.jl/issues/669" return end diff --git a/lib/LinearSolveAutotune/src/telemetry.jl b/lib/LinearSolveAutotune/src/telemetry.jl index b49385e0c..4d3a9857c 100644 --- a/lib/LinearSolveAutotune/src/telemetry.jl +++ b/lib/LinearSolveAutotune/src/telemetry.jl @@ -17,15 +17,18 @@ function get_gh_command() end """ - setup_github_authentication() + setup_github_authentication(; auto_login::Bool = true) Set up GitHub authentication for telemetry uploads. +If auto_login is true and no authentication is found, will prompt to run gh auth login. Returns an authentication method indicator if successful, nothing if setup fails. """ -function setup_github_authentication() +function setup_github_authentication(; auto_login::Bool = true) # 1. Check for `gh` CLI (system or JLL) + gh_cmd = get_gh_command() + + # First check if already authenticated try - gh_cmd = get_gh_command() # Suppress output of gh auth status check if success(pipeline(`$gh_cmd auth status`; stdout=devnull, stderr=devnull)) # Check if logged in to github.com @@ -36,7 +39,7 @@ function setup_github_authentication() end end catch e - @debug "gh CLI check failed: $e" + @debug "gh CLI auth status check failed: $e" end # 2. Check for GITHUB_TOKEN environment variable @@ -48,7 +51,43 @@ function setup_github_authentication() end end - # 3. No authentication available - return nothing + # 3. If auto_login is enabled, offer to authenticate + if auto_login + println("\nšŸ” GitHub authentication not found.") + println(" To share results with the community, authentication is required.") + println("\nWould you like to authenticate with GitHub now? (y/n)") + print("> ") + response = readline() + + if lowercase(strip(response)) in ["y", "yes"] + println("\nšŸ“ Starting GitHub authentication...") + println(" This will open your browser to authenticate with GitHub.") + println(" Please follow the prompts to complete authentication.\n") + + try + # Run gh auth login interactively (using system gh or JLL) + run(`$gh_cmd auth login`) + + # Check if authentication succeeded + if success(pipeline(`$gh_cmd auth status`; stdout=devnull, stderr=devnull)) + auth_status_output = read(`$gh_cmd auth status`, String) + if contains(auth_status_output, "Logged in to github.com") + println("\nāœ… Authentication successful! You can now share results.") + return (:gh_cli, "GitHub CLI") + end + end + catch e + println("\nāŒ Authentication failed: $e") + println(" You can try again later or use a GitHub token instead.") + end + else + println("\nšŸ“ Skipping authentication. You can authenticate later by:") + println(" 1. Running: gh auth login") + println(" 2. Or setting: ENV[\"GITHUB_TOKEN\"] = \"your_token\"") + end + end + + # 4. No authentication available - return nothing return (nothing, nothing) end