Skip to content

[Github] Add script to count running jobs #80250

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 6, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 49 additions & 0 deletions llvm/utils/count_running_jobs.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
# Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
# See https://llvm.org/LICENSE.txt for license information.
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
"""Tool for counting the number of currently running Github actions jobs.

This tool counts and enumerates the currently active jobs in Github actions
for the monorepo.

python3 ./count_running_jobs.py --token=<github token>

Note that the token argument is optional. If it is not specified, the queries
will be performed unauthenticated.
"""

import argparse
import github


def main(token):
workflows = (
github.Github(args.token)
.get_repo("llvm/llvm-project")
.get_workflow_runs(status="in_progress")
)

in_progress_jobs = 0

for workflow in workflows:
for job in workflow.jobs():
if job.status == "in_progress":
print(f"{workflow.name}/{job.name}")
in_progress_jobs += 1

print(f"\nFound {in_progress_jobs} running jobs.")


if __name__ == "__main__":
parser = argparse.ArgumentParser(
description="A tool for listing and counting Github actions jobs"
)
parser.add_argument(
"--token",
type=str,
help="The Github token to use to authorize with the API",
default=None,
nargs="?",
)
args = parser.parse_args()
main(args.token)