[components] Bring Taskcluster graphs back on push events
[gecko.git] / mobile / android / android-components / automation / taskcluster / decision_task.py
blobc5bfaeeb2f6d0ec7bfa2228e91e1e8fa2d1fcd9e
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 """
6 Decision task for pull requests and pushes
7 """
9 import datetime
10 import os
11 import taskcluster
12 import re
13 import subprocess
14 import sys
16 import lib.tasks
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')
48 return {
49 "workerType": 'github-worker',
50 "taskGroupId": TASK_ID,
51 "expires": taskcluster.stringDate(expires),
52 "retries": 5,
53 "created": taskcluster.stringDate(created),
54 "tags": {},
55 "priority": "lowest",
56 "schedulerId": "taskcluster-github",
57 "deadline": taskcluster.stringDate(deadline),
58 "dependencies": [ TASK_ID ],
59 "routes": [],
60 "scopes": [],
61 "requires": "all-completed",
62 "payload": {
63 "features": {},
64 "maxRunTime": 7200,
65 "image": "mozillamobile/android-components:1.5",
66 "command": [
67 "/bin/bash",
68 "--login",
69 "-cx",
70 "export TERM=dumb && git fetch %s %s && git config advice.detachedHead false && git checkout %s && %s" % (REPO_URL, BRANCH, COMMIT, full_command)
72 "artifacts": {}
74 "provisionerId": "aws-provisioner-v1",
75 "metadata": {
76 "name": name,
77 "description": description,
78 "owner": "skaspari@mozilla.com",
79 "source": "https://github.com/mozilla-mobile/android-components"
84 def create_module_task(module):
85 return create_task(
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():
92 return create_task(
93 name='Android Components - detekt',
94 description='Running detekt over all modules',
95 command='detektCheck')
98 def create_ktlint_task():
99 return create_task(
100 name='Android Components - ktlint',
101 description='Running ktlint over all modules',
102 command='ktlint')
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
115 print "Exit"
116 exit(0)
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"
124 sys.exit(2)
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())