mirror of
https://github.com/saymrwulf/transformers.git
synced 2026-05-14 20:58:08 +00:00
Fix call to get_workflow_id. ruff format
This commit is contained in:
parent
0d90a51f72
commit
526bb303d2
2 changed files with 29 additions and 8 deletions
|
|
@ -5,14 +5,30 @@ import requests
|
|||
from get_ci_error_statistics import download_artifact, get_artifacts_links
|
||||
|
||||
|
||||
|
||||
# This is the id of a workflow (not of a workflow run).
|
||||
# From a given workflow run (where we have workflow run id), we can get the workflow id by going to
|
||||
# https://api.github.com/repos/huggingface/transformers/actions/runs/{workflow_run_id}
|
||||
# and check the `workflow_id` key.
|
||||
DEFAULT_WORKFLOW_ID = "90575235"
|
||||
|
||||
def get_daily_ci_runs(token, workflow_id = DEFAULT_WORKFLOW_ID, num_runs=7):
|
||||
|
||||
def get_workflow_id(token, run_id):
|
||||
"""Get the workflow id of the provided run"""
|
||||
|
||||
if run_id is None:
|
||||
return DEFAULT_WORKFLOW_ID
|
||||
|
||||
headers = None
|
||||
if token is not None:
|
||||
headers = {"Accept": "application/vnd.github+json", "Authorization": f"Bearer {token}"}
|
||||
|
||||
url = f"https://api.github.com/repos/huggingface/transformers/actions/runs/{run_id}"
|
||||
result = requests.get(url, headers=headers).json()
|
||||
|
||||
return result["workflow_id"]
|
||||
|
||||
|
||||
def get_daily_ci_runs(token, workflow_id=DEFAULT_WORKFLOW_ID, num_runs=7):
|
||||
"""Get the workflow runs of the scheduled (daily) CI.
|
||||
|
||||
This only selects the runs triggered by the `schedule` event on the `main` branch.
|
||||
|
|
@ -21,7 +37,6 @@ def get_daily_ci_runs(token, workflow_id = DEFAULT_WORKFLOW_ID, num_runs=7):
|
|||
if token is not None:
|
||||
headers = {"Accept": "application/vnd.github+json", "Authorization": f"Bearer {token}"}
|
||||
|
||||
|
||||
url = f"https://api.github.com/repos/huggingface/transformers/actions/workflows/{workflow_id}/runs"
|
||||
# On `main` branch + event being `schedule` + not returning PRs + only `num_runs` results
|
||||
url += f"?branch=main&event=schedule&exclude_pull_requests=true&per_page={num_runs}"
|
||||
|
|
@ -31,7 +46,7 @@ def get_daily_ci_runs(token, workflow_id = DEFAULT_WORKFLOW_ID, num_runs=7):
|
|||
return result["workflow_runs"]
|
||||
|
||||
|
||||
def get_last_daily_ci_runs(token, workflow_id = DEFAULT_WORKFLOW_ID):
|
||||
def get_last_daily_ci_runs(token, workflow_id=DEFAULT_WORKFLOW_ID):
|
||||
"""Get the last completed workflow run id of the scheduled (daily) CI."""
|
||||
workflow_runs = get_daily_ci_runs(token, workflow_id)
|
||||
workflow_run_id = None
|
||||
|
|
@ -55,7 +70,7 @@ def get_last_daily_ci_run_commit(token):
|
|||
return head_sha
|
||||
|
||||
|
||||
def get_last_daily_ci_artifacts(artifact_names, output_dir, token, workflow_id = DEFAULT_WORKFLOW_ID):
|
||||
def get_last_daily_ci_artifacts(artifact_names, output_dir, token, workflow_id=DEFAULT_WORKFLOW_ID):
|
||||
"""Get the artifacts of last completed workflow run id of the scheduled (daily) CI."""
|
||||
workflow_run_id = get_last_daily_ci_runs(token, workflow_id)
|
||||
if workflow_run_id is not None:
|
||||
|
|
@ -68,7 +83,7 @@ def get_last_daily_ci_artifacts(artifact_names, output_dir, token, workflow_id =
|
|||
)
|
||||
|
||||
|
||||
def get_last_daily_ci_reports(artifact_names, output_dir, token, workflow_id = DEFAULT_WORKFLOW_ID):
|
||||
def get_last_daily_ci_reports(artifact_names, output_dir, token, workflow_id=DEFAULT_WORKFLOW_ID):
|
||||
"""Get the artifacts' content of the last completed workflow run id of the scheduled (daily) CI."""
|
||||
get_last_daily_ci_artifacts(artifact_names, output_dir, token, workflow_id)
|
||||
|
||||
|
|
|
|||
|
|
@ -26,7 +26,7 @@ from typing import Dict, List, Optional, Union
|
|||
|
||||
import requests
|
||||
from get_ci_error_statistics import get_jobs
|
||||
from get_previous_daily_ci import get_last_daily_ci_reports
|
||||
from get_previous_daily_ci import get_last_daily_ci_reports, get_workflow_id
|
||||
from huggingface_hub import HfApi
|
||||
from slack_sdk import WebClient
|
||||
|
||||
|
|
@ -1275,8 +1275,14 @@ if __name__ == "__main__":
|
|||
artifact_names = [f"ci_results_{job_name}"]
|
||||
output_dir = os.path.join(os.getcwd(), "previous_reports")
|
||||
os.makedirs(output_dir, exist_ok=True)
|
||||
workflow_id = None
|
||||
token = os.environ["ACCESS_REPO_INFO_TOKEN"]
|
||||
workflow_id = get_workflow_id(token, os.environ["GITHUB_RUN_ID"])
|
||||
prev_ci_artifacts = get_last_daily_ci_reports(
|
||||
artifact_names=artifact_names, output_dir=output_dir, token=os.environ["ACCESS_REPO_INFO_TOKEN"], workflow_id=WORKFLOW_ID
|
||||
artifact_names=artifact_names,
|
||||
output_dir=output_dir,
|
||||
token=token,
|
||||
workflow_id=workflow_id,
|
||||
)
|
||||
|
||||
message = Message(
|
||||
|
|
|
|||
Loading…
Reference in a new issue