Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
86 changes: 44 additions & 42 deletions scripts/trigger-mobile-metrics.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,14 @@

# Implements https://circleci.com/docs/2.0/api-job-trigger/

import os
import json
import requests
import os
import sys

def TriggerWorkflow(token, commit, publish):
import requests


def trigger_workflow(token, commit, publish):
url = "https://circleci.com/api/v2/project/github/mapbox/mobile-metrics/pipeline"

headers = {
Expand All @@ -17,9 +19,9 @@ def TriggerWorkflow(token, commit, publish):

data = {
"parameters": {
"run_android_navigation_benchmark": publish,
"mapbox_slug": "mapbox/mapbox-navigation-android",
"mapbox_hash": commit
"run_android_navigation_benchmark": publish,
"mapbox_slug": "mapbox/mapbox-navigation-android",
"mapbox_hash": commit
}
}

Expand All @@ -29,13 +31,14 @@ def TriggerWorkflow(token, commit, publish):
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)
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)
response_dict = json.loads(response.text)
print("Started run_android_navigation_benchmark: %s" % response_dict)

def TriggerJob(token, commit, job):

def trigger_job(token, commit, job):
url = "https://circleci.com/api/v1.1/project/github/mapbox/mobile-metrics/tree/master"

headers = {
Expand All @@ -45,43 +48,42 @@ def TriggerJob(token, commit, job):

data = {
"build_parameters": {
"CIRCLE_JOB": job,
"BENCHMARK_COMMIT": commit
"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)
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.
publishResults = os.getenv("CIRCLE_BRANCH") == "main"
TriggerWorkflow(token, commit, publishResults)

if publishResults:
TriggerJob(token, commit, "android-navigation-benchmark")
TriggerJob(token, commit, "android-navigation-code-coverage")
TriggerJob(token, commit, "android-navigation-binary-size")
else:
TriggerJob(token, commit, "android-navigation-code-coverage-ci")
TriggerJob(token, commit, "android-navigation-binary-size-ci")

return 0
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:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What happened to the branch where publish_results is True?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These jobs will be called by running the workflow with run_android_navigation_benchmark flag

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What do you mean? Why don't we publish results anymore?

trigger_job(token, commit, "android-navigation-code-coverage-ci")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it's not clear what happens if publish_results == false, the script trigger workflow and additionally triggered jobs, right?

trigger_job(token, commit, "android-navigation-binary-size-ci")

return 0


if __name__ == "__main__":
Main()
main()