-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathworkflow-status.py
More file actions
49 lines (46 loc) · 1.76 KB
/
workflow-status.py
File metadata and controls
49 lines (46 loc) · 1.76 KB
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
import os
import sys
import time
import json
import requests
headers = {
"Accept": "application/vnd.github+json",
"Authorization": f"Bearer {os.getenv('GH_TOKEN')}",
"X-GitHub-Api-Version": "2022-11-28",
"Content-Type": "application/x-www-form-urlencoded"
}
run_id = os.getenv('INFRA_WORKFLOW_ID')
repo_name = os.getenv('repo_name')
queued_time_limit = 60*30 ## seconds to wait before stop checking
start_time = time.time()
try:
while True:
print(f"https://api.github.com/repos/{repo_name}/actions/runs/{run_id}")
response = requests.get(
f"https://api.github.com/repos/{repo_name}/actions/runs/{run_id}",
headers=headers
).json()
if response.get('status') == "completed":
if response.get('conclusion') == "success":
print("================================================")
print("SUCCESS")
print("================================================")
break
else:
print("------------------------------------------------")
print("FAILURE")
print("------------------------------------------------")
raise
else:
print(f"The job is being run: {response.get('status')}")
time.sleep(30)
# check if taking too long
current_time = time.time()
queued_duration = current_time - start_time
if queued_duration > queued_time_limit:
print(f"Workflow has been queued for too long ({queued_duration / 60:.2f} minutes). Failing the job.")
raise
except Exception as err:
print(f"Exception occurred while processing your request - please verify the logs for more information")
print(err)
raise