Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 22 additions & 19 deletions lib/LinearSolveAutotune/src/LinearSolveAutotune.jl
Original file line number Diff line number Diff line change
Expand Up @@ -265,15 +265,25 @@ 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.

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/
Expand All @@ -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
Expand All @@ -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"
Expand All @@ -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

Expand Down
49 changes: 44 additions & 5 deletions lib/LinearSolveAutotune/src/telemetry.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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

Expand Down
Loading