taskcluster/comm_taskgraph/optimize.py
author Richard Marti <richard.marti@gmail.com>
Fri, 20 Nov 2020 17:14:49 +0100
changeset 95739 3c8996f7d3ae715359f5eb7f08f26a4418150719
parent 94684 7473fd8d06d91efb619ea3bee69fa6307c7ba9d3
permissions -rw-r--r--
Bug 1641519 - Set the style for quoted text defined in preferences to plain text composertoo. r=mkmelin

#  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
#  file, You can obtain one at http://mozilla.org/MPL/2.0/.
"""
Thunderbird specific taskgraph optimizers.
"""

from __future__ import absolute_import, print_function, unicode_literals

import logging

from taskgraph.optimize import (
    register_strategy,
    OptimizationStrategy,
)
from taskgraph.optimize.schema import (
    default_optimizations,
)
from mozbuild.util import memoize
from mozpack.path import match as mozpackmatch
from taskgraph.files_changed import get_changed_files

logger = logging.getLogger(__name__)


def is_excluded(check_path, file_patterns):
    for pattern in file_patterns:
        if mozpackmatch(check_path, pattern):
            return True
    return False


def is_suite(check_path):
    suite_patterns = ("editor", "suite")
    return is_excluded(check_path, suite_patterns)


@memoize
def get_non_suite_changed_files(repository, revision):
    """
    Returns the list of changed files from comm- repository (no prefixing)
    with suite/** and editor/** files removed.
    """
    return {
        file for file in get_changed_files(repository, revision) if not is_suite(file)
    }


@register_strategy("skip-suite-only")
class SkipSuiteOnly(OptimizationStrategy):
    def should_remove_task(self, task, params, arg):
        # pushlog_id == -1 - this is the case when run from a cron.yml job
        if params.get("pushlog_id") == -1:
            return False

        repository = params.get("comm_head_repository")
        revision = params.get("comm_head_rev")
        non_suite_changed_files = get_non_suite_changed_files(repository, revision)
        # non_suite_changed_files will be an empty set (Falsy) for suite-only pushes
        # so "skip" this task
        if not non_suite_changed_files:
            return True
        return False


thunderbird_optimizations = default_optimizations + ({"skip-suite-only": None},)