Skip to content

Commit

Permalink
try download pkgci script
Browse files Browse the repository at this point in the history
  • Loading branch information
saienduri committed Nov 21, 2024
1 parent 94d2090 commit bcfa414
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 0 deletions.
1 change: 1 addition & 0 deletions .github/workflows/test_sdxl.yml
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ jobs:
python3.11 -m venv sdxl_venv
source sdxl_venv/bin/activate
python -m pip install --upgrade pip
python ci-tools/latest-pkgci.py
pip install --no-compile -r ${{ github.workspace }}/iree-turbine/pytorch-cpu-requirements.txt
pip install --pre --upgrade -r ${{ github.workspace }}/iree-turbine/requirements.txt
pip install --no-compile --pre --upgrade -e models -r models/requirements.txt
Expand Down
66 changes: 66 additions & 0 deletions ci-tools/latest-pkgci.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
import requests
import json
import os

GITHUB_TOKEN = os.getenv("IREE_TOKEN")

OWNER = "iree-org"
REPO = "iree"

API_URL = f"https://api.github.com/repos/{OWNER}/{REPO}/actions/workflows/pkgci.yml/runs"

# Function to get the latest workflow run ID for pkgci.yml
def get_latest_pkgci_workflow_run():
headers = {"Authorization": f"token {GITHUB_TOKEN}"}
params = {"per_page": 1}
response = requests.get(API_URL, headers=headers, params=params)

if response.status_code == 200:
data = response.json()
if data["total_count"] > 0:
latest_run = data["workflow_runs"][0]
return latest_run["id"]
else:
print("No workflow runs found for pkgci.yml.")
return None
else:
print(f"Error fetching workflow runs: {response.status_code}")
return None

# Function to get the artifacts of a specific workflow run
def get_artifacts(workflow_run_id):
artifacts_url = f"https://api.github.com/repos/{OWNER}/{REPO}/actions/runs/{workflow_run_id}/artifacts"
headers = {"Authorization": f"token {GITHUB_TOKEN}"}
response = requests.get(artifacts_url, headers=headers)

if response.status_code == 200:
artifacts = response.json()["artifacts"]
if artifacts:
print(f"Artifacts for pkgci.yml workflow run {workflow_run_id}:")
for artifact in artifacts:
print(f"- {artifact['name']} (Size: {artifact['size_in_bytes']} bytes)")
download_artifact(artifact['archive_download_url'], artifact['name'])
else:
print("No artifacts found for the pkgci.yml workflow run.")
else:
print(f"Error fetching artifacts: {response.status_code}")

# Function to download an artifact
def download_artifact(download_url, artifact_name):
headers = {"Authorization": f"token {GITHUB_TOKEN}"}
response = requests.get(download_url, headers=headers, stream=True)

if response.status_code == 200:
file_name = f"{artifact_name}.tar.gz"
with open(file_name, "wb") as f:
for chunk in response.iter_content(chunk_size=8192):
if chunk:
f.write(chunk)
print(f"Artifact '{artifact_name}' downloaded successfully as '{file_name}'.")
else:
print(f"Error downloading artifact '{artifact_name}': {response.status_code}")

if __name__ == "__main__":
workflow_run_id = get_latest_pkgci_workflow_run()
if workflow_run_id:
get_artifacts(workflow_run_id)

0 comments on commit bcfa414

Please sign in to comment.