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/.
6 Decision task for pull requests and pushes
19 TASK_ID
= os
.environ
.get('TASK_ID')
20 REPO_URL
= os
.environ
.get('MOBILE_HEAD_REPOSITORY')
21 BRANCH
= os
.environ
.get('MOBILE_HEAD_BRANCH')
22 COMMIT
= os
.environ
.get('MOBILE_HEAD_REV')
23 PR_TITLE
= os
.environ
.get('GITHUB_PULL_TITLE', '')
25 # If we see this text inside a pull request title then we will not execute any tasks for this PR.
26 SKIP_TASKS_TRIGGER
= '[ci skip]'
29 def fetch_module_names():
30 process
= subprocess
.Popen(["./gradlew", "--no-daemon", "printModules"], stdout
=subprocess
.PIPE
)
31 (output
, err
) = process
.communicate()
32 exit_code
= process
.wait()
34 if exit_code
is not 0:
35 print "Gradle command returned error:", exit_code
37 return re
.findall('module: (.*)', output
, re
.M
)
40 def create_task(name
, description
, command
):
41 return create_raw_task(name
, description
, "./gradlew --no-daemon clean %s" % command
)
43 def create_raw_task(name
, description
, full_command
):
44 created
= datetime
.datetime
.now()
45 expires
= taskcluster
.fromNow('1 year')
46 deadline
= taskcluster
.fromNow('1 day')
49 "workerType": 'github-worker',
50 "taskGroupId": TASK_ID
,
51 "expires": taskcluster
.stringDate(expires
),
53 "created": taskcluster
.stringDate(created
),
56 "schedulerId": "taskcluster-github",
57 "deadline": taskcluster
.stringDate(deadline
),
58 "dependencies": [ TASK_ID
],
61 "requires": "all-completed",
65 "image": "mozillamobile/android-components:1.5",
70 "export TERM=dumb && git fetch %s %s && git config advice.detachedHead false && git checkout %s && %s" % (REPO_URL
, BRANCH
, COMMIT
, full_command
)
74 "provisionerId": "aws-provisioner-v1",
77 "description": description
,
78 "owner": "skaspari@mozilla.com",
79 "source": "https://github.com/mozilla-mobile/android-components"
84 def create_module_task(module
):
86 name
='Android Components - Module ' + module
,
87 description
='Building and testing module ' + module
,
88 command
=" ".join(map(lambda x
: module
+ ":" + x
, ['assemble', 'test', 'lint'])))
91 def create_detekt_task():
93 name
='Android Components - detekt',
94 description
='Running detekt over all modules',
95 command
='detektCheck')
98 def create_ktlint_task():
100 name
='Android Components - ktlint',
101 description
='Running ktlint over all modules',
105 def create_compare_locales_task():
106 return create_raw_task(
107 name
='Android Components - compare-locales',
108 description
='Validate strings.xml with compare-locales',
109 full_command
='pip install "compare-locales>=4.0.1,<5.0" && compare-locales --validate l10n.toml .')
112 if __name__
== "__main__":
113 if SKIP_TASKS_TRIGGER
in PR_TITLE
:
114 print "Pull request title contains", SKIP_TASKS_TRIGGER
118 queue
= taskcluster
.Queue({ 'baseUrl': 'http://taskcluster/queue/v1' })
120 modules
= fetch_module_names()
122 if len(modules
) == 0:
123 print "Could not get module names from gradle"
126 for module
in modules
:
127 task
= create_module_task(module
)
128 task_id
= taskcluster
.slugId()
129 lib
.tasks
.schedule_task(queue
, task_id
, task
)
131 lib
.tasks
.schedule_task(queue
, taskcluster
.slugId(), create_detekt_task())
132 lib
.tasks
.schedule_task(queue
, taskcluster
.slugId(), create_ktlint_task())
133 lib
.tasks
.schedule_task(queue
, taskcluster
.slugId(), create_compare_locales_task())