@@ -210,14 +210,17 @@ def rewrite_mirrored_dependencies(
210210 prefix : str ,
211211 dependencies : dict [str , str ],
212212 tasks : dict [str , Any ],
213- patterns : list [re .Pattern ],
213+ include_deps : list [str ],
214+ artifact_tasks ,
214215):
215216 """Re-write dependencies and fetches of tasks that are being re-run in the
216217 staging instance that are also being re-run in the staging instance. Without
217218 this, the downstream tasks will attempt to refer to firefoxci task ids that
218219 do not exist in the staging cluster, and task submission will fail.
219220 """
221+ patterns = [re .compile (p ) for p in include_deps ]
220222 modified_deps = set ()
223+ mirrored_deps = set ()
221224 # First, update any dependencies that are also being run as part of this integration test
222225 for upstream_task_id in dependencies :
223226 if upstream_task_id in tasks :
@@ -227,6 +230,11 @@ def rewrite_mirrored_dependencies(
227230 upstream_task_label = f"{ prefix } -{ name } "
228231 taskdesc ["dependencies" ][upstream_task_label ] = upstream_task_label
229232
233+ artifact_task_label = f"firefoxci-artifact-{ prefix } -{ upstream_task_id } "
234+ if artifact_task_label in artifact_tasks and artifact_task_label not in taskdesc ["dependencies" ].values ():
235+ mirrored_deps .add (upstream_task_id )
236+ taskdesc ["dependencies" ][artifact_task_label ] = artifact_task_label
237+
230238 # Second, update any fetches that point to dependencies that are also being run as part
231239 # of this integration test
232240 updated_fetches = []
@@ -241,6 +249,9 @@ def rewrite_mirrored_dependencies(
241249 fetch_task_label = tasks [fetch_task_id ]["metadata" ]["name" ]
242250 fetch ["task" ] = f"<{ prefix } -{ fetch_task_label } >"
243251
252+ if fetch_task_id in mirrored_deps :
253+ fetch ["task" ] = f"<firefoxci-artifact-{ prefix } -{ fetch_task_id } >"
254+
244255 updated_fetches .append (fetch )
245256
246257 taskdesc ["task" ]["payload" ]["env" ]["MOZ_FETCHES" ] = {
@@ -253,6 +264,8 @@ def make_integration_test_description(
253264 name_prefix : str ,
254265 tasks : dict [str , Any ],
255266 include_deps : list [str ],
267+ should_patch_root_url : bool ,
268+ artifact_tasks ,
256269):
257270 """Schedule a task on the staging Taskcluster instance.
258271
@@ -274,30 +287,6 @@ def make_integration_test_description(
274287 if "treeherder" in task_def ["extra" ]:
275288 del task_def ["extra" ]["treeherder" ]
276289
277- include_patterns = [re .compile (p ) for p in include_deps ]
278- # Tasks may only have 1 root url set, which is primarily used to decide
279- # where to find `MOZ_FETCHES`. When we're including dependencies, we peek
280- # at upstream tasks to figure out what this should be set to. If any
281- # upstream task is present that doesn't match an include pattern, its
282- # dependencies must be pulled from the firefox ci cluster, and we must
283- # patch the root. If a task matches an include pattern, its dependencies
284- # will be in the staging cluster, and we must not patch the root.
285- # If we have a mix of tasks, we cannot proceed.
286- matches = set ()
287- for upstream_task_id in orig_dependencies :
288- if upstream_task_id in tasks :
289- name = tasks [upstream_task_id ]["metadata" ]["name" ]
290- matches .add (any ([pat .match (name ) for pat in include_patterns ]))
291-
292- should_patch_root_url = True
293- if len (matches ) == 2 :
294- raise Exception (
295- f"task '{ task_def ['metadata' ]['name' ]} ' has both mirrored and unmirrored dependencies; it will not work correctly"
296- )
297- elif len (matches ) == 1 :
298- if matches .pop () is True :
299- should_patch_root_url = False
300-
301290 if should_patch_root_url :
302291 patch_root_url (task_def )
303292 rewrite_mounts (task_def )
@@ -328,7 +317,7 @@ def make_integration_test_description(
328317 rewrite_docker_image (taskdesc )
329318 rewrite_private_fetches (taskdesc )
330319 rewrite_mirrored_dependencies (
331- taskdesc , name_prefix , orig_dependencies , tasks , include_patterns
320+ taskdesc , name_prefix , orig_dependencies , tasks , include_deps , artifact_tasks ,
332321 )
333322 return taskdesc
334323
@@ -341,10 +330,12 @@ def schedule_tasks_at_index(config, tasks):
341330 if os .environ ["TASKCLUSTER_ROOT_URL" ] != STAGING_ROOT_URL :
342331 return
343332
333+ artifact_tasks = {k : v for k , v in config .kind_dependencies_tasks .items () if k .startswith ("firefoxci-artifact" )}
344334 for task in tasks :
345335 include_attrs = task .pop ("include-attrs" , {})
346336 exclude_attrs = task .pop ("exclude-attrs" , {})
347337 include_deps = task .pop ("include-deps" , [])
338+ patch_root_url = task .pop ("patch-root-url" , True )
348339 for decision_index_path in task .pop ("decision-index-paths" ):
349340 found_tasks = find_tasks (
350341 decision_index_path ,
@@ -356,5 +347,5 @@ def schedule_tasks_at_index(config, tasks):
356347 # task_def is copied to avoid modifying the version in `tasks`, which
357348 # may be used to modify parts of the new task description
358349 yield make_integration_test_description (
359- copy .deepcopy (task_def ), task ["name" ], found_tasks , include_deps
350+ copy .deepcopy (task_def ), task ["name" ], found_tasks , include_deps , patch_root_url , artifact_tasks
360351 )
0 commit comments