diff --git a/src/mozilla_taskgraph/util/attributes.py b/src/mozilla_taskgraph/util/attributes.py index 59ecb9b..1d6df80 100644 --- a/src/mozilla_taskgraph/util/attributes.py +++ b/src/mozilla_taskgraph/util/attributes.py @@ -4,6 +4,38 @@ import re +_COPYABLE_ATTRIBUTES = ( + "accepted-mar-channel-ids", + "artifact_map", + "artifact_prefix", + "build_platform", + "build_type", + "l10n_chunk", + "locale", + "mar-channel-id", + "maven_packages", + "nightly", + "shippable", + "shipping_phase", + "shipping_product", + "signed", + "stub-installer", + "update-channel", +) + + +def copy_attributes_from_dependent_job(dep_job, denylist=()): + """Copy the curated ``_COPYABLE_ATTRIBUTES`` from a dependent job. + + Only attributes present on ``dep_job`` and not in ``denylist`` are copied, + so entries that don't apply to a given job are simply skipped. + """ + return { + attr: dep_job.attributes[attr] + for attr in _COPYABLE_ATTRIBUTES + if attr in dep_job.attributes and attr not in denylist + } + def release_level(release_branches: dict, params: dict): """Whether this is a production release or not. diff --git a/test/util/test_attributes.py b/test/util/test_attributes.py index 71d78e3..d495ec2 100644 --- a/test/util/test_attributes.py +++ b/test/util/test_attributes.py @@ -2,9 +2,14 @@ # License, v. 2.0. If a copy of the MPL was not distributed with this # file, You can obtain one at http://mozilla.org/MPL/2.0/. +from types import SimpleNamespace + import pytest -from mozilla_taskgraph.util.attributes import release_level +from mozilla_taskgraph.util.attributes import ( + copy_attributes_from_dependent_job, + release_level, +) FIREFOX_BRANCHES = ["main", "beta", "release", "esr140"] RELEASE_BRANCHES = { @@ -54,3 +59,23 @@ ) def test_release_level(release_branches, params, expected): assert release_level(release_branches, params) == expected + + +def test_copy_attributes_from_dependent_job(): + dep_job = SimpleNamespace( + attributes={ + "build_platform": "linux64", + "shippable": True, + "locale": "de", + "not_copyable": "x", # not in _COPYABLE_ATTRIBUTES -> skipped + } + ) + assert copy_attributes_from_dependent_job(dep_job) == { + "build_platform": "linux64", + "shippable": True, + "locale": "de", + } + assert copy_attributes_from_dependent_job(dep_job, denylist=("locale",)) == { + "build_platform": "linux64", + "shippable": True, + }