2
2
3
3
# Implements https://circleci.com/docs/2.0/api-job-trigger/
4
4
5
- import os
6
5
import json
7
- import requests
6
+ import os
8
7
import sys
9
8
10
- def TriggerWorkflow (token , commit , publish ):
9
+ import requests
10
+
11
+
12
+ def trigger_workflow (token , commit , publish ):
11
13
url = "https://circleci.com/api/v2/project/github/mapbox/mobile-metrics/pipeline"
12
14
13
15
headers = {
@@ -17,9 +19,9 @@ def TriggerWorkflow(token, commit, publish):
17
19
18
20
data = {
19
21
"parameters" : {
20
- "run_android_navigation_benchmark" : publish ,
21
- "mapbox_slug" : "mapbox/mapbox-navigation-android" ,
22
- "mapbox_hash" : commit
22
+ "run_android_navigation_benchmark" : publish ,
23
+ "mapbox_slug" : "mapbox/mapbox-navigation-android" ,
24
+ "mapbox_hash" : commit
23
25
}
24
26
}
25
27
@@ -29,13 +31,14 @@ def TriggerWorkflow(token, commit, publish):
29
31
response = requests .post (url , auth = (token , "" ), headers = headers , json = data )
30
32
31
33
if response .status_code != 201 and response .status_code != 200 :
32
- print ("Error triggering the CircleCI: %s." % response .json ()["message" ])
33
- sys .exit (1 )
34
+ print ("Error triggering the CircleCI: %s." % response .json ()["message" ])
35
+ sys .exit (1 )
34
36
else :
35
- response_dict = json .loads (response .text )
36
- print ("Started run_android_navigation_benchmark: %s" % response_dict )
37
+ response_dict = json .loads (response .text )
38
+ print ("Started run_android_navigation_benchmark: %s" % response_dict )
37
39
38
- def TriggerJob (token , commit , job ):
40
+
41
+ def trigger_job (token , commit , job ):
39
42
url = "https://circleci.com/api/v1.1/project/github/mapbox/mobile-metrics/tree/master"
40
43
41
44
headers = {
@@ -45,43 +48,42 @@ def TriggerJob(token, commit, job):
45
48
46
49
data = {
47
50
"build_parameters" : {
48
- "CIRCLE_JOB" : job ,
49
- "BENCHMARK_COMMIT" : commit
51
+ "CIRCLE_JOB" : job ,
52
+ "BENCHMARK_COMMIT" : commit
50
53
}
51
54
}
52
55
53
56
response = requests .post (url , auth = (token , "" ), headers = headers , json = data )
54
57
55
58
if response .status_code != 201 and response .status_code != 200 :
56
- print ("Error triggering the CircleCI: %s." % response .json ()["message" ])
57
- sys .exit (1 )
59
+ print ("Error triggering the CircleCI: %s." % response .json ()["message" ])
60
+ sys .exit (1 )
58
61
else :
59
- response_dict = json .loads (response .text )
60
- build_url = response_dict ['build_url' ]
61
- print ("Started %s: %s" % (job , build_url ))
62
-
63
- def Main ():
64
- token = os .getenv ("MOBILE_METRICS_TOKEN" )
65
- commit = os .getenv ("CIRCLE_SHA1" )
66
-
67
- if token is None :
68
- print ("Error triggering because MOBILE_METRICS_TOKEN is not set" )
69
- sys .exit (1 )
70
-
71
- # Publish results that have been committed to the main branch.
72
- # Development runs can be found in CircleCI after manually triggered.
73
- publishResults = os .getenv ("CIRCLE_BRANCH" ) == "main"
74
- TriggerWorkflow (token , commit , publishResults )
75
-
76
- if publishResults :
77
- TriggerJob (token , commit , "android-navigation-benchmark" )
78
- TriggerJob (token , commit , "android-navigation-code-coverage" )
79
- TriggerJob (token , commit , "android-navigation-binary-size" )
80
- else :
81
- TriggerJob (token , commit , "android-navigation-code-coverage-ci" )
82
- TriggerJob (token , commit , "android-navigation-binary-size-ci" )
83
-
84
- return 0
62
+ response_dict = json .loads (response .text )
63
+ build_url = response_dict ['build_url' ]
64
+ print ("Started %s: %s" % (job , build_url ))
65
+
66
+
67
+ def main ():
68
+ token = os .getenv ("MOBILE_METRICS_TOKEN" )
69
+ commit = os .getenv ("CIRCLE_SHA1" )
70
+
71
+ if token is None :
72
+ print ("Error triggering because MOBILE_METRICS_TOKEN is not set" )
73
+ sys .exit (1 )
74
+
75
+ # Publish results that have been committed to the main branch.
76
+ # Development runs can be found in CircleCI after manually triggered.
77
+ publish_results = os .getenv ("CIRCLE_BRANCH" ) == "main"
78
+
79
+ trigger_workflow (token , commit , publish_results )
80
+
81
+ if not publish_results :
82
+ trigger_job (token , commit , "android-navigation-code-coverage-ci" )
83
+ trigger_job (token , commit , "android-navigation-binary-size-ci" )
84
+
85
+ return 0
86
+
85
87
86
88
if __name__ == "__main__" :
87
- Main ()
89
+ main ()
0 commit comments