From e970f682d24e4319d6248ea92f47518bdcb23cef Mon Sep 17 00:00:00 2001 From: ChrisRackauckas Date: Thu, 7 Aug 2025 22:11:04 -0400 Subject: [PATCH 1/2] 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. --- .../src/LinearSolveAutotune.jl | 41 +++++++++-------- lib/LinearSolveAutotune/src/telemetry.jl | 44 +++++++++++++++++-- 2 files changed, 63 insertions(+), 22 deletions(-) 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..dd8a280a8 100644 --- a/lib/LinearSolveAutotune/src/telemetry.jl +++ b/lib/LinearSolveAutotune/src/telemetry.jl @@ -17,12 +17,13 @@ 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) try gh_cmd = get_gh_command() @@ -48,7 +49,44 @@ function setup_github_authentication() end end - # 3. No authentication available - return nothing + # 3. If auto_login is enabled, offer to authenticate using gh (system or JLL) + if auto_login + gh_cmd = get_gh_command() + 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 the wrapper command + 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 From e80024e357ca27e921c78f1b236359c5f3890207 Mon Sep 17 00:00:00 2001 From: ChrisRackauckas Date: Thu, 7 Aug 2025 22:17:06 -0400 Subject: [PATCH 2/2] 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. --- lib/LinearSolveAutotune/src/telemetry.jl | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/lib/LinearSolveAutotune/src/telemetry.jl b/lib/LinearSolveAutotune/src/telemetry.jl index dd8a280a8..4d3a9857c 100644 --- a/lib/LinearSolveAutotune/src/telemetry.jl +++ b/lib/LinearSolveAutotune/src/telemetry.jl @@ -25,8 +25,10 @@ Returns an authentication method indicator if successful, nothing if setup fails """ 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 @@ -37,7 +39,7 @@ function setup_github_authentication(; auto_login::Bool = true) 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 @@ -49,9 +51,8 @@ function setup_github_authentication(; auto_login::Bool = true) end end - # 3. If auto_login is enabled, offer to authenticate using gh (system or JLL) + # 3. If auto_login is enabled, offer to authenticate if auto_login - gh_cmd = get_gh_command() 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)") @@ -64,7 +65,7 @@ function setup_github_authentication(; auto_login::Bool = true) println(" Please follow the prompts to complete authentication.\n") try - # Run gh auth login interactively using the wrapper command + # Run gh auth login interactively (using system gh or JLL) run(`$gh_cmd auth login`) # Check if authentication succeeded