Revision control
Copy as Markdown
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
import os
import re
from importlib import import_module
from typing import Optional
from mozilla_taskgraph import register as mozilla_taskgraph_register
from mozilla_taskgraph.actions import enable_action
from taskgraph.parameters import extend_parameters_schema
from taskgraph.util.schema import Schema
from . import branch_builds
from .build_config import get_version_from_version_txt # noqa: F401
PREVIEW_RE = re.compile(r"\[preview ([\w-]+)\]")
RELEASE_PROMOTION_PROJECTS = (
)
_branch_build_repo = {
"owner": Optional[str],
"branch": Optional[str],
}
AppServicesParametersSchema = Schema.from_dict(
{
"branch-build": Schema.from_dict(
{
"firefox-android": Schema.from_dict(
_branch_build_repo, name="BranchBuildAndroid", optional=True
),
"firefox-ios": Schema.from_dict(
_branch_build_repo, name="BranchBuildIOS", optional=True
),
},
name="BranchBuild",
optional=True,
),
# Publish a "preview build" for a future version. This is set to
# "nightly" for the nightly builds. Other strings indicate making a
# preview build for a particular application-services branch.
"preview-build": Optional[str],
# Release type. Set to `release` or `nightly` when we're building release artifacts.
"release-type": Optional[str],
},
name="AppServicesParameters",
kw_only=True,
forbid_unknown_fields=False,
)
def is_relpro_available(params):
return params["head_repository"] in RELEASE_PROMOTION_PROJECTS
def register(graph_config):
# Import modules to register decorated functions
_import_modules(
[
"branch_builds",
"job",
"target_tasks",
"transforms",
"worker_types",
]
)
extend_parameters_schema(AppServicesParametersSchema)
# Register mozilla-taskgraph extensions
mozilla_taskgraph_register(graph_config)
# Enable mozilla-taskgraph actions
enable_action("release-promotion", available=is_relpro_available)
def _import_modules(modules):
for module in modules:
import_module(f".{module}", package=__name__)
def get_decision_parameters(graph_config, parameters):
if parameters["tasks_for"] == "github-pull-request":
pr_title = os.environ.get("APPSERVICES_PULL_REQUEST_TITLE", "")
preview_match = PREVIEW_RE.search(pr_title)
if preview_match is not None:
if preview_match.group(1) == "nightly":
parameters["preview-build"] = "nightly"
parameters["target_tasks_method"] = "full"
elif preview_match.group(1) == "release":
parameters["target_tasks_method"] = "full"
parameters["release-type"] = "release"
else:
raise NotImplementedError(
"Only nightly preview builds are currently supported"
)
elif "[ci full]" in pr_title:
parameters["target_tasks_method"] = "pr-full"
elif "[ci skip]" in pr_title:
parameters["target_tasks_method"] = "pr-skip"
else:
parameters["target_tasks_method"] = "pr-normal"
elif parameters["tasks_for"] == "github-push":
if parameters["head_tag"].startswith("release-"):
parameters["target_tasks_method"] = "release"
parameters["release-type"] = "release"
elif parameters["tasks_for"] == "cron":
# We don't have a great way of determining if something is a nightly or
# not. But for now, we can assume all cron-based builds are nightlies.
parameters["preview-build"] = "nightly"
parameters["release-type"] = "nightly"
parameters["branch-build"] = branch_builds.calc_branch_build_param(parameters)
parameters["filters"].extend(
[
"branch-build",
]
)