Skip to content

Commit 38476b0

Browse files
[Github] Add script to count running jobs (#80250)
This patch adds a script to automatically query the number of running jobs and print them to the terminal as this functionality isn't available through the Github UI (unless you are a Github administrator).
1 parent 03881dc commit 38476b0

File tree

1 file changed

+49
-0
lines changed

1 file changed

+49
-0
lines changed

llvm/utils/count_running_jobs.py

+49
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
# Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
2+
# See https://llvm.org/LICENSE.txt for license information.
3+
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
4+
"""Tool for counting the number of currently running Github actions jobs.
5+
6+
This tool counts and enumerates the currently active jobs in Github actions
7+
for the monorepo.
8+
9+
python3 ./count_running_jobs.py --token=<github token>
10+
11+
Note that the token argument is optional. If it is not specified, the queries
12+
will be performed unauthenticated.
13+
"""
14+
15+
import argparse
16+
import github
17+
18+
19+
def main(token):
20+
workflows = (
21+
github.Github(args.token)
22+
.get_repo("llvm/llvm-project")
23+
.get_workflow_runs(status="in_progress")
24+
)
25+
26+
in_progress_jobs = 0
27+
28+
for workflow in workflows:
29+
for job in workflow.jobs():
30+
if job.status == "in_progress":
31+
print(f"{workflow.name}/{job.name}")
32+
in_progress_jobs += 1
33+
34+
print(f"\nFound {in_progress_jobs} running jobs.")
35+
36+
37+
if __name__ == "__main__":
38+
parser = argparse.ArgumentParser(
39+
description="A tool for listing and counting Github actions jobs"
40+
)
41+
parser.add_argument(
42+
"--token",
43+
type=str,
44+
help="The Github token to use to authorize with the API",
45+
default=None,
46+
nargs="?",
47+
)
48+
args = parser.parse_args()
49+
main(args.token)

0 commit comments

Comments
 (0)