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

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.
This commit is contained in:
Aiden Grossman 2024-02-19 16:28:47 -08:00 committed by GitHub
parent eac8604d98
commit 66d8377dbd
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -16,7 +16,7 @@ import argparse
import github
def main(token):
def main(token, filter_gha_runners):
workflows = (
github.Github(args.token)
.get_repo("llvm/llvm-project")
@ -28,6 +28,17 @@ def main(token):
for workflow in workflows:
for job in workflow.jobs():
if job.status == "in_progress":
# 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
@ -45,5 +56,18 @@ if __name__ == "__main__":
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=False)
args = parser.parse_args()
main(args.token)
main(args.token, args.filter_gha_runners)