FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
RainingKeysPython/.github/scripts/monitor_ci.py at master · Thedoczek/RainingKeysPython · GitHub
Thedoczek
/
RainingKeysPython
Public
forked from
Ian-bug/RainingKeysPython
Notifications
You must be signed in to change notification settings
Fork
0
Star
0
Code
Pull requests
0
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
RainingKeysPython
/
.github
/
scripts
/
monitor_ci.py
Copy path
More file actions
More file actions
Latest commit
History
History
History
137 lines (118 loc) · 4.13 KB
Breadcrumbs
RainingKeysPython
/
.github
/
scripts
/
monitor_ci.py
Copy path
File metadata and controls
137 lines (118 loc) · 4.13 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
#!/usr/bin/env python3
"""Monitor GitHub Actions CI runs until success."""
import
subprocess
import
json
import
time
import
sys
def
get_latest_run_id
():
"""Get latest Code Quality run ID."""
try
:
result
=
subprocess
.
run
(
[
'gh'
,
'run'
,
'list'
,
'--workflow=Code Quality'
,
'--limit=1'
,
'--json'
,
'databaseId'
],
capture_output
=
True
,
text
=
True
,
check
=
True
)
data
=
json
.
loads
(
result
.
stdout
)
if
data
:
return
data
[
0
][
'databaseId'
]
return
None
except
Exception
as
e
:
print
(
f"Error getting run ID:
{
e
}
"
)
return
None
def
get_run_status
(
run_id
):
"""Get status of a specific run."""
try
:
result
=
subprocess
.
run
(
[
'gh'
,
'run'
,
'view'
,
str
(
run_id
),
'--json'
,
'status'
,
'conclusion'
],
capture_output
=
True
,
text
=
True
,
check
=
True
)
data
=
json
.
loads
(
result
.
stdout
)
return
data
.
get
(
'status'
),
data
.
get
(
'conclusion'
)
except
Exception
as
e
:
print
(
f"Error getting run status:
{
e
}
"
)
return
None
,
None
def
get_job_errors
(
run_id
):
"""Get error logs from failed jobs."""
try
:
result
=
subprocess
.
run
(
[
'gh'
,
'run'
,
'view'
,
str
(
run_id
),
'--log'
],
capture_output
=
True
,
text
=
True
,
check
=
True
)
logs
=
result
.
stdout
# Extract error lines
errors
=
[]
for
line
in
logs
.
split
(
'
\n
'
):
if
'Error:'
in
line
or
'Traceback'
in
line
or
'X'
in
line
:
if
'Checkout code'
not
in
line
and
'Set up Python'
not
in
line
:
errors
.
append
(
line
)
return
errors
[:
20
]
# Return first 20 errors
except
Exception
as
e
:
print
(
f"Error getting job logs:
{
e
}
"
)
return
[]
def
monitor_run
(
run_id
,
max_wait
=
1800
):
"""Monitor a run until it completes or times out."""
print
(
f"
\n
{
'='
*
60
}
"
)
print
(
f"Monitoring Run ID:
{
run_id
}
"
)
print
(
f"
{
'='
*
60
}
\n
"
)
start_time
=
time
.
time
()
check_interval
=
30
# Check every 30 seconds
while
True
:
elapsed
=
time
.
time
()
-
start_time
if
elapsed
>
max_wait
:
print
(
f"
\n
Timeout after
{
max_wait
}
seconds"
)
return
False
status
,
conclusion
=
get_run_status
(
run_id
)
if
status
is
None
:
print
(
f"Unable to get status, retrying..."
)
time
.
sleep
(
check_interval
)
continue
if
status
==
'queued'
:
print
(
f"[QUEUED] (
{
int
(
elapsed
)
}
s elapsed)"
)
elif
status
==
'in_progress'
:
print
(
f"[IN PROGRESS] (
{
int
(
elapsed
)
}
s elapsed)"
)
elif
status
==
'completed'
:
print
(
f"
\n
Run completed! Status:
{
status
}
, Conclusion:
{
conclusion
}
"
)
if
conclusion
==
'success'
:
print
(
"
\n
*** All CI checks passed! ***"
)
return
True
else
:
print
(
f"
\n
Run failed with conclusion:
{
conclusion
}
"
)
errors
=
get_job_errors
(
run_id
)
if
errors
:
print
(
"
\n
Errors found:"
)
for
i
,
error
in
enumerate
(
errors
,
1
):
print
(
f"
{
i
}
.
{
error
}
"
)
return
False
time
.
sleep
(
check_interval
)
if
__name__
==
"__main__"
:
print
(
"GitHub Actions CI Monitor"
)
print
(
"="
*
60
)
# Get latest run ID
run_id
=
get_latest_run_id
()
if
not
run_id
:
print
(
"Could not find any Code Quality runs"
)
sys
.
exit
(
1
)
# Check if run is already completed
status
,
conclusion
=
get_run_status
(
run_id
)
if
status
==
'completed'
:
print
(
f"
\n
Latest run (
{
run_id
}
) already completed"
)
print
(
f"Status:
{
status
}
, Conclusion:
{
conclusion
}
"
)
if
conclusion
==
'success'
:
print
(
"
\n
All checks passed!"
)
sys
.
exit
(
0
)
else
:
print
(
"
\n
Run failed"
)
errors
=
get_job_errors
(
run_id
)
if
errors
:
print
(
"
\n
Errors found:"
)
for
i
,
error
in
enumerate
(
errors
,
1
):
print
(
f"
{
i
}
.
{
error
}
"
)
sys
.
exit
(
1
)
# Monitor the run
success
=
monitor_run
(
run_id
)
sys
.
exit
(
0
if
success
else
1
)
Back
|
FazBrowse Home
|
New Git URL