2
2
3
3
# Implements https://circleci.com/docs/2.0/api-job-trigger/
4
4
5
- import json
6
5
import os
7
- import sys
8
-
6
+ import json
9
7
import requests
8
+ import sys
10
9
11
-
12
- def trigger_workflow (token , commit , publish ):
10
+ def TriggerWorkflow (token , commit , publish ):
13
11
url = "https://circleci.com/api/v2/project/github/mapbox/mobile-metrics/pipeline"
14
12
15
13
headers = {
@@ -19,9 +17,9 @@ def trigger_workflow(token, commit, publish):
19
17
20
18
data = {
21
19
"parameters" : {
22
- "run_android_navigation_benchmark" : publish ,
23
- "mapbox_slug" : "mapbox/mapbox-navigation-android" ,
24
- "mapbox_hash" : commit
20
+ "run_android_navigation_benchmark" : publish ,
21
+ "mapbox_slug" : "mapbox/mapbox-navigation-android" ,
22
+ "mapbox_hash" : commit
25
23
}
26
24
}
27
25
@@ -31,14 +29,13 @@ def trigger_workflow(token, commit, publish):
31
29
response = requests .post (url , auth = (token , "" ), headers = headers , json = data )
32
30
33
31
if response .status_code != 201 and response .status_code != 200 :
34
- print ("Error triggering the CircleCI: %s." % response .json ()["message" ])
35
- sys .exit (1 )
32
+ print ("Error triggering the CircleCI: %s." % response .json ()["message" ])
33
+ sys .exit (1 )
36
34
else :
37
- response_dict = json .loads (response .text )
38
- print ("Started run_android_navigation_benchmark: %s" % response_dict )
35
+ response_dict = json .loads (response .text )
36
+ print ("Started run_android_navigation_benchmark: %s" % response_dict )
39
37
40
-
41
- def trigger_job (token , commit , job ):
38
+ def TriggerJob (token , commit , job ):
42
39
url = "https://circleci.com/api/v1.1/project/github/mapbox/mobile-metrics/tree/master"
43
40
44
41
headers = {
@@ -48,42 +45,43 @@ def trigger_job(token, commit, job):
48
45
49
46
data = {
50
47
"build_parameters" : {
51
- "CIRCLE_JOB" : job ,
52
- "BENCHMARK_COMMIT" : commit
48
+ "CIRCLE_JOB" : job ,
49
+ "BENCHMARK_COMMIT" : commit
53
50
}
54
51
}
55
52
56
53
response = requests .post (url , auth = (token , "" ), headers = headers , json = data )
57
54
58
55
if response .status_code != 201 and response .status_code != 200 :
59
- print ("Error triggering the CircleCI: %s." % response .json ()["message" ])
60
- sys .exit (1 )
56
+ print ("Error triggering the CircleCI: %s." % response .json ()["message" ])
57
+ sys .exit (1 )
61
58
else :
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
-
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
87
85
88
86
if __name__ == "__main__" :
89
- main ()
87
+ Main ()
0 commit comments