[llvm] [Github] Add ability to filter jobs in job counting script (PR #82136)

Aiden Grossman via llvm-commits llvm-commits at lists.llvm.org
Sat Feb 17 16:30:46 PST 2024


https://github.com/boomanaiden154 updated https://github.com/llvm/llvm-project/pull/82136

>From ec5aef696f2bd13c4dbd4cd900b884ce25b91067 Mon Sep 17 00:00:00 2001
From: Aiden Grossman <agrossman154 at yahoo.com>
Date: Sat, 17 Feb 2024 23:10:13 +0000
Subject: [PATCH 1/2] [Github] Add ability to filter jobs in job counting
 script

This patch adds a new flag pair, --filter-gha-runners, and
--no-filter-gha-runners, that filters out all non-Github hosted runners
so that we can actual counts of the Github runners, where we are
actually limited.
---
 llvm/utils/count_running_jobs.py | 19 +++++++++++++++++--
 1 file changed, 17 insertions(+), 2 deletions(-)

diff --git a/llvm/utils/count_running_jobs.py b/llvm/utils/count_running_jobs.py
index a53bc02f7b0ae1..bf51de75347701 100644
--- a/llvm/utils/count_running_jobs.py
+++ b/llvm/utils/count_running_jobs.py
@@ -16,7 +16,7 @@
 import github
 
 
-def main(token):
+def main(token, filter_gha_runners):
     workflows = (
         github.Github(args.token)
         .get_repo("llvm/llvm-project")
@@ -28,6 +28,8 @@ def main(token):
     for workflow in workflows:
         for job in workflow.jobs():
             if job.status == "in_progress":
+                if filter_gha_runners and job.runner_group_name != "GitHub Actions":
+                    continue
                 print(f"{workflow.name}/{job.name}")
                 in_progress_jobs += 1
 
@@ -45,5 +47,18 @@ def main(token):
         default=None,
         nargs="?",
     )
+    parser.add_argument(
+        "--filter-gha-runners",
+        help="Only consider jobs running on hosted Github actions runners",
+        action="store_true",
+    )
+    parser.add_argument(
+        "--no-filter-gha-runners",
+        dest="filter_gha_runners",
+        action="store_false",
+        help="Consider all running jobs",
+    )
+    parser.set_defaults(filter_gha_runners=True)
+
     args = parser.parse_args()
-    main(args.token)
+    main(args.token, args.filter_gha_runners)

>From a546da8a56081024ec1da05a78bcb64b12092d5a Mon Sep 17 00:00:00 2001
From: Aiden Grossman <agrossman154 at yahoo.com>
Date: Sun, 18 Feb 2024 00:30:31 +0000
Subject: [PATCH 2/2] Make new option work with older pygithub

---
 llvm/utils/count_running_jobs.py | 15 ++++++++++++---
 1 file changed, 12 insertions(+), 3 deletions(-)

diff --git a/llvm/utils/count_running_jobs.py b/llvm/utils/count_running_jobs.py
index bf51de75347701..dee822a811258e 100644
--- a/llvm/utils/count_running_jobs.py
+++ b/llvm/utils/count_running_jobs.py
@@ -28,8 +28,17 @@ def main(token, filter_gha_runners):
     for workflow in workflows:
         for job in workflow.jobs():
             if job.status == "in_progress":
-                if filter_gha_runners and job.runner_group_name != "GitHub Actions":
-                    continue
+                # TODO(boomanaiden154): Remove the try/except block once we are able
+                # to pull in a PyGithub release that has the runner_group_name property
+                # for workflow jobs.
+                try:
+                    if filter_gha_runners and job.runner_group_name != "GitHub Actions":
+                        continue
+                except:
+                    print(
+                        "Failed to filter runners. Your PyGithub version is "
+                        "most likely too old."
+                    )
                 print(f"{workflow.name}/{job.name}")
                 in_progress_jobs += 1
 
@@ -58,7 +67,7 @@ def main(token, filter_gha_runners):
         action="store_false",
         help="Consider all running jobs",
     )
-    parser.set_defaults(filter_gha_runners=True)
+    parser.set_defaults(filter_gha_runners=False)
 
     args = parser.parse_args()
     main(args.token, args.filter_gha_runners)



More information about the llvm-commits mailing list