|
| 1 | +import os |
| 2 | +import requests |
| 3 | +from datetime import datetime |
| 4 | + |
| 5 | +# GitHub API endpoints |
| 6 | +GITHUB_API_URL = "https://api.github.com" |
| 7 | +REPO_OWNER = "BerriAI" |
| 8 | +REPO_NAME = "litellm" |
| 9 | + |
| 10 | +# GitHub personal access token (required for uploading release assets) |
| 11 | +GITHUB_ACCESS_TOKEN = os.environ.get("GITHUB_ACCESS_TOKEN") |
| 12 | + |
| 13 | +# Headers for GitHub API requests |
| 14 | +headers = { |
| 15 | + "Accept": "application/vnd.github+json", |
| 16 | + "Authorization": f"Bearer {GITHUB_ACCESS_TOKEN}", |
| 17 | + "X-GitHub-Api-Version": "2022-11-28", |
| 18 | +} |
| 19 | + |
| 20 | +# Get the latest release |
| 21 | +releases_url = f"{GITHUB_API_URL}/repos/{REPO_OWNER}/{REPO_NAME}/releases/latest" |
| 22 | +response = requests.get(releases_url, headers=headers) |
| 23 | +latest_release = response.json() |
| 24 | +print("Latest release:", latest_release) |
| 25 | + |
| 26 | +# Upload an asset to the latest release |
| 27 | +upload_url = latest_release["upload_url"].split("{?")[0] |
| 28 | +asset_name = "results_stats.csv" |
| 29 | +asset_path = os.path.join(os.getcwd(), asset_name) |
| 30 | +print("upload_url:", upload_url) |
| 31 | + |
| 32 | +with open(asset_path, "rb") as asset_file: |
| 33 | + asset_data = asset_file.read() |
| 34 | + |
| 35 | +upload_payload = { |
| 36 | + "name": asset_name, |
| 37 | + "label": "Load test results", |
| 38 | + "created_at": datetime.utcnow().isoformat() + "Z", |
| 39 | +} |
| 40 | + |
| 41 | +upload_headers = headers.copy() |
| 42 | +upload_headers["Content-Type"] = "application/octet-stream" |
| 43 | + |
| 44 | +upload_response = requests.post( |
| 45 | + upload_url, |
| 46 | + headers=upload_headers, |
| 47 | + data=asset_data, |
| 48 | + params=upload_payload, |
| 49 | +) |
| 50 | + |
| 51 | +if upload_response.status_code == 201: |
| 52 | + print(f"Asset '{asset_name}' uploaded successfully to the latest release.") |
| 53 | +else: |
| 54 | + print(f"Failed to upload asset. Response: {upload_response.text}") |
0 commit comments