openai/tiktoken
Publicmirrored fromhttps://github.com/openai/tiktokenAvailable
scripts/wheel_download.py
56lines · modecode
| 1 | import argparse |
| 2 | import zipfile |
| 3 | from pathlib import Path |
| 4 | |
| 5 | import requests |
| 6 | |
| 7 | |
| 8 | def download_artifacts(token, owner, repo, run_id, output_dir): |
| 9 | headers = {"Authorization": f"token {token}", "Accept": "application/vnd.github.v3+json"} |
| 10 | |
| 11 | # Get list of artifacts |
| 12 | artifacts_url = f"https://api.github.com/repos/{owner}/{repo}/actions/runs/{run_id}/artifacts" |
| 13 | response = requests.get(artifacts_url, headers=headers) |
| 14 | response.raise_for_status() |
| 15 | artifacts = response.json()["artifacts"] |
| 16 | |
| 17 | if not artifacts: |
| 18 | print(f"No artifacts found for run ID: {run_id}") |
| 19 | return |
| 20 | |
| 21 | output_dir = Path(output_dir) |
| 22 | output_dir.mkdir(parents=True, exist_ok=True) |
| 23 | |
| 24 | print(f"Found {len(artifacts)} artifacts") |
| 25 | for artifact in artifacts: |
| 26 | name = artifact["name"] |
| 27 | download_url = artifact["archive_download_url"] |
| 28 | |
| 29 | print(f"Downloading {name}...") |
| 30 | |
| 31 | response = requests.get(download_url, headers=headers, stream=True) |
| 32 | response.raise_for_status() |
| 33 | |
| 34 | temp_zip = output_dir / f"{name}.zip" |
| 35 | with open(temp_zip, "wb") as f: |
| 36 | for chunk in response.iter_content(chunk_size=8192): |
| 37 | f.write(chunk) |
| 38 | with zipfile.ZipFile(temp_zip, "r") as zip_ref: |
| 39 | zip_ref.extractall(output_dir) |
| 40 | temp_zip.unlink() |
| 41 | print(f"Downloaded and extracted {name}") |
| 42 | |
| 43 | |
| 44 | if __name__ == "__main__": |
| 45 | parser = argparse.ArgumentParser(description="Download artifacts from a GitHub Actions run") |
| 46 | parser.add_argument("--token", required=True, help="GitHub Personal Access Token") |
| 47 | parser.add_argument("--owner", required=True, help="Repository owner") |
| 48 | parser.add_argument("--repo", required=True, help="Repository name") |
| 49 | parser.add_argument("--run-id", required=True, help="Workflow run ID") |
| 50 | parser.add_argument( |
| 51 | "--output-dir", default="artifacts", help="Output directory for downloaded artifacts" |
| 52 | ) |
| 53 | |
| 54 | args = parser.parse_args() |
| 55 | |
| 56 | download_artifacts(args.token, args.owner, args.repo, args.run_id, args.output_dir) |
| 57 | |