[fenix] Fixes https://github.com/mozilla-mobile/fenix/issues/5156; Don't publish...
[gecko.git] / mobile / android / fenix / automation / taskcluster / lib / tasks.py
blob8fd03e1770e3616d0a3e9a2b88c58f822e979a55
1 # This Source Code Form is subject to the terms of the Mozilla Public
2 # License, v. 2.0. If a copy of the MPL was not distributed with this
3 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
5 from __future__ import print_function
7 import arrow
8 import datetime
9 import json
10 import taskcluster
12 from lib.util import upper_case_first_letter, convert_camel_case_into_kebab_case, lower_case_first_letter
14 DEFAULT_EXPIRES_IN = '1 year'
15 DEFAULT_APK_ARTIFACT_LOCATION = 'public/target.apk'
16 _OFFICIAL_REPO_URL = 'https://github.com/mozilla-mobile/fenix'
17 _DEFAULT_TASK_URL = 'https://queue.taskcluster.net/v1/task'
18 GOOGLE_APPLICATION_CREDENTIALS = '.firebase_token.json'
19 # Bug 1558456 - Stop tracking youtube-playback-test on motoG5 for >1080p cases
20 ARM_RAPTOR_URL_PARAMS = [
21 "exclude=1,2,9,10,17,18,21,22,26,28,30,32,39,40,47,"
22 "48,55,56,63,64,71,72,79,80,83,84,89,90,95,96",
26 class TaskBuilder(object):
27 def __init__(
28 self,
29 task_id,
30 repo_url,
31 git_ref,
32 short_head_branch, commit, owner, source, scheduler_id, date_string,
33 tasks_priority='lowest',
34 trust_level=1
36 self.task_id = task_id
37 self.repo_url = repo_url
38 self.git_ref = git_ref
39 self.short_head_branch = short_head_branch
40 self.commit = commit
41 self.owner = owner
42 self.source = source
43 self.scheduler_id = scheduler_id
44 self.trust_level = trust_level
45 self.tasks_priority = tasks_priority
46 self.date = arrow.get(date_string)
47 self.trust_level = trust_level
49 def craft_assemble_release_task(self, variant, channel, is_staging, version_name):
50 if is_staging:
51 secret_index = 'garbage/staging/project/mobile/fenix'
52 else:
53 secret_index = 'project/mobile/fenix/{}'.format(channel)
55 pre_gradle_commands = (
56 'python automation/taskcluster/helper/get-secret.py -s {} -k {} -f {}'.format(
57 secret_index, key, target_file
59 for key, target_file in (
60 ('sentry_dsn', '.sentry_token'),
61 ('leanplum', '.leanplum_token'),
62 ('adjust', '.adjust_token'),
63 ('firebase', 'app/src/{}/res/values/firebase.xml'.format(variant.build_type)),
67 capitalized_build_type = upper_case_first_letter(variant.build_type)
68 gradle_commands = (
69 './gradlew --no-daemon -PversionName="{}" clean test assemble{}'.format(
70 version_name, capitalized_build_type),
73 command = ' && '.join(
74 cmd
75 for commands in (pre_gradle_commands, gradle_commands)
76 for cmd in commands
77 if cmd
80 routes = [] if is_staging else [
81 "notify.email.fenix-eng-notifications@mozilla.com.on-failed"
84 return self._craft_build_ish_task(
85 name='Build {} task'.format(capitalized_build_type),
86 description='Build Fenix {} from source code'.format(capitalized_build_type),
87 command=command,
88 scopes=[
89 "secrets:get:{}".format(secret_index)
91 artifacts=variant.artifacts(),
92 routes=routes,
93 treeherder={
94 'jobKind': 'build',
95 'machine': {
96 'platform': 'android-all',
98 'symbol': '{}-A'.format(variant.build_type),
99 'tier': 1,
103 def craft_assemble_raptor_task(self, variant):
104 command = ' && '.join((
105 'echo "https://fake@sentry.prod.mozaws.net/368" > .sentry_token',
106 'echo "--" > .adjust_token',
107 'echo "-:-" > .leanplum_token',
108 './gradlew --no-daemon clean assemble{}'.format(variant.name),
111 return self._craft_build_ish_task(
112 name='assemble: {}'.format(variant.name),
113 description='Building and testing variant {}'.format(variant.name),
114 command=command,
115 artifacts=variant.artifacts(),
116 treeherder={
117 'groupSymbol': variant.build_type,
118 'jobKind': 'build',
119 'machine': {
120 'platform': 'android-all',
122 'symbol': 'A',
123 'tier': 1,
127 def craft_assemble_pr_task(self, variant):
128 return self._craft_clean_gradle_task(
129 name='assemble: {}'.format(variant.name),
130 description='Building and testing variant {}'.format(variant.name),
131 gradle_task='assemble{}'.format(variant.name),
132 artifacts=variant.artifacts(),
133 treeherder={
134 'groupSymbol': variant.build_type,
135 'jobKind': 'build',
136 'machine': {
137 'platform': 'android-all',
139 'symbol': 'A',
140 'tier': 1,
144 def craft_test_pr_task(self, variant):
145 # upload coverage only once, if the variant is arm64
146 test_gradle_command = \
147 '-Pcoverage jacocoGeckoNightlyDebugTestReport && automation/taskcluster/upload_coverage_report.sh'
149 return self._craft_clean_gradle_task(
150 name='test: {}'.format(variant.name),
151 description='Building and testing variant {}'.format(variant.name),
152 gradle_task=test_gradle_command,
153 treeherder={
154 'groupSymbol': variant.build_type,
155 'jobKind': 'test',
156 'machine': {
157 'platform': 'android-all',
159 'symbol': 'T',
160 'tier': 1,
162 scopes=[
163 'secrets:get:project/mobile/fenix/public-tokens'
167 def craft_ui_tests_task(self):
168 artifacts = {
169 "public": {
170 "type": "directory",
171 "path": "/build/fenix/results",
172 "expires": taskcluster.stringDate(taskcluster.fromNow(DEFAULT_EXPIRES_IN))
176 env_vars = {
177 "GOOGLE_PROJECT": "moz-fenix",
178 "GOOGLE_APPLICATION_CREDENTIALS": ".firebase_token.json"
181 gradle_commands = (
182 './gradlew --no-daemon clean assemble assembleAndroidTest',
185 test_commands = (
186 'automation/taskcluster/androidTest/ui-test.sh arm64-v8a -1',
187 'automation/taskcluster/androidTest/ui-test.sh armeabi-v7a -1',
190 command = ' && '.join(
192 for commands in (gradle_commands, test_commands)
193 for cmd in commands
194 if cmd
197 return self._craft_build_ish_task(
198 name='Fenix - UI test',
199 description='Execute Gradle tasks for UI tests',
200 command=command,
201 scopes=[
202 'secrets:get:project/mobile/fenix/firebase'
204 artifacts=artifacts,
205 env_vars=env_vars,
208 def craft_upload_apk_nimbledroid_task(self, assemble_task_id):
209 # For GeckoView, upload nightly (it has release config) by default, all Release builds have WV
210 return self._craft_build_ish_task(
211 name="Upload Release APK to Nimbledroid",
212 description='Upload APKs to Nimbledroid for performance measurement and tracking.',
213 command=' && '.join([
214 'curl --location "{}/{}/artifacts/public/build/armeabi-v7a/geckoNightly/target.apk" > target.apk'.format(_DEFAULT_TASK_URL, assemble_task_id),
215 'python automation/taskcluster/upload_apk_nimbledroid.py',
217 treeherder={
218 'jobKind': 'test',
219 'machine': {
220 'platform': 'android-all',
222 'symbol': 'compare-locale',
223 'tier': 2,
225 scopes=["secrets:get:project/mobile/fenix/nimbledroid"],
226 dependencies=[assemble_task_id],
229 def craft_detekt_task(self):
230 return self._craft_clean_gradle_task(
231 name='detekt',
232 description='Running detekt code quality checks',
233 gradle_task='detekt',
234 treeherder={
235 'jobKind': 'test',
236 'machine': {
237 'platform': 'lint',
239 'symbol': 'detekt',
240 'tier': 1,
245 def craft_ktlint_task(self):
246 return self._craft_clean_gradle_task(
247 name='ktlint',
248 description='Running ktlint code quality checks',
249 gradle_task='ktlint',
250 treeherder={
251 'jobKind': 'test',
252 'machine': {
253 'platform': 'lint',
255 'symbol': 'ktlint',
256 'tier': 1,
260 def craft_lint_task(self):
261 return self._craft_clean_gradle_task(
262 name='lint',
263 description='Running lint for aarch64 release variant',
264 gradle_task='lintDebug',
265 treeherder={
266 'jobKind': 'test',
267 'machine': {
268 'platform': 'lint',
270 'symbol': 'lint',
271 'tier': 1,
275 def _craft_clean_gradle_task(
276 self, name, description, gradle_task, artifacts=None, routes=None, treeherder=None, scopes=None
278 return self._craft_build_ish_task(
279 name=name,
280 description=description,
281 command='./gradlew --no-daemon clean {}'.format(gradle_task),
282 artifacts=artifacts,
283 routes=routes,
284 treeherder=treeherder,
285 scopes=scopes,
288 def craft_compare_locales_task(self):
289 return self._craft_build_ish_task(
290 name='compare-locales',
291 description='Validate strings.xml with compare-locales',
292 command=(
293 'pip install "compare-locales>=5.0.2,<6.0" && '
294 'compare-locales --validate l10n.toml .'
296 treeherder={
297 'jobKind': 'test',
298 'machine': {
299 'platform': 'lint',
301 'symbol': 'compare-locale',
302 'tier': 2,
306 def _craft_build_ish_task(
307 self, name, description, command, dependencies=None, artifacts=None,
308 routes=None, treeherder=None, env_vars=None, scopes=None
310 dependencies = [] if dependencies is None else dependencies
311 artifacts = {} if artifacts is None else artifacts
312 scopes = [] if scopes is None else scopes
313 routes = [] if routes is None else routes
314 env_vars = {} if env_vars is None else env_vars
316 checkout_command = ' && '.join([
317 "export TERM=dumb",
318 "git fetch {} {}".format(self.repo_url, self.git_ref),
319 "git config advice.detachedHead false",
320 "git checkout FETCH_HEAD",
323 command = '{} && {}'.format(checkout_command, command)
325 features = {}
326 if artifacts:
327 features['chainOfTrust'] = True
328 if any(scope.startswith('secrets:') for scope in scopes):
329 features['taskclusterProxy'] = True
330 payload = {
331 "features": features,
332 "env": env_vars,
333 "maxRunTime": 7200,
334 "image": "mozillamobile/fenix:1.4",
335 "command": [
336 "/bin/bash",
337 "--login",
338 "-cx",
339 command
341 "artifacts": artifacts,
344 return self._craft_default_task_definition(
345 worker_type='mobile-{}-b-fenix'.format(self.trust_level),
346 provisioner_id='aws-provisioner-v1',
347 name=name,
348 description=description,
349 payload=payload,
350 dependencies=dependencies,
351 routes=routes,
352 scopes=scopes,
353 treeherder=treeherder,
356 def _craft_signing_task(self, name, description, signing_type, assemble_task_id, apk_paths, routes, treeherder):
357 signing_format = "autograph_apk"
358 payload = {
359 'upstreamArtifacts': [{
360 'paths': apk_paths,
361 'formats': [signing_format],
362 'taskId': assemble_task_id,
363 'taskType': 'build'
367 return self._craft_default_task_definition(
368 worker_type='mobile-signing-dep-v1' if signing_type == 'dep' else 'mobile-signing-v1',
369 provisioner_id='scriptworker-prov-v1',
370 dependencies=[assemble_task_id],
371 routes=routes,
372 scopes=[
373 "project:mobile:fenix:releng:signing:format:{}".format(signing_format),
374 "project:mobile:fenix:releng:signing:cert:{}-signing".format(signing_type),
376 name=name,
377 description=description,
378 payload=payload,
379 treeherder=treeherder,
382 def _craft_default_task_definition(
383 self,
384 worker_type,
385 provisioner_id,
386 name,
387 description,
388 payload,
389 dependencies=None,
390 routes=None,
391 scopes=None,
392 treeherder=None,
393 notify=None,
395 dependencies = [] if dependencies is None else dependencies
396 scopes = [] if scopes is None else scopes
397 routes = [] if routes is None else routes
398 treeherder = {} if treeherder is None else treeherder
400 created = datetime.datetime.now()
401 deadline = taskcluster.fromNow('1 day')
402 expires = taskcluster.fromNow(DEFAULT_EXPIRES_IN)
404 if self.trust_level == 3:
405 routes.append('tc-treeherder.v2.fenix.{}'.format(self.commit))
407 extra = {
408 "treeherder": treeherder,
410 if notify:
411 extra['notify'] = notify
413 return {
414 "provisionerId": provisioner_id,
415 "workerType": worker_type,
416 "taskGroupId": self.task_id,
417 "schedulerId": self.scheduler_id,
418 "created": taskcluster.stringDate(created),
419 "deadline": taskcluster.stringDate(deadline),
420 "expires": taskcluster.stringDate(expires),
421 "retries": 5,
422 "tags": {},
423 "priority": self.tasks_priority,
424 "dependencies": [self.task_id] + dependencies,
425 "requires": "all-completed",
426 "routes": routes,
427 "scopes": scopes,
428 "payload": payload,
429 "extra": extra,
430 "metadata": {
431 "name": "Fenix - {}".format(name),
432 "description": description,
433 "owner": self.owner,
434 "source": self.source,
438 def craft_raptor_signing_task(
439 self, assemble_task_id, variant, is_staging,
441 staging_prefix = '.staging' if is_staging else ''
442 routes = [
443 "index.project.mobile.fenix.v2{}.performance-test.{}.{}.{}.latest".format(
444 staging_prefix, self.date.year, self.date.month, self.date.day
446 "index.project.mobile.fenix.v2{}.performance-test.{}.{}.{}.revision.{}".format(
447 staging_prefix, self.date.year, self.date.month, self.date.day, self.commit
449 "index.project.mobile.fenix.v2{}.performance-test.latest".format(staging_prefix),
452 return self._craft_signing_task(
453 name='sign: {}'.format('forPerformanceTest'),
454 description='Dep-signing variant {}'.format('forPerformanceTest'),
455 signing_type="dep",
456 assemble_task_id=assemble_task_id,
457 apk_paths=variant.upstream_artifacts(),
458 routes=routes,
459 treeherder={
460 'groupSymbol': 'forPerformanceTest',
461 'jobKind': 'other',
462 'machine': {
463 'platform': 'android-all',
465 'symbol': 'As',
466 'tier': 1,
470 def craft_release_signing_task(
471 self, build_task_id, apk_paths, channel, is_staging, publish_to_index=True
473 if publish_to_index:
474 staging_prefix = '.staging' if is_staging else ''
475 routes = [
476 "index.project.mobile.fenix.v2{}.{}.{}.{}.{}.latest".format(
477 staging_prefix, channel, self.date.year, self.date.month, self.date.day
479 "index.project.mobile.fenix.v2{}.{}.{}.{}.{}.revision.{}".format(
480 staging_prefix, channel, self.date.year, self.date.month, self.date.day, self.commit
482 "index.project.mobile.fenix.v2{}.{}.latest".format(staging_prefix, channel),
484 else:
485 routes = []
487 capitalized_channel = upper_case_first_letter(channel)
488 return self._craft_signing_task(
489 name="Signing {} task".format(capitalized_channel),
490 description="Sign {} builds of Fenix".format(capitalized_channel),
491 signing_type="dep" if is_staging else channel,
492 assemble_task_id=build_task_id,
493 apk_paths=apk_paths,
494 routes=routes,
495 treeherder={
496 'jobKind': 'other',
497 'machine': {
498 'platform': 'android-all',
500 'symbol': '{}-s'.format(channel),
501 'tier': 1,
505 def craft_push_task(
506 self, signing_task_id, apk_paths, channel, is_staging=False, override_google_play_track=None
508 payload = {
509 "commit": True,
510 "channel": channel,
511 "certificate_alias": 'fenix' if is_staging else 'fenix-{}'.format(channel),
512 "upstreamArtifacts": [
514 "paths": apk_paths,
515 "taskId": signing_task_id,
516 "taskType": "signing"
521 if override_google_play_track:
522 payload['google_play_track'] = override_google_play_track
524 return self._craft_default_task_definition(
525 worker_type='mobile-pushapk-dep-v1' if is_staging else 'mobile-pushapk-v1',
526 provisioner_id='scriptworker-prov-v1',
527 dependencies=[signing_task_id],
528 routes=[],
529 scopes=[
530 "project:mobile:fenix:releng:googleplay:product:fenix{}".format(
531 ':dep' if is_staging else ''
534 name="Push task",
535 description="Upload signed release builds of Fenix to Google Play",
536 payload=payload,
537 treeherder={
538 'jobKind': 'other',
539 'machine': {
540 'platform': 'android-all',
542 'symbol': '{}-gp'.format(channel),
543 'tier': 1,
547 def craft_raptor_tp6m_cold_task(self, for_suite):
549 def craft_function(signing_task_id, mozharness_task_id, variant_apk, gecko_revision, is_staging, force_run_on_64_bit_device=False):
550 return self._craft_raptor_task(
551 signing_task_id,
552 mozharness_task_id,
553 variant_apk,
554 gecko_revision,
555 is_staging,
556 name_prefix='raptor tp6m-cold-{}'.format(for_suite),
557 description='Raptor tp6m cold on Fenix',
558 test_name='raptor-tp6m-cold-{}'.format(for_suite),
559 job_symbol='tp6m-c-{}'.format(for_suite),
560 force_run_on_64_bit_device=force_run_on_64_bit_device,
562 return craft_function
564 def craft_raptor_youtube_playback_task(self, signing_task_id, mozharness_task_id, variant_apk, gecko_revision,
565 is_staging, force_run_on_64_bit_device=False):
566 return self._craft_raptor_task(
567 signing_task_id,
568 mozharness_task_id,
569 variant_apk,
570 gecko_revision,
571 is_staging,
572 name_prefix='raptor youtube playback',
573 description='Raptor YouTube Playback on Fenix',
574 test_name='raptor-youtube-playback',
575 job_symbol='ytp',
576 group_symbol='Rap',
577 force_run_on_64_bit_device=force_run_on_64_bit_device,
580 def _craft_raptor_task(
581 self,
582 signing_task_id,
583 mozharness_task_id,
584 variant_apk,
585 gecko_revision,
586 is_staging,
587 name_prefix,
588 description,
589 test_name,
590 job_symbol,
591 group_symbol=None,
592 force_run_on_64_bit_device=False,
594 worker_type = 'gecko-t-bitbar-gw-perf-p2' if force_run_on_64_bit_device or variant_apk.abi == 'arm64-v8a' else 'gecko-t-bitbar-gw-perf-g5'
596 if force_run_on_64_bit_device:
597 treeherder_platform = 'android-hw-p2-8-0-arm7-api-16'
598 elif variant_apk.abi == 'armeabi-v7a':
599 treeherder_platform = 'android-hw-g5-7-0-arm7-api-16'
600 elif variant_apk.abi == 'arm64-v8a':
601 treeherder_platform = 'android-hw-p2-8-0-android-aarch64'
602 else:
603 raise ValueError('Unsupported architecture "{}"'.format(variant_apk.abi))
605 task_name = '{}: forPerformanceTest {}'.format(
606 name_prefix, '(on 64-bit-device)' if force_run_on_64_bit_device else ''
609 apk_url = '{}/{}/artifacts/{}'.format(_DEFAULT_TASK_URL, signing_task_id, variant_apk.taskcluster_path)
610 command = [[
611 "/builds/taskcluster/script.py",
612 "bash",
613 "./test-linux.sh",
614 "--cfg=mozharness/configs/raptor/android_hw_config.py",
615 "--test={}".format(test_name),
616 "--app=fenix",
617 "--binary=org.mozilla.fenix.performancetest",
618 "--activity=org.mozilla.fenix.browser.BrowserPerformanceTestActivity",
619 "--download-symbols=ondemand",
621 # Bug 1558456 - Stop tracking youtube-playback-test on motoG5 for >1080p cases
622 if variant_apk.abi == 'armeabi-v7a' and test_name == 'raptor-youtube-playback':
623 params_query = '&'.join(ARM_RAPTOR_URL_PARAMS)
624 add_extra_params_option = "--test-url-params={}".format(params_query)
625 command[0].append(add_extra_params_option)
627 return self._craft_default_task_definition(
628 worker_type=worker_type,
629 provisioner_id='proj-autophone',
630 dependencies=[signing_task_id],
631 name=task_name,
632 description=description,
633 routes=['notify.email.perftest-alerts@mozilla.com.on-failed'] if not is_staging else [],
634 payload={
635 "maxRunTime": 2700,
636 "artifacts": [{
637 'path': '{}'.format(worker_path),
638 'expires': taskcluster.stringDate(taskcluster.fromNow(DEFAULT_EXPIRES_IN)),
639 'type': 'directory',
640 'name': 'public/{}/'.format(public_folder)
641 } for worker_path, public_folder in (
642 ('artifacts/public', 'test'),
643 ('workspace/logs', 'logs'),
644 ('workspace/build/blobber_upload_dir', 'test_info'),
646 "command": command,
647 "env": {
648 "EXTRA_MOZHARNESS_CONFIG": json.dumps({
649 "test_packages_url": "{}/{}/artifacts/public/build/en-US/target.test_packages.json".format(_DEFAULT_TASK_URL, mozharness_task_id),
650 "installer_url": apk_url,
652 "GECKO_HEAD_REPOSITORY": "https://hg.mozilla.org/mozilla-central",
653 "GECKO_HEAD_REV": gecko_revision,
654 "MOZ_AUTOMATION": "1",
655 "MOZ_HIDE_RESULTS_TABLE": "1",
656 "MOZ_NO_REMOTE": "1",
657 "MOZ_NODE_PATH": "/usr/local/bin/node",
658 "MOZHARNESS_CONFIG": "raptor/android_hw_config.py",
659 "MOZHARNESS_SCRIPT": "raptor_script.py",
660 "MOZHARNESS_URL": "{}/{}/artifacts/public/build/en-US/mozharness.zip".format(_DEFAULT_TASK_URL, mozharness_task_id),
661 "MOZILLA_BUILD_URL": apk_url,
662 "NEED_XVFB": "false",
663 "NO_FAIL_ON_TEST_ERRORS": "1",
664 "SCCACHE_DISABLE": "1",
665 "TASKCLUSTER_WORKER_TYPE": worker_type[len('gecko-'):],
666 "TRY_COMMIT_MSG": "",
667 "TRY_SELECTOR": "fuzzy",
668 "XPCOM_DEBUG_BREAK": "warn",
670 "mounts": [{
671 "content": {
672 "url": "https://hg.mozilla.org/mozilla-central/raw-file/{}/taskcluster/scripts/tester/test-linux.sh".format(gecko_revision),
674 "file": "test-linux.sh",
677 treeherder={
678 'jobKind': 'test',
679 'groupSymbol': 'Rap' if group_symbol is None else group_symbol,
680 'machine': {
681 'platform': treeherder_platform,
683 'symbol': job_symbol,
684 'tier': 2,
686 notify={
687 'email': {
688 'link': {
689 'text': "Treeherder Job",
690 'href': "https://treeherder.mozilla.org/#/jobs?repo=fenix&revision={}".format(self.commit),
692 'subject': '[fenix] Raptor job "{}" failed'.format(task_name),
693 'content': "This calls for an action of the Performance team. Use the link to view it on Treeherder.",
699 def schedule_task(queue, taskId, task):
700 print("TASK", taskId)
701 print(json.dumps(task, indent=4, separators=(',', ': ')))
703 result = queue.createTask(taskId, task)
704 print("RESULT", taskId)
705 print(json.dumps(result))
708 def schedule_task_graph(ordered_groups_of_tasks):
709 queue = taskcluster.Queue({'baseUrl': 'http://taskcluster/queue/v1'})
710 full_task_graph = {}
712 # TODO: Switch to async python to speed up submission
713 for group_of_tasks in ordered_groups_of_tasks:
714 for task_id, task_definition in group_of_tasks.items():
715 schedule_task(queue, task_id, task_definition)
717 full_task_graph[task_id] = {
718 # Some values of the task definition are automatically filled. Querying the task
719 # allows to have the full definition. This is needed to make Chain of Trust happy
720 'task': queue.task(task_id),
723 return full_task_graph
726 def fetch_mozharness_task_id():
727 # We now want to use the latest available raptor
728 raptor_index = 'gecko.v2.mozilla-central.nightly.latest.mobile.android-x86_64-opt'
729 return taskcluster.Index().findTask(raptor_index)['taskId']