예제 #1
0
async def bump_version(config, task, repo_path, repo_type):
    """Perform a version bump.

    This function takes its inputs from task by using the ``get_version_bump_info``
    function from treescript.task. Using `next_version` and `files`, then
    calls do_version_bump to perform the work.

    Args:
        config (dict): the running config
        task (dict): the running task
        repo_path (str): the source directory

    Returns:
        int: the number of commits created.

    """
    bump_info = get_version_bump_info(task)
    num_commits = 0

    changed = await do_bump_version(config, repo_path, bump_info["files"], bump_info["next_version"])
    vcs = get_vcs_module(repo_type)
    if changed:
        commit_msg = "Automatic version bump CLOSED TREE NO BUG a=release"
        if get_dontbuild(task):
            commit_msg += DONTBUILD_MSG
        await vcs.commit(config, repo_path, commit_msg)
        num_commits += 1
    return num_commits
예제 #2
0
async def l10n_bump(config, task, repo_path):
    """Perform a version bump.

    This function takes its inputs from task by using the ``get_l10n_bump_info``
    function from treescript.task. Using `next_version` and `files`.

    This function does nothing (but logs) if the current version and next version
    match, and nothing if the next_version is actually less than current_version.

    Args:
        config (dict): the running config
        task (dict): the running task
        repo_path (str): the source directory

    Raises:
        TaskVerificationError: if a file specified is not allowed, or
                               if the file is not in the target repository.

    Returns:
        bool: True if there are any changes.

    """
    log.info("Preparing to bump l10n changesets.")
    dontbuild = get_dontbuild(task)
    ignore_closed_tree = get_ignore_closed_tree(task)
    l10n_bump_info = get_l10n_bump_info(task)
    revision_info = None
    changes = 0

    if not ignore_closed_tree:
        if not await check_treestatus(config, task):
            log.info("Treestatus is closed; skipping l10n bump.")
            return
    for bump_config in l10n_bump_info:
        if bump_config.get("revision_url"):
            revision_info = await get_revision_info(bump_config, repo_path)
        path = os.path.join(repo_path, bump_config["path"])
        old_contents = load_json_or_yaml(path, is_path=True)
        new_contents = build_revision_dict(bump_config, revision_info,
                                           repo_path)
        if old_contents == new_contents:
            continue
        with open(path, "w") as fh:
            fh.write(
                json.dumps(new_contents,
                           sort_keys=True,
                           indent=4,
                           separators=(",", ": ")))
        locale_map = build_locale_map(old_contents, new_contents)
        message = build_commit_message(bump_config["name"],
                                       locale_map,
                                       dontbuild=dontbuild,
                                       ignore_closed_tree=ignore_closed_tree)
        await run_hg_command(config,
                             "commit",
                             "-m",
                             message,
                             repo_path=repo_path)
        changes += 1
    return changes
async def do_tagging(config, task, repo_path):
    """Perform tagging, at ${repo_path}/src.

    This function will perform a mercurial tag, on 'default' head of target repository.
    It will tag the revision specified in the tag_info portion of the task payload, using
    the specified tags in that payload.

    Tags are forced to be created at the specified revision if they already existed.

    This function has the side affect of pulling the specified revision from the
    destination repository. This feature exists because mozilla-unified does not
    contain relbranches, though some releases are created on relbranches, so we must ensure
    the desired revision to tag is known to the local repository.

    Args:
        config (dict): the running config.
        task (dict): the running task.
        repo_path (str): The directory to place the resulting clone.

    Raises:
        FailedSubprocess: if the tag attempt doesn't succeed.

    Returns:
        bool: True if there are any changes.

    """
    tag_info = get_tag_info(task)
    desired_tags = await check_tags(config, tag_info, repo_path)
    if not desired_tags:
        log.info("No unique tags to add; skipping tagging.")
        return
    desired_rev = tag_info["revision"]
    dontbuild = get_dontbuild(task)
    dest_repo = get_source_repo(task)
    commit_msg = TAG_MSG.format(revision=desired_rev, tags=", ".join(desired_tags))
    if dontbuild:
        commit_msg += DONTBUILD_MSG
    log.info(
        "Pulling {revision} from {repo} explicitly.".format(
            revision=desired_rev, repo=dest_repo
        )
    )
    await run_hg_command(
        config, "pull", "-r", desired_rev, dest_repo, repo_path=repo_path
    )
    log.info(commit_msg)
    await run_hg_command(
        config,
        "tag",
        "-m",
        commit_msg,
        "-r",
        desired_rev,
        "-f",  # Todo only force if needed
        *desired_tags,
        repo_path=repo_path,
    )
    return True
예제 #4
0
async def l10n_bump(config, task, repo_path, repo_type="hg"):
    """Perform a l10n revision bump.

    This function takes its inputs from task by using the ``get_l10n_bump_info``
    function from treescript.task. It then calculates the locales, the platforms
    for each locale, and the locale revision for each locale.

    Args:
        config (dict): the running config
        task (dict): the running task
        repo_path (str): the source directory
        repo_type (str): the repository type

    Raises:
        TaskVerificationError: if a file specified is not allowed, or
                               if the file is not in the target repository.

    Returns:
        int: non-zero if there are any changes.

    """
    vcs = get_vcs_module(repo_type)

    log.info("Preparing to bump l10n changesets.")

    ignore_closed_tree = get_ignore_closed_tree(task)
    if not ignore_closed_tree:
        if not await check_treestatus(config, task):
            log.info("Treestatus is closed; skipping l10n bump.")
            return 0

    dontbuild = get_dontbuild(task)
    l10n_bump_info = get_l10n_bump_info(task)
    changes = 0

    for bump_config in l10n_bump_info:
        path = os.path.join(repo_path, bump_config["path"])
        old_contents = load_json_or_yaml(path, is_path=True)
        new_contents = await build_revision_dict(bump_config, repo_path,
                                                 deepcopy(old_contents))
        if old_contents == new_contents:
            continue
        with open(path, "w") as fh:
            fh.write(
                json.dumps(new_contents,
                           sort_keys=True,
                           indent=4,
                           separators=(",", ": ")))
        locale_map = build_locale_map(old_contents, new_contents)
        message = build_commit_message(bump_config["name"],
                                       locale_map,
                                       dontbuild=dontbuild,
                                       ignore_closed_tree=ignore_closed_tree)
        await vcs.commit(config, repo_path, message)
        changes += 1
    return changes
예제 #5
0
async def do_tagging(context, directory):
    """Perform tagging, at ${directory}/src.

    This function will perform a mercurial tag, on 'default' head of target repository.
    It will tag the revision specified in the tag_info portion of the task payload, using
    the specified tags in that payload.

    Tags are forced to be created at the specified revision if they already existed.

    This function has the side affect of pulling the specified revision from the
    destination repository. This feature exists because mozilla-unified does not
    contain relbranches, though some releases are created on relbranches, so we must ensure
    the desired revision to tag is known to the local repository.

    Args:
        context (TreeScriptContext): the treescript context
        directory (str): The directory to place the resulting clone.

    Raises:
        FailedSubprocess: if the tag attempt doesn't succeed.

    """
    local_repo = os.path.join(directory, 'src')
    tag_info = get_tag_info(context.task)
    desired_tags = tag_info['tags']
    desired_rev = tag_info['revision']
    dontbuild = get_dontbuild(context.task)
    dest_repo = get_source_repo(context.task)
    commit_msg = TAG_MSG.format(revision=desired_rev,
                                tags=', '.join(desired_tags))
    if dontbuild:
        commit_msg += DONTBUILD_MSG
    log.info("Pulling {revision} from {repo} explicitly.".format(
        revision=desired_rev, repo=dest_repo))
    await run_hg_command(context,
                         'pull',
                         '-r',
                         desired_rev,
                         dest_repo,
                         local_repo=local_repo)
    log.info(commit_msg)
    await run_hg_command(
        context,
        'tag',
        '-m',
        commit_msg,
        '-r',
        desired_rev,
        '-f',  # Todo only force if needed
        *desired_tags,
        local_repo=local_repo)
예제 #6
0
def test_get_dontbuild(task_defn, dontbuild):
    if dontbuild:
        task_defn["payload"]["dontbuild"] = True
    assert ttask.get_dontbuild(task_defn) == dontbuild
async def bump_version(context):
    """Perform a version bump.

    This function takes its inputs from context.task by using the ``get_version_bump_info``
    function from treescript.task. Using `next_version` and `files`.

    This function does nothing (but logs) if the current version and next version
    match, and nothing if the next_version is actually less than current_version.

    raises:
        TaskverificationError: if a file specified is not allowed, or
                               if the file is not in the target repository.

    """
    bump_info = get_version_bump_info(context.task)
    next_version = bump_info['next_version']
    old_next_version = None
    files = bump_info['files']
    changed = False
    for file in files:
        if old_next_version:
            next_version = old_next_version
        abs_file = os.path.join(context.repo, file)
        if file not in ALLOWED_BUMP_FILES:
            raise TaskVerificationError(
                "Specified file to version bump is not in whitelist")
        if not os.path.exists(abs_file):
            raise TaskVerificationError("Specified file is not in repo")
        curr_version = _get_version(abs_file)

        Comparator = StrictVersion
        if curr_version.endswith('esr') or next_version.endswith('esr'):
            #  We use LooseVersion for ESR because StrictVersion can't parse the trailing
            # 'esr', but StrictVersion otherwise because it can sort X.0bN lower than X.0
            Comparator = LooseVersion
        if Comparator(next_version) < Comparator(curr_version):
            log.warning("Version bumping skipped due to conflicting values: "
                        "(next version {} is < current version {})".format(
                            next_version, curr_version))
            continue
        elif Comparator(next_version) == Comparator(curr_version):
            log.info("Version bumping skipped due to unchanged values")
            continue
        else:
            changed = True
            if curr_version.endswith('esr'):
                # Only support esr addition if already an esr string.
                if not next_version.endswith('esr'):
                    old_next_version = next_version
                    next_version = next_version + 'esr'
            replace_ver_in_file(file=abs_file,
                                curr_version=curr_version,
                                new_version=next_version)
    if changed:
        dontbuild = get_dontbuild(context.task)
        commit_msg = 'Automatic version bump CLOSED TREE NO BUG a=release'
        if dontbuild:
            commit_msg += DONTBUILD_MSG
        await run_hg_command(context,
                             'commit',
                             '-m',
                             commit_msg,
                             local_repo=context.repo)
예제 #8
0
async def bump_version(context):
    """Perform a version bump.

    This function takes its inputs from context.task by using the ``get_version_bump_info``
    function from treescript.task. Using `next_version` and `files`.

    This function does nothing (but logs) if the current version and next version
    match, and nothing if the next_version is actually less than current_version.

    raises:
        TaskverificationError: if a file specified is not allowed, or
                               if the file is not in the target repository.

    """
    bump_info = get_version_bump_info(context.task)
    files = bump_info['files']
    changed = False

    for file in files:
        abs_file = os.path.join(context.repo, file)
        if file not in ALLOWED_BUMP_FILES:
            raise TaskVerificationError(
                "Specified file to version bump is not in whitelist")
        if not os.path.exists(abs_file):
            raise TaskVerificationError("Specified file is not in repo")

        VersionClass = _find_what_version_parser_to_use(file)
        curr_version = VersionClass.parse(_get_version(abs_file))
        next_version = VersionClass.parse(bump_info['next_version'])

        # XXX In the case of ESR, some files (like version.txt) show version numbers without `esr`
        # at the end. next_version is usually provided without `esr` too.
        # That's why we do this late minute replacement and why we reset `next_version` at every
        # cycle of the loop
        if curr_version.is_esr and not any((
                next_version.is_esr,  # No need to append esr again
                # We don't want XX.Ya1esr nor XX.YbNesr
                next_version.is_aurora_or_devedition,
                next_version.is_beta,
        )):
            next_version = VersionClass.parse('{}esr'.format(
                bump_info['next_version']))

        if next_version < curr_version:
            log.warning("Version bumping skipped due to conflicting values: "
                        "(next version {} is < current version {})".format(
                            next_version, curr_version))
            continue
        elif next_version == curr_version:
            log.info("Version bumping skipped due to unchanged values")
            continue
        else:
            changed = True
            replace_ver_in_file(abs_file, curr_version, next_version)

    if changed:
        dontbuild = get_dontbuild(context.task)
        commit_msg = 'Automatic version bump CLOSED TREE NO BUG a=release'
        if dontbuild:
            commit_msg += DONTBUILD_MSG
        await run_hg_command(context,
                             'commit',
                             '-m',
                             commit_msg,
                             local_repo=context.repo)
예제 #9
0
async def bump_version(config, task, repo_path):
    """Perform a version bump.

    This function takes its inputs from task by using the ``get_version_bump_info``
    function from treescript.task. Using `next_version` and `files`.

    This function does nothing (but logs) if the current version and next version
    match, and nothing if the next_version is actually less than current_version.

    Args:
        config (dict): the running config
        task (dict): the running task
        repo_path (str): the source directory

    Raises:
        TaskverificationError: if a file specified is not allowed, or
                               if the file is not in the target repository.

    Returns:
        int: the number of commits created.

    """
    bump_info = get_version_bump_info(task)
    files = bump_info["files"]
    changed = False
    num_commits = 0

    for file_ in files:
        abs_file = os.path.join(repo_path, file_)
        if file_ not in ALLOWED_BUMP_FILES:
            raise TaskVerificationError(
                "{} is not in version bump whitelist".format(file_))
        if not os.path.exists(abs_file):
            raise TaskVerificationError("{} is not in repo".format(abs_file))

        VersionClass = _find_what_version_parser_to_use(file_)
        curr_version = get_version(file_, repo_path)
        next_version = VersionClass.parse(bump_info["next_version"])

        # XXX In the case of ESR, some files (like version.txt) show version numbers without `esr`
        # at the end. next_version is usually provided without `esr` too.
        # That's why we do this late minute replacement and why we reset `next_version` at every
        # cycle of the loop
        if curr_version.is_esr and not any((
                next_version.is_esr,  # No need to append esr again
                # We don't want XX.Ya1esr nor XX.YbNesr
                next_version.is_aurora_or_devedition,
                next_version.is_beta,
        )):
            next_version = VersionClass.parse("{}esr".format(
                bump_info["next_version"]))

        if next_version < curr_version:
            log.warning("Version bumping skipped due to conflicting values: "
                        "(next version {} is < current version {})".format(
                            next_version, curr_version))
            continue
        elif next_version == curr_version:
            log.info("Version bumping skipped due to unchanged values")
            continue
        else:
            changed = True
            replace_ver_in_file(abs_file, curr_version, next_version)

    if changed:
        dontbuild = get_dontbuild(task)
        commit_msg = "Automatic version bump CLOSED TREE NO BUG a=release"
        if dontbuild:
            commit_msg += DONTBUILD_MSG
        await run_hg_command(config,
                             "commit",
                             "-m",
                             commit_msg,
                             repo_path=repo_path)
        num_commits += 1
    return num_commits