Spaces:
Running
Running
ci run id
Browse files- app.py +2 -2
- get_last_ci_run.py +72 -0
app.py
CHANGED
|
@@ -8,7 +8,7 @@ import asyncio
|
|
| 8 |
import aiohttp
|
| 9 |
import pandas as pd
|
| 10 |
from tqdm import tqdm
|
| 11 |
-
|
| 12 |
|
| 13 |
def get_audio_models():
|
| 14 |
url = "https://raw.githubusercontent.com/huggingface/transformers/main/docs/source/en/_toctree.yml"
|
|
@@ -188,7 +188,7 @@ with gr.Blocks() as results_viz:
|
|
| 188 |
|
| 189 |
def check_and_refresh():
|
| 190 |
# For now just return hardcoded ID
|
| 191 |
-
latest_ci_id =
|
| 192 |
|
| 193 |
try:
|
| 194 |
with open("ci_id.txt", "r") as f:
|
|
|
|
| 8 |
import aiohttp
|
| 9 |
import pandas as pd
|
| 10 |
from tqdm import tqdm
|
| 11 |
+
from get_last_ci_run import get_last_ci_run_id
|
| 12 |
|
| 13 |
def get_audio_models():
|
| 14 |
url = "https://raw.githubusercontent.com/huggingface/transformers/main/docs/source/en/_toctree.yml"
|
|
|
|
| 188 |
|
| 189 |
def check_and_refresh():
|
| 190 |
# For now just return hardcoded ID
|
| 191 |
+
latest_ci_id = str(get_last_ci_run_id())
|
| 192 |
|
| 193 |
try:
|
| 194 |
with open("ci_id.txt", "r") as f:
|
get_last_ci_run.py
ADDED
|
@@ -0,0 +1,72 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import os
|
| 2 |
+
import requests
|
| 3 |
+
|
| 4 |
+
WORKFLOW_ID = "90575235"
|
| 5 |
+
|
| 6 |
+
def get_daily_ci_runs(token, num_runs=7, workflow_id=None):
|
| 7 |
+
"""Get the workflow runs of the scheduled (daily) CI.
|
| 8 |
+
|
| 9 |
+
This only selects the runs triggered by the `schedule` event on the `main` branch.
|
| 10 |
+
"""
|
| 11 |
+
headers = None
|
| 12 |
+
if token is not None:
|
| 13 |
+
headers = {"Accept": "application/vnd.github+json", "Authorization": f"Bearer {token}"}
|
| 14 |
+
|
| 15 |
+
# The id of a workflow (not of a workflow run).
|
| 16 |
+
# From a given workflow run (where we have workflow run id), we can get the workflow id by going to
|
| 17 |
+
# https://api.github.com/repos/huggingface/transformers/actions/runs/{workflow_run_id}
|
| 18 |
+
# and check the `workflow_id` key.
|
| 19 |
+
|
| 20 |
+
if not workflow_id:
|
| 21 |
+
workflow_run_id = os.environ["GITHUB_RUN_ID"]
|
| 22 |
+
workflow_run = requests.get(
|
| 23 |
+
f"https://api.github.com/repos/huggingface/transformers/actions/runs/{workflow_run_id}", headers=headers
|
| 24 |
+
).json()
|
| 25 |
+
workflow_id = workflow_run["workflow_id"]
|
| 26 |
+
|
| 27 |
+
url = f"https://api.github.com/repos/huggingface/transformers/actions/workflows/{workflow_id}/runs"
|
| 28 |
+
# On `main` branch + event being `schedule` + not returning PRs + only `num_runs` results
|
| 29 |
+
url += f"?branch=main&exclude_pull_requests=true&per_page={num_runs}"
|
| 30 |
+
|
| 31 |
+
result = requests.get(f"{url}&event=schedule", headers=headers).json()
|
| 32 |
+
workflow_runs = result["workflow_runs"]
|
| 33 |
+
if len(workflow_runs) == 0:
|
| 34 |
+
result = requests.get(f"{url}&event=workflow_run", headers=headers).json()
|
| 35 |
+
workflow_runs = result["workflow_runs"]
|
| 36 |
+
|
| 37 |
+
return workflow_runs
|
| 38 |
+
|
| 39 |
+
|
| 40 |
+
def get_last_daily_ci_run(token, workflow_run_id=None, workflow_id=None, commit_sha=None):
|
| 41 |
+
"""Get the last completed workflow run id of the scheduled (daily) CI."""
|
| 42 |
+
headers = None
|
| 43 |
+
if token is not None:
|
| 44 |
+
headers = {"Accept": "application/vnd.github+json", "Authorization": f"Bearer {token}"}
|
| 45 |
+
|
| 46 |
+
workflow_run = None
|
| 47 |
+
if workflow_run_id is not None and workflow_run_id != "":
|
| 48 |
+
workflow_run = requests.get(
|
| 49 |
+
f"https://api.github.com/repos/huggingface/transformers/actions/runs/{workflow_run_id}", headers=headers
|
| 50 |
+
).json()
|
| 51 |
+
return workflow_run
|
| 52 |
+
|
| 53 |
+
workflow_runs = get_daily_ci_runs(token, workflow_id=workflow_id)
|
| 54 |
+
for run in workflow_runs:
|
| 55 |
+
if commit_sha in [None, ""] and run["status"] == "completed":
|
| 56 |
+
workflow_run = run
|
| 57 |
+
break
|
| 58 |
+
# if `commit_sha` is specified, return the latest completed run with `workflow_run["head_sha"]` matching the specified sha.
|
| 59 |
+
elif commit_sha not in [None, ""] and run["head_sha"] == commit_sha and run["status"] == "completed":
|
| 60 |
+
workflow_run = run
|
| 61 |
+
break
|
| 62 |
+
|
| 63 |
+
return workflow_run
|
| 64 |
+
|
| 65 |
+
|
| 66 |
+
def get_last_ci_run_id():
|
| 67 |
+
token = os.environ.get("GITHUB_TOKEN")
|
| 68 |
+
workflow_run = get_last_daily_ci_run(token, workflow_id=WORKFLOW_ID)
|
| 69 |
+
return workflow_run["id"]
|
| 70 |
+
|
| 71 |
+
|
| 72 |
+
print(get_last_ci_run_id())
|