-
Couldn't load subscription status.
- Fork 320
Refactoring trigger-mobile-metrics script for updated notifications #6844
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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 = { | ||
|
|
@@ -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 | ||
| } | ||
| } | ||
|
|
||
|
|
@@ -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 = { | ||
|
|
@@ -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: | ||
| trigger_job(token, commit, "android-navigation-code-coverage-ci") | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. it's not clear what happens if |
||
| trigger_job(token, commit, "android-navigation-binary-size-ci") | ||
|
|
||
| return 0 | ||
|
|
||
|
|
||
| if __name__ == "__main__": | ||
| Main() | ||
| main() | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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_benchmarkflagThere was a problem hiding this comment.
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?