|
1 | 1 | #!/usr/bin/env julia
|
2 | 2 |
|
3 | 3 | # MWE: Exact reproduction of LinearSolveAutotune GitHub API call
|
4 |
| -# Usage: GITHUB_TOKEN=your_token julia --project=lib/LinearSolveAutotune mwe_api_call.jl |
| 4 | +# Usage: julia --project=lib/LinearSolveAutotune mwe_api_call.jl |
| 5 | +# (Will prompt for GitHub token if GITHUB_TOKEN environment variable not set) |
5 | 6 |
|
6 | 7 | using GitHub
|
7 | 8 | using Dates
|
8 | 9 |
|
| 10 | +# Multi-attempt authentication (exactly as package does) |
| 11 | +function test_github_authentication(token::AbstractString) |
| 12 | + max_auth_attempts = 3 |
| 13 | + |
| 14 | + println("🔍 Testing GitHub authentication...") |
| 15 | + println("📏 Token length: $(length(token))") |
| 16 | + flush(stdout) |
| 17 | + |
| 18 | + for auth_attempt in 1:max_auth_attempts |
| 19 | + try |
| 20 | + if auth_attempt == 1 |
| 21 | + println("🌐 Establishing connection to GitHub API...") |
| 22 | + elseif auth_attempt == 2 |
| 23 | + println("🔄 Retrying connection (sometimes GitHub needs warmup)...") |
| 24 | + else |
| 25 | + println("🎯 Final authentication attempt...") |
| 26 | + end |
| 27 | + flush(stdout) |
| 28 | + |
| 29 | + # Add delay between attempts to handle timing issues |
| 30 | + if auth_attempt > 1 |
| 31 | + sleep(0.5) |
| 32 | + end |
| 33 | + |
| 34 | + # Test authentication |
| 35 | + auth_result = GitHub.authenticate(token) |
| 36 | + |
| 37 | + # If we get here, authentication worked |
| 38 | + println("✅ Authentication successful - your results will help everyone!") |
| 39 | + flush(stdout) |
| 40 | + return auth_result |
| 41 | + |
| 42 | + catch e |
| 43 | + println("❌ Attempt $auth_attempt failed: $(typeof(e))") |
| 44 | + if auth_attempt < max_auth_attempts |
| 45 | + println(" Retrying in a moment...") |
| 46 | + else |
| 47 | + println(" All authentication attempts failed.") |
| 48 | + # Show safe preview of token for debugging |
| 49 | + if length(token) > 8 |
| 50 | + token_preview = token[1:4] * "..." * token[end-3:end] |
| 51 | + println("🔍 Token preview: $token_preview") |
| 52 | + end |
| 53 | + println("💡 Please verify your token has 'Issues: Write' permission and try again.") |
| 54 | + end |
| 55 | + flush(stdout) |
| 56 | + end |
| 57 | + end |
| 58 | + |
| 59 | + return nothing |
| 60 | +end |
| 61 | + |
9 | 62 | function mwe_github_api_call()
|
10 | 63 | println("🧪 MWE: LinearSolveAutotune GitHub API Call")
|
11 | 64 | println("="^50)
|
12 | 65 |
|
13 |
| - # Check for token (exactly as package does) |
| 66 | + # Token input (exactly as package does) |
14 | 67 | token = get(ENV, "GITHUB_TOKEN", nothing)
|
15 | 68 | if token === nothing
|
16 |
| - println("❌ No GITHUB_TOKEN found") |
17 |
| - return false |
| 69 | + println("🚀 Help Improve LinearSolve.jl for Everyone!") |
| 70 | + println("="^50) |
| 71 | + println("Your benchmark results help the community by improving automatic") |
| 72 | + println("algorithm selection across different hardware configurations.") |
| 73 | + println() |
| 74 | + println("📋 Quick GitHub Token Setup (takes 30 seconds):") |
| 75 | + println() |
| 76 | + println("1️⃣ Open: https://github.com/settings/tokens?type=beta") |
| 77 | + println("2️⃣ Click 'Generate new token'") |
| 78 | + println("3️⃣ Set:") |
| 79 | + println(" • Name: 'LinearSolve Autotune'") |
| 80 | + println(" • Expiration: 90 days") |
| 81 | + println(" • Repository access: 'Public Repositories (read-only)'") |
| 82 | + println(" • Permissions: Enable 'Issues: Write'") |
| 83 | + println("4️⃣ Click 'Generate token' and copy it") |
| 84 | + println() |
| 85 | + println("🔑 Paste your GitHub token here:") |
| 86 | + println(" (If it shows julia> prompt, just paste the token there and press Enter)") |
| 87 | + print("Token: ") |
| 88 | + flush(stdout) |
| 89 | + |
| 90 | + # Get token input - handle both direct input and REPL interpretation |
| 91 | + try |
| 92 | + sleep(0.1) # Small delay for I/O stability |
| 93 | + input_line = String(strip(readline())) |
| 94 | + |
| 95 | + # If we got direct input, use it |
| 96 | + if !isempty(input_line) |
| 97 | + token = input_line |
| 98 | + else |
| 99 | + # Check if token was interpreted as Julia code and became a variable |
| 100 | + # Look for common GitHub token patterns in global variables |
| 101 | + println("🔍 Looking for token that may have been interpreted as Julia code...") |
| 102 | + for name in names(Main, all=true) |
| 103 | + if startswith(string(name), "github_pat_") || startswith(string(name), "ghp_") |
| 104 | + try |
| 105 | + value = getfield(Main, name) |
| 106 | + if isa(value, AbstractString) && length(value) > 20 |
| 107 | + println("✅ Found token variable: $(name)") |
| 108 | + token = String(value) |
| 109 | + break |
| 110 | + end |
| 111 | + catch |
| 112 | + continue |
| 113 | + end |
| 114 | + end |
| 115 | + end |
| 116 | + |
| 117 | + # If still no token, try one more direct input |
| 118 | + if isempty(token) |
| 119 | + println("💡 Please paste your token again (make sure to press Enter after):") |
| 120 | + print("Token: ") |
| 121 | + flush(stdout) |
| 122 | + sleep(0.1) |
| 123 | + token = String(strip(readline())) |
| 124 | + end |
| 125 | + end |
| 126 | + |
| 127 | + catch e |
| 128 | + println("❌ Input error: $e") |
| 129 | + return false |
| 130 | + end |
| 131 | + |
| 132 | + if isempty(token) || length(token) < 10 |
| 133 | + println("❌ Token seems invalid or too short") |
| 134 | + return false |
| 135 | + end |
| 136 | + |
| 137 | + # Clean token |
| 138 | + token = strip(replace(token, r"[\r\n\t ]+" => "")) |
| 139 | + |
| 140 | + # Set environment variable for this session |
| 141 | + ENV["GITHUB_TOKEN"] = token |
| 142 | + println("✅ Token accepted (length: $(length(token)))") |
| 143 | + else |
| 144 | + println("✅ Token found from environment (length: $(length(token)))") |
18 | 145 | end
|
19 | 146 |
|
20 |
| - println("✅ Token found (length: $(length(token)))") |
21 |
| - |
22 | 147 | try
|
23 |
| - # Step 1: Authenticate (exactly as package does) |
24 |
| - println("📋 Step 1: GitHub.authenticate(token)") |
25 |
| - auth = GitHub.authenticate(token) |
| 148 | + # Step 1: Authenticate with multiple attempts (exactly as package does) |
| 149 | + println("📋 Step 1: GitHub.authenticate(token) with multiple attempts") |
| 150 | + auth = test_github_authentication(token) |
| 151 | + if auth === nothing |
| 152 | + println("❌ Authentication failed after multiple attempts") |
| 153 | + return false |
| 154 | + end |
26 | 155 | println("✅ Authentication successful")
|
27 | 156 | println(" Auth type: $(typeof(auth))")
|
28 | 157 |
|
|
0 commit comments