1
1
import argparse
2
- import requests
3
- import time
4
2
import sys
3
+ import time
4
+
5
+ import requests
6
+
5
7
6
8
def parse_args ():
7
9
parser = argparse .ArgumentParser ()
@@ -16,32 +18,35 @@ def parse_args():
16
18
17
19
return parser .parse_args ()
18
20
21
+
19
22
if __name__ == "__main__" :
20
23
args = parse_args ()
21
24
22
25
# Submit build job
23
26
headers = {
24
27
"CF-Access-Client-Id" : args .client_id ,
25
- "CF-Access-Client-Secret" : args .secret
28
+ "CF-Access-Client-Secret" : args .secret ,
26
29
}
27
30
28
31
payload = {
29
32
"pr_id" : args .pr_id ,
30
33
"commit_sha" : args .sha ,
31
34
"run_attempt" : args .run_attempt ,
32
- "branch_name" : args .branch_name
35
+ "branch_name" : args .branch_name ,
33
36
}
34
37
35
- workflow_id = ''
38
+ workflow_id = ""
36
39
try :
37
40
resp = requests .post (args .URL , headers = headers , json = payload )
38
41
resp .raise_for_status ()
39
42
40
- workflow_id = resp .json (). id
43
+ workflow_id = resp .json ()[ "workflow_id" ]
41
44
except Exception as err :
42
45
print (f"Unexpected error { err = } , { type (err )= } " )
43
46
sys .exit (1 )
44
47
48
+ print ("Internal build submitted" )
49
+
45
50
time .sleep (30 )
46
51
47
52
# Poll build status
@@ -50,15 +55,18 @@ def parse_args():
50
55
51
56
while failed_requests < FAILED_REQUEST_LIMIT :
52
57
try :
53
- resp = requests .get (args .URL , headers = headers , params = { 'id' : workflow_id })
58
+ resp = requests .get (args .URL , headers = headers , params = {"id" : workflow_id })
54
59
resp .raise_for_status ()
55
60
56
- status = resp .json (). status
61
+ status = resp .json ()[ " status" ]
57
62
if status == "errored" :
63
+ print ("Build failed" )
58
64
sys .exit (1 )
59
65
elif status == "complete" :
60
66
break
61
67
68
+ print ("Waiting for build to finish.." )
69
+
62
70
except Exception as err :
63
71
print (f"Unexpected error { err = } , { type (err )= } " )
64
72
failed_requests = failed_requests + 1
@@ -68,4 +76,3 @@ def parse_args():
68
76
sys .exit (1 )
69
77
70
78
print ("Internal build succeeded" )
71
-
0 commit comments