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
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):
32 short_head_branch
, commit
, owner
, source
, scheduler_id
, date_string
,
33 tasks_priority
='lowest',
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
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
):
51 secret_index
= 'garbage/staging/project/mobile/fenix'
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
)
69 './gradlew --no-daemon -PversionName="{}" clean test assemble{}'.format(
70 version_name
, capitalized_build_type
),
73 command
= ' && '.join(
75 for commands
in (pre_gradle_commands
, gradle_commands
)
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
),
89 "secrets:get:{}".format(secret_index
)
91 artifacts
=variant
.artifacts(),
96 'platform': 'android-all',
98 'symbol': '{}-A'.format(variant
.build_type
),
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
),
115 artifacts
=variant
.artifacts(),
117 'groupSymbol': variant
.build_type
,
120 'platform': 'android-all',
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(),
134 'groupSymbol': variant
.build_type
,
137 'platform': 'android-all',
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
,
154 'groupSymbol': variant
.build_type
,
157 'platform': 'android-all',
163 'secrets:get:project/mobile/fenix/public-tokens'
167 def craft_ui_tests_task(self
):
171 "path": "/build/fenix/results",
172 "expires": taskcluster
.stringDate(taskcluster
.fromNow(DEFAULT_EXPIRES_IN
))
177 "GOOGLE_PROJECT": "moz-fenix",
178 "GOOGLE_APPLICATION_CREDENTIALS": ".firebase_token.json"
182 './gradlew --no-daemon clean assemble assembleAndroidTest',
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
)
197 return self
._craft
_build
_ish
_task
(
198 name
='Fenix - UI test',
199 description
='Execute Gradle tasks for UI tests',
202 'secrets:get:project/mobile/fenix/firebase'
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',
220 'platform': 'android-all',
222 'symbol': 'compare-locale',
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
(
232 description
='Running detekt code quality checks',
233 gradle_task
='detekt',
245 def craft_ktlint_task(self
):
246 return self
._craft
_clean
_gradle
_task
(
248 description
='Running ktlint code quality checks',
249 gradle_task
='ktlint',
260 def craft_lint_task(self
):
261 return self
._craft
_clean
_gradle
_task
(
263 description
='Running lint for aarch64 release variant',
264 gradle_task
='lintDebug',
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
(
280 description
=description
,
281 command
='./gradlew --no-daemon clean {}'.format(gradle_task
),
284 treeherder
=treeherder
,
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',
293 'pip install "compare-locales>=5.0.2,<6.0" && '
294 'compare-locales --validate l10n.toml .'
301 'symbol': 'compare-locale',
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([
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
)
327 features
['chainOfTrust'] = True
328 if any(scope
.startswith('secrets:') for scope
in scopes
):
329 features
['taskclusterProxy'] = True
331 "features": features
,
334 "image": "mozillamobile/fenix:1.4",
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',
348 description
=description
,
350 dependencies
=dependencies
,
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"
359 'upstreamArtifacts': [{
361 'formats': [signing_format
],
362 'taskId': assemble_task_id
,
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
],
373 "project:mobile:fenix:releng:signing:format:{}".format(signing_format
),
374 "project:mobile:fenix:releng:signing:cert:{}-signing".format(signing_type
),
377 description
=description
,
379 treeherder
=treeherder
,
382 def _craft_default_task_definition(
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
))
408 "treeherder": treeherder
,
411 extra
['notify'] = notify
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
),
423 "priority": self
.tasks_priority
,
424 "dependencies": [self
.task_id
] + dependencies
,
425 "requires": "all-completed",
431 "name": "Fenix - {}".format(name
),
432 "description": description
,
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 ''
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'),
456 assemble_task_id
=assemble_task_id
,
457 apk_paths
=variant
.upstream_artifacts(),
460 'groupSymbol': 'forPerformanceTest',
463 'platform': 'android-all',
470 def craft_release_signing_task(
471 self
, build_task_id
, apk_paths
, channel
, is_staging
, publish_to_index
=True
474 staging_prefix
= '.staging' if is_staging
else ''
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
),
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
,
498 'platform': 'android-all',
500 'symbol': '{}-s'.format(channel
),
506 self
, signing_task_id
, apk_paths
, channel
, is_staging
=False, override_google_play_track
=None
511 "certificate_alias": 'fenix' if is_staging
else 'fenix-{}'.format(channel
),
512 "upstreamArtifacts": [
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
],
530 "project:mobile:fenix:releng:googleplay:product:fenix{}".format(
531 ':dep' if is_staging
else ''
535 description
="Upload signed release builds of Fenix to Google Play",
540 'platform': 'android-all',
542 'symbol': '{}-gp'.format(channel
),
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
(
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
(
572 name_prefix
='raptor youtube playback',
573 description
='Raptor YouTube Playback on Fenix',
574 test_name
='raptor-youtube-playback',
577 force_run_on_64_bit_device
=force_run_on_64_bit_device
,
580 def _craft_raptor_task(
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'
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
)
611 "/builds/taskcluster/script.py",
614 "--cfg=mozharness/configs/raptor/android_hw_config.py",
615 "--test={}".format(test_name
),
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
],
632 description
=description
,
633 routes
=['notify.email.perftest-alerts@mozilla.com.on-failed'] if not is_staging
else [],
637 'path': '{}'.format(worker_path
),
638 'expires': taskcluster
.stringDate(taskcluster
.fromNow(DEFAULT_EXPIRES_IN
)),
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'),
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",
672 "url": "https://hg.mozilla.org/mozilla-central/raw-file/{}/taskcluster/scripts/tester/test-linux.sh".format(gecko_revision
),
674 "file": "test-linux.sh",
679 'groupSymbol': 'Rap' if group_symbol
is None else group_symbol
,
681 'platform': treeherder_platform
,
683 'symbol': job_symbol
,
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'})
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']