Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
280 changes: 280 additions & 0 deletions src/mozilla_taskgraph/worker_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -183,3 +183,283 @@ def build_signing_payload(config, task, task_def):
)
)
task["attributes"]["release_artifacts"] = sorted(list(artifacts))


l10n_bump_info_schema = [
{
Required("name"): str,
Required("path"): str,
Required("l10n-repo-url"): str,
Required("l10n-repo-target-branch"): str,
Optional("ignore-config"): object,
Required("platform-configs"): [
{
Required("platforms"): [str],
Required("path"): str,
Optional("format"): str,
}
],
}
]


def process_l10n_bump_info(info):
l10n_bump_info = []
l10n_repo_urls = set()
for lbi in info:
l10n_repo_urls.add(lbi["l10n-repo-url"])
l10n_bump_info.append(dash_to_underscore(lbi))

if len(l10n_repo_urls) > 1:
raise Exception(
"Must use the same l10n-repo-url for all files in the same task!"
)

return l10n_bump_info


@payload_builder(
"scriptworker-lando",
schema={
Required("lando-repo"): str,
Required("actions"): [
Any(
{
Required("android-l10n-sync"): {
Required("from-branch"): str,
Required("toml-info"): [
{
Required("toml-path"): str,
}
],
},
},
{
Required("android-l10n-import"): {
Required("from-repo-url"): str,
Required("toml-info"): [
{
Required("toml-path"): str,
Required("dest-path"): str,
}
],
},
},
{
Required("l10n-bump"): l10n_bump_info_schema,
},
{
Required("tag"): {
Required("types"): [Any("buildN", "release")],
Required("hg-repo-url"): str,
}
},
{
Required("version-bump"): {
Required("bump-files"): [str],
},
},
# the remaining action types all end up using the "merge_day"
# landoscript action. however, these are quite varied tasks,
# and separating them out allows us to have stronger schemas.
{
Required("esr-bump"): {
Required("to-branch"): str,
Required("fetch-version-from"): str,
Required("version-files"): [
{
Required("filename"): str,
Required("version-bump"): str,
Optional("new-suffix"): str,
},
],
},
},
{
Required("main-bump"): {
Required("to-branch"): str,
Required("fetch-version-from"): str,
Required("version-files"): [
{
Required("filename"): str,
Required("version-bump"): str,
Optional("new-suffix"): str,
},
],
Optional("replacements"): [[str]],
Optional("regex-replacements"): [[str]],
Optional("end-tag"): str,
},
},
{
Required("early-to-late-beta"): {
Required("to-branch"): str,
Optional("replacements"): [[str]],
},
},
{
Required("uplift"): {
Required("fetch-version-from"): str,
Required("version-files"): [
{
Required("filename"): str,
Optional("version-bump"): str,
Optional("new-suffix"): str,
},
],
Required("from-branch"): str,
Required("to-branch"): str,
Optional("replacements"): [[str]],
Optional("base-tag"): str,
Optional("end-tag"): str,
Optional("l10n-bump-info"): l10n_bump_info_schema,
},
},
)
],
Optional("ignore-closed-tree"): bool,
Optional("dontbuild"): bool,
Optional("force-dry-run"): bool,
Optional("matrix-rooms"): [str],
},
)
def build_lando_payload(config, task, task_def):
worker = task["worker"]
release_config = get_release_config(config)
task_def["payload"] = {"actions": [], "lando_repo": worker["lando-repo"]}
task_def["tags"]["worker-implementation"] = "scriptworker"
actions = task_def["payload"]["actions"]

if worker.get("ignore-closed-tree") is not None:
task_def["payload"]["ignore_closed_tree"] = worker["ignore-closed-tree"]

if worker.get("dontbuild"):
task_def["payload"]["dontbuild"] = True

if worker.get("force-dry-run"):
task_def["payload"]["dry_run"] = True

for action in worker["actions"]:
if info := action.get("android-l10n-import"):
android_l10n_import_info = dash_to_underscore(info)
android_l10n_import_info["toml_info"] = [
dash_to_underscore(ti) for ti in android_l10n_import_info["toml_info"]
]
task_def["payload"]["android_l10n_import_info"] = android_l10n_import_info
actions.append("android_l10n_import")

if info := action.get("android-l10n-sync"):
android_l10n_sync_info = dash_to_underscore(info)
android_l10n_sync_info["toml_info"] = [
dash_to_underscore(ti) for ti in android_l10n_sync_info["toml_info"]
]
task_def["payload"]["android_l10n_sync_info"] = android_l10n_sync_info
actions.append("android_l10n_sync")

if info := action.get("l10n-bump"):
task_def["payload"]["l10n_bump_info"] = process_l10n_bump_info(info)
actions.append("l10n_bump")

if info := action.get("tag"):
tag_types = info["types"]
tag_names = []
product = task["shipping-product"].upper()
version = release_config["version"].replace(".", "_")
buildnum = release_config["build_number"]
if "buildN" in tag_types:
tag_names.extend(
[
f"{product}_{version}_BUILD{buildnum}",
]
)
if "release" in tag_types:
tag_names.extend([f"{product}_{version}_RELEASE"])
tag_info = {
"tags": tag_names,
"hg_repo_url": info["hg-repo-url"],
"revision": config.params[
"{}head_rev".format(worker.get("repo-param-prefix", ""))
],
}
task_def["payload"]["tag_info"] = tag_info
actions.append("tag")

if info := action.get("version-bump"):
bump_info = {}
bump_info["next_version"] = release_config["next_version"]
bump_info["files"] = info["bump-files"]
task_def["payload"]["version_bump_info"] = bump_info
actions.append("version_bump")

if info := action.get("esr-bump"):
merge_info = dash_to_underscore(info)
merge_info["version_files"] = [
dash_to_underscore(vf) for vf in info["version-files"]
]
task_def["payload"]["merge_info"] = merge_info
actions.append("merge_day")

if info := action.get("main-bump"):
merge_info = dash_to_underscore(info)

merge_info["version_files"] = [
dash_to_underscore(vf) for vf in info["version-files"]
]
task_def["payload"]["merge_info"] = merge_info
actions.append("merge_day")

if info := action.get("early-to-late-beta"):
task_def["payload"]["merge_info"] = dash_to_underscore(info)
actions.append("merge_day")

if info := action.get("uplift"):
merge_info = dash_to_underscore(info)
merge_info["merge_old_head"] = True

merge_info["version_files"] = [
dash_to_underscore(vf) for vf in info["version-files"]
]
if lbi := info.get("l10n-bump-info"):
merge_info["l10n_bump_info"] = process_l10n_bump_info(lbi)

task_def["payload"]["merge_info"] = merge_info
actions.append("merge_day")

scopes = set(task_def.get("scopes", []))
scopes.add(f"project:releng:lando:repo:{worker['lando-repo']}")
scopes.update([f"project:releng:lando:action:{action}" for action in actions])

for matrix_room in worker.get("matrix-rooms", []):
task_def.setdefault("routes", [])
task_def["routes"].append(f"notify.matrix-room.{matrix_room}.on-pending")
task_def["routes"].append(f"notify.matrix-room.{matrix_room}.on-resolved")
scopes.add("queue:route:notify.matrix-room.*")

task_def["scopes"] = sorted(scopes)


def get_release_config(config):
"""Get the build number and version for a release task.

Currently only applies to beetmover tasks.

Args:
config (TransformConfig): The configuration for the kind being transformed.

Returns:
dict: containing both `build_number` and `version`. This can be used to
update `task.payload`.
"""
return {
"version": config.params["version"],
"appVersion": config.params["app_version"],
"next_version": config.params["next_version"],
"build_number": config.params["build_number"],
}


def dash_to_underscore(obj):
new_obj = {}
for k, v in obj.items():
new_obj[k.replace("-", "_")] = v
return new_obj
5 changes: 3 additions & 2 deletions test/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ def file_url(self, path, pretty=False):
def parameters():
return FakeParameters(
{
"app_version": "99.0",
"base_ref": "123456",
"base_repository": "http://example.com/base/repo",
"build_date": 0,
Expand All @@ -85,15 +86,15 @@ def parameters():
"head_tag": "",
"level": "1",
"moz_build_date": 0,
"next_version": "1.0.1",
"next_version": "100.0",
"owner": "some-owner",
"project": "some-project",
"pushlog_id": 1,
"repository_type": "hg",
"target_tasks_method": "test_method",
"tasks_for": "hg-push",
"try_mode": None,
"version": "",
"version": "99.0",
}
)

Expand Down
Loading