-
Notifications
You must be signed in to change notification settings - Fork 320
Expand file tree
/
Copy pathtrigger-mobile-metrics.py
More file actions
89 lines (64 loc) · 2.49 KB
/
trigger-mobile-metrics.py
File metadata and controls
89 lines (64 loc) · 2.49 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
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
#!/usr/bin/env python3
# Implements https://circleci.com/docs/2.0/api-job-trigger/
import json
import os
import sys
import requests
def trigger_workflow(token, commit, publish):
url = "https://circleci.com/api/v2/project/github/mapbox/mobile-metrics/pipeline"
headers = {
"Content-Type": "application/json",
"Accept": "application/json",
}
data = {
"parameters": {
"run_android_navigation_benchmark": publish,
"mapbox_slug": "mapbox/mapbox-navigation-android",
"mapbox_hash": commit
}
}
# Use this to test your mobile-metrics branches.
# data["branch"]: "mobile-metrics-branch-name"
response = requests.post(url, auth=(token, ""), headers=headers, json=data)
if response.status_code != 201 and response.status_code != 200:
print("Error triggering the CircleCI: %s." % response.json()["message"])
sys.exit(1)
else:
response_dict = json.loads(response.text)
print("Started run_android_navigation_benchmark: %s" % response_dict)
def trigger_job(token, commit, job):
url = "https://circleci.com/api/v1.1/project/github/mapbox/mobile-metrics/tree/master"
headers = {
"Content-Type": "application/json",
"Accept": "application/json",
}
data = {
"build_parameters": {
"CIRCLE_JOB": job,
"BENCHMARK_COMMIT": commit
}
}
response = requests.post(url, auth=(token, ""), headers=headers, json=data)
if response.status_code != 201 and response.status_code != 200:
print("Error triggering the CircleCI: %s." % response.json()["message"])
sys.exit(1)
else:
response_dict = json.loads(response.text)
build_url = response_dict['build_url']
print("Started %s: %s" % (job, build_url))
def main():
token = os.getenv("MOBILE_METRICS_TOKEN")
commit = os.getenv("CIRCLE_SHA1")
if token is None:
print("Error triggering because MOBILE_METRICS_TOKEN is not set")
sys.exit(1)
# Publish results that have been committed to the main branch.
# Development runs can be found in CircleCI after manually triggered.
publish_results = os.getenv("CIRCLE_BRANCH") == "main"
trigger_workflow(token, commit, publish_results)
if not publish_results:
trigger_job(token, commit, "android-navigation-code-coverage-ci")
trigger_job(token, commit, "android-navigation-binary-size-ci")
return 0
if __name__ == "__main__":
main()