From 46b2d6f937f267137f7744256d829eb5d5d40550 Mon Sep 17 00:00:00 2001 From: kglazko Date: Fri, 2 Aug 2019 11:57:46 -0700 Subject: [PATCH] Upload Fenix Nightly to Nimbledroid #4222 (#4253) --- automation/taskcluster/decision_task.py | 8 +++- automation/taskcluster/lib/tasks.py | 23 +++++++++- .../taskcluster/upload_apk_nimbledroid.py | 46 +++++++++++++++++++ 3 files changed, 74 insertions(+), 3 deletions(-) create mode 100644 automation/taskcluster/upload_apk_nimbledroid.py diff --git a/automation/taskcluster/decision_task.py b/automation/taskcluster/decision_task.py index 768f2dd06..be16d1ef0 100644 --- a/automation/taskcluster/decision_task.py +++ b/automation/taskcluster/decision_task.py @@ -158,6 +158,7 @@ def nightly_to_production_app(is_staging, version_name): build_tasks = {} signing_tasks = {} push_tasks = {} + other_tasks = {} build_task_id = taskcluster.slugId() build_tasks[build_task_id] = BUILDER.craft_assemble_release_task(architectures, build_type, is_staging, version_name) @@ -180,7 +181,12 @@ def nightly_to_production_app(is_staging, version_name): is_staging=is_staging, ) - return (build_tasks, signing_tasks, push_tasks) + nimbledroid_task_id = taskcluster.slugId() + other_tasks[nimbledroid_task_id] = BUILDER.craft_upload_apk_nimbledroid_task( + build_task_id + ) + + return (build_tasks, signing_tasks, push_tasks, other_tasks) if __name__ == "__main__": diff --git a/automation/taskcluster/lib/tasks.py b/automation/taskcluster/lib/tasks.py index 3ab6b5fa1..a482c4511 100644 --- a/automation/taskcluster/lib/tasks.py +++ b/automation/taskcluster/lib/tasks.py @@ -162,7 +162,6 @@ class TaskBuilder(object): 'tier': 1, }, ) - def craft_ui_tests_task(self): artifacts = { @@ -203,7 +202,27 @@ class TaskBuilder(object): artifacts=artifacts, env_vars=env_vars, ) - + + def craft_upload_apk_nimbledroid_task(self, assemble_task_id): + # For GeckoView, upload nightly (it has release config) by default, all Release builds have WV + return self._craft_build_ish_task( + name="Upload Release APK to Nimbledroid", + description='Upload APKs to Nimbledroid for performance measurement and tracking.', + command=' && '.join([ + 'curl --location "{}/{}/artifacts/public/target.apk" > target.apk'.format(_DEFAULT_TASK_URL, assemble_task_id), + 'python automation/taskcluster/upload_apk_nimbledroid.py', + ]), + treeherder={ + 'jobKind': 'test', + 'machine': { + 'platform': 'android-all', + }, + 'symbol': 'compare-locale', + 'tier': 2, + }, + scopes=["secrets:get:project/mobile/fenix/nimbledroid"], + dependencies=[assemble_task_id], + ) def craft_detekt_task(self): return self._craft_clean_gradle_task( diff --git a/automation/taskcluster/upload_apk_nimbledroid.py b/automation/taskcluster/upload_apk_nimbledroid.py new file mode 100644 index 000000000..ef39b6142 --- /dev/null +++ b/automation/taskcluster/upload_apk_nimbledroid.py @@ -0,0 +1,46 @@ +# This Source Code Form is subject to the terms of the Mozilla Public +# License, v. 2.0. If a copy of the MPL was not distributed with this +# file, You can obtain one at http://mozilla.org/MPL/2.0/. + +""" +This script talks to the taskcluster secrets service to obtain the +Nimbledroid account key and upload Klar and Focus apk to Nimbledroid for perf analysis. +""" + +import taskcluster +import requests +import json +import urllib2 +import os + +url = "https://nimbledroid.com/api/v2/apks" + +def uploadApk(apk,key): + headers = {"Accept":"*/*"} + payload = {'auto_scenarios':'false'} + response = requests.post(url, auth=(key, ''), headers=headers, files=apk, data=payload) + + if response.status_code != 201: + print('Status:', response.status_code, 'Headers:', response.headers, 'Error Response:',response.json()) + exit(1) + + # Print Response Details + print 'Response Status Code:', response.status_code + + print '' + print('Reponse Payload:') + print json.dumps(response.json(), indent=4) + + +def uploadNightlyFenixApk(key): + apk_url = 'https://index.taskcluster.net/v1/task/project.mobile.fenix.v2.nightly.latest/artifacts/public/build/arm/target.apk' + apk_data = urllib2.urlopen(apk_url).read() + with open('./fenix_example_nd.apk', 'wb') as f: + f.write(apk_data) + uploadApk({'apk' : open('fenix_example_nd.apk')},key) + +# Get JSON data from taskcluster secrets service +secrets = taskcluster.Secrets({'baseUrl': 'http://taskcluster/secrets/v1'}) +data = secrets.get('project/mobile/fenix/nimbledroid') +# upload the nightly build to Nimbledroid +uploadNightlyFenixApk(data['secret']['api_key'])