From 526bb303d245cc053a9da8c8d2252172568aa9b1 Mon Sep 17 00:00:00 2001 From: Ivar Flakstad <69173633+ivarflakstad@users.noreply.github.com> Date: Wed, 15 Jan 2025 12:07:47 +0100 Subject: [PATCH] Fix call to get_workflow_id. ruff format --- utils/get_previous_daily_ci.py | 27 +++++++++++++++++++++------ utils/notification_service.py | 10 ++++++++-- 2 files changed, 29 insertions(+), 8 deletions(-) diff --git a/utils/get_previous_daily_ci.py b/utils/get_previous_daily_ci.py index e75b4896d..c46a924ea 100644 --- a/utils/get_previous_daily_ci.py +++ b/utils/get_previous_daily_ci.py @@ -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) diff --git a/utils/notification_service.py b/utils/notification_service.py index d361ffa72..d501a24eb 100644 --- a/utils/notification_service.py +++ b/utils/notification_service.py @@ -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(