Bug 1788606 - Decision task: let docker-worker cache the gradle cache
[gecko.git] / mobile / android / .taskcluster.yml
blob58239ba2bc068d6a7cc0b3a9a1df6a9130b3cdfb
1 ---
2 version: 1
3 reporting: checks-v1
4 policy:
5     pullRequests: public_restricted
6 tasks:
7     - $let:
8           trustDomain: mobile
9           canonicalRepo: https://github.com/mozilla-mobile/firefox-android
10           isPullRequest:
11               # We now support both github-pull-request and github-pull-request-untrusted
12               $eval: 'tasks_for[:19] == "github-pull-request"'
14           ownTaskId:
15               $if: '"github" in tasks_for'
16               then: {$eval: as_slugid("decision_task")}
17               else:
18                   $if: 'tasks_for == "cron"'
19                   then: '${ownTaskId}'
20       in:
21           $let:
22               # Github events have this stuff in different places...
23               ownerEmail:
24                   $if: 'tasks_for in ["cron", "action"]'
25                   then: '${tasks_for}@noreply.mozilla.org'
26                   else:
27                       # GitHub adds "[bot]" to bot usernames and that doesn't validate as email.
28                       $if: 'event.sender.login == "bors[bot]"'
29                       then: 'skaspari+mozlando@mozilla.com'   # It must match what's in bors.toml
30                       else:
31                           $if: 'tasks_for == "github-push"'
32                           then:
33                               $if: 'event.pusher.email'
34                               then: '${event.pusher.email}'
35                               else: '${event.pusher.name}@users.noreply.github.com'
36                           else:
37                               $if: 'isPullRequest'
38                               then: '${event.pull_request.user.login}@users.noreply.github.com'
40               repoFullName:
41                   $if: 'tasks_for in "github-push"'
42                   then: '${event.repository.full_name}'
43                   else:
44                       $if: 'isPullRequest'
45                       then: '${event.pull_request.base.repo.full_name}'
46                       else:
47                           $if: 'tasks_for in ["cron", "action"]'
48                           # Trim https://github.com/
49                           then: '${repository.url[19:]}'
51               baseRepoUrl:
52                   $if: 'tasks_for == "github-push"'
53                   then: '${event.repository.html_url}'
54                   else:
55                       $if: 'isPullRequest'
56                       then: '${event.pull_request.base.repo.html_url}'
57                       else:
58                           $if: 'tasks_for in ["cron", "action"]'
59                           then: '${repository.url}'
60               repoUrl:
61                   $if: 'tasks_for == "github-push"'
62                   then: '${event.repository.html_url}'
63                   else:
64                       $if: 'isPullRequest'
65                       then: '${event.pull_request.head.repo.html_url}'
66                       else:
67                           $if: 'tasks_for in ["cron", "action"]'
68                           then: '${repository.url}'
69               project:
70                   $if: 'tasks_for == "github-push"'
71                   then: '${event.repository.name}'
72                   else:
73                       $if: 'isPullRequest'
74                       then: '${event.pull_request.head.repo.name}'
75                       else:
76                           $if: 'tasks_for in ["cron", "action"]'
77                           then: '${repository.project}'
78               base_ref:
79                   $if: 'isPullRequest'
80                   then: ${event.pull_request.base.ref}
81                   else:
82                       # event.base_ref is barely documented[1]. Testing showed it's only
83                       # defined when creating a new branch. It's null when pushing to an
84                       # existing branch
85                       #
86                       # [1] https://docs.github.com/en/developers/webhooks-and-events/webhooks/webhook-events-and-payloads#push
87                       $if: 'tasks_for == "github-push" && event.base_ref'
88                       then: ${event.base_ref}
89                       else:
90                           $if: 'tasks_for == "github-push"'
91                           then: ${event.ref}
92                           else:
93                               $if: 'tasks_for in ["cron", "action"]'
94                               then:
95                                 $if: 'push.branch[:11] == "refs/heads/"'
96                                 then: {$eval: 'push.branch[11:]'}
97                                 else: ${push.branch}
98               head_ref:
99                   $if: 'isPullRequest'
100                   then: ${event.pull_request.head.ref}
101                   else:
102                       $if: 'tasks_for == "github-push"'
103                       then: ${event.ref}
104                       else:
105                           $if: 'tasks_for in ["cron", "action"]'
106                           then: '${push.branch}'
107               base_sha:
108                   $if: 'tasks_for == "github-push"'
109                   then: '${event.before}'
110                   else:
111                       $if: 'isPullRequest'
112                       then: '${event.pull_request.base.sha}'
113                       else:
114                           $if: 'tasks_for in ["cron", "action"]'
115                           then: '${push.revision}'
116               head_sha:
117                   $if: 'tasks_for == "github-push"'
118                   then: '${event.after}'
119                   else:
120                       $if: 'isPullRequest'
121                       then: '${event.pull_request.head.sha}'
122                       else:
123                           $if: 'tasks_for in ["cron", "action"]'
124                           then: '${push.revision}'
125               pullRequestAction:
126                   $if: 'isPullRequest'
127                   then: ${event.action}
128                   else: 'UNDEFINED'
129           in:
130               $if: >
131                   tasks_for in ["action", "cron"]
132                   || (isPullRequest && pullRequestAction in ["opened", "reopened", "synchronize"])
133                   || (tasks_for == "github-push" && head_ref[:10] != "refs/tags/" && head_ref != "staging.tmp" && head_ref != "trying.tmp") && (head_ref[:8] != "mergify/")
134               then:
135                   $let:
136                       level:
137                           $if: >
138                               tasks_for in ["github-push", "action", "cron"] && repoUrl == canonicalRepo
139                           then: '3'
140                           else: '1'
142                       short_base_ref:
143                           $if: 'base_ref[:11] == "refs/heads/"'
144                           then: {$eval: 'base_ref[11:]'}
145                           else: ${base_ref}
147                       short_head_ref:
148                           $if: 'head_ref[:11] == "refs/heads/"'
149                           then: {$eval: 'head_ref[11:]'}
150                           else: ${head_ref}
151                   in:
152                       $mergeDeep:
153                           - $if: 'tasks_for != "action"'
154                             then:
155                                 taskId: '${ownTaskId}'
156                           - taskGroupId:
157                                 $if: 'tasks_for == "action"'
158                                 then:
159                                     '${action.taskGroupId}'
160                                 else:
161                                     '${ownTaskId}'  # same as taskId; this is how automation identifies a decision task
162                             schedulerId: '${trustDomain}-level-${level}'
163                             created: {$fromNow: ''}
164                             deadline: {$fromNow: '1 day'}
165                             expires: {$fromNow: '1 year 1 second'}  # 1 second so artifacts expire first, despite rounding errors
166                             metadata:
167                                 $merge:
168                                     - owner: "${ownerEmail}"
169                                       source: 'https://github.com/${repoFullName}/raw/${head_sha}/.taskcluster.yml'
170                                     - $if: 'isPullRequest || tasks_for == "github-push"'
171                                       then:
172                                           name: "Decision Task"
173                                           description: 'The task that creates all of the other tasks in the task graph'
174                                       else:
175                                           $if: 'tasks_for == "action"'
176                                           then:
177                                               name: "Action: ${action.title}"
178                                               description: |
179                                                       ${action.description}
181                                                       Action triggered by clientID `${clientId}`
182                                           else:
183                                               name: "Decision Task for cron job ${cron.job_name}"
184                                               description: 'Created by a [cron task](https://firefox-ci-tc.services.mozilla.com/tasks/${cron.task_id})'
185                             provisionerId: "mobile-${level}"
186                             workerType: "decision-gcp"
187                             tags:
188                                 $if: 'isPullRequest || tasks_for == "github-push"'
189                                 then:
190                                     kind: decision-task
191                                 else:
192                                     $if: 'tasks_for == "action"'
193                                     then:
194                                         kind: 'action-callback'
195                                     else:
196                                         $if: 'tasks_for == "cron"'
197                                         then:
198                                             kind: cron-task
199                             routes:
200                                 $flattenDeep:
201                                     - checks
202                                     - $if: 'level == "3" || repoUrl == "https://github.com/mozilla-releng/staging-firefox-android"'
203                                       then:
204                                           - tc-treeherder.v2.${project}.${head_sha}
205                                           - $if: 'tasks_for == "github-push"'
206                                             then:
207                                                 - index.mobile.v2.${project}.branch.${short_head_ref}.latest.taskgraph.decision
208                                                 - index.mobile.v2.${project}.branch.${short_head_ref}.revision.${head_sha}.taskgraph.decision
209                                                 - index.mobile.v2.${project}.revision.${head_sha}.taskgraph.decision
210                                           - $if: 'tasks_for == "cron"'
211                                             then:
212                                                 # cron context provides ${head_ref} as a short one
213                                                 - index.mobile.v2.${project}.branch.${head_ref}.latest.taskgraph.decision-${cron.job_name}
214                                                 - index.mobile.v2.${project}.branch.${head_ref}.revision.${head_sha}.taskgraph.decision-${cron.job_name}
215                                                 - index.mobile.v2.${project}.branch.${head_ref}.revision.${head_sha}.taskgraph.cron.${ownTaskId}
216                             scopes:
217                                 $if: 'tasks_for == "github-push"'
218                                 then:
219                                     - 'assume:repo:github.com/${repoFullName}:branch:${short_head_ref}'
220                                 else:
221                                     $if: 'isPullRequest'
222                                     then:
223                                         - 'assume:repo:github.com/${repoFullName}:${tasks_for[7:]}'
224                                     else:
225                                         $if: 'tasks_for == "action"'
226                                         then:
227                                             # when all actions are hooks, we can calculate this directly rather than using a variable
228                                             - '${action.repo_scope}'
229                                         else:
230                                             - 'assume:repo:github.com/${repoFullName}:cron:${cron.job_name}'
232                             requires: all-completed
233                             priority: lowest
234                             retries: 5
236                             payload:
237                                 cache:
238                                     "${trustDomain}-level-${level}-gradle-decision-cache": /builds/worker/.gradle
239                                 env:
240                                     # run-task uses these to check out the source; the inputs
241                                     # to `mach taskgraph decision` are all on the command line.
242                                     $merge:
243                                         - MOBILE_BASE_REPOSITORY: '${baseRepoUrl}'
244                                           MOBILE_BASE_REF: '${short_base_ref}'
245                                           MOBILE_BASE_REV: '${base_sha}'
246                                           MOBILE_HEAD_REPOSITORY: '${repoUrl}'
247                                           MOBILE_HEAD_REF: '${short_head_ref}'
248                                           MOBILE_HEAD_REV: '${head_sha}'
249                                           MOBILE_PIP_REQUIREMENTS: taskcluster/requirements.txt
250                                           MOBILE_REPOSITORY_TYPE: git
251                                           MOZ_AUTOMATION: "1"
252                                           REPOSITORIES: {$json: {mobile: "firefox-android"}}
253                                           TASKCLUSTER_CACHES: /builds/worker/.gradle
254                                         - $if: 'isPullRequest'
255                                           then:
256                                               MOBILE_PULL_REQUEST_NUMBER: '${event.pull_request.number}'
257                                         - $if: 'tasks_for == "action"'
258                                           then:
259                                               ACTION_TASK_GROUP_ID: '${action.taskGroupId}'  # taskGroupId of the target task
260                                               ACTION_TASK_ID: {$json: {$eval: 'taskId'}}  # taskId of the target task (JSON-encoded)
261                                               ACTION_INPUT: {$json: {$eval: 'input'}}
262                                               ACTION_CALLBACK: '${action.cb_name}'
263                                 features:
264                                     taskclusterProxy: true
265                                     chainOfTrust: true
266                                 # Note: This task is built server side without the context or tooling that
267                                 # exist in tree so we must hard code the hash
268                                 image:
269                                     mozillareleases/taskgraph:decision-mobile-c0fca789e58f5458999ac9780a45897340f96f2a273c3c5ea1d2be438ab5223b@sha256:e9f387c9049db80281eaed73c7173b653be195423cdd58300f71d9796d8f1ac7
271                                 maxRunTime: 1800
273                                 command:
274                                     - /usr/local/bin/run-task
275                                     - '--mobile-checkout=/builds/worker/checkouts/vcs'
276                                     - '--task-cwd=/builds/worker/checkouts/vcs'
277                                     - '--'
278                                     - bash
279                                     - -cx
280                                     - $let:
281                                           extraArgs: {$if: 'tasks_for == "cron"', then: '${cron.quoted_args}', else: ''}
282                                       in:
283                                           $if: 'tasks_for == "action"'
284                                           then: >
285                                               cd /builds/worker/checkouts/vcs &&
286                                               ln -s /builds/worker/artifacts artifacts &&
287                                               ~/.local/bin/taskgraph action-callback
288                                           else: >
289                                               cd /builds/worker/checkouts/vcs &&
290                                               ln -s /builds/worker/artifacts artifacts &&
291                                               ~/.local/bin/taskgraph decision
292                                               --pushlog-id='0'
293                                               --pushdate='0'
294                                               --project='${project}'
295                                               --message=""
296                                               --owner='${ownerEmail}'
297                                               --level='${level}'
298                                               --base-repository="$MOBILE_BASE_REPOSITORY"
299                                               --base-ref="$MOBILE_BASE_REF"
300                                               --base-rev="$MOBILE_BASE_REV"
301                                               --head-repository="$MOBILE_HEAD_REPOSITORY"
302                                               --head-ref="$MOBILE_HEAD_REF"
303                                               --head-rev="$MOBILE_HEAD_REV"
304                                               --repository-type="$MOBILE_REPOSITORY_TYPE"
305                                               --tasks-for='${tasks_for}'
306                                               ${extraArgs}
308                                 artifacts:
309                                     'public':
310                                         type: 'directory'
311                                         path: '/builds/worker/artifacts'
312                                         expires: {$fromNow: '1 year'}
313                                     'public/docker-contexts':
314                                         type: 'directory'
315                                         path: '/builds/worker/checkouts/vcs/docker-contexts'
316                                         # This needs to be at least the deadline of the
317                                         # decision task + the docker-image task deadlines.
318                                         # It is set to a week to allow for some time for
319                                         # debugging, but they are not useful long-term.
320                                         expires: {$fromNow: '7 day'}
322                             extra:
323                                 $merge:
324                                     - treeherder:
325                                           $merge:
326                                               - machine:
327                                                     platform: gecko-decision
328                                               - $if: 'isPullRequest || tasks_for == "github-push"'
329                                                 then:
330                                                     symbol: D
331                                                 else:
332                                                     $if: 'tasks_for == "action"'
333                                                     then:
334                                                         groupName: 'action-callback'
335                                                         groupSymbol: AC
336                                                         symbol: "${action.symbol}"
337                                                     else:
338                                                         groupSymbol: cron
339                                                         symbol: "${cron.job_symbol}"
340                                     - $if: 'tasks_for == "action"'
341                                       then:
342                                           parent: '${action.taskGroupId}'
343                                           action:
344                                               name: '${action.name}'
345                                               context:
346                                                   taskGroupId: '${action.taskGroupId}'
347                                                   taskId: {$eval: 'taskId'}
348                                                   input: {$eval: 'input'}
349                                                   clientId: {$eval: 'clientId'}
350                                     - $if: 'tasks_for == "cron"'
351                                       then:
352                                           cron: {$json: {$eval: 'cron'}}
353                                     - tasks_for: '${tasks_for}'