def test_get_merge_config_missing(task_defn):
    with pytest.raises(TaskVerificationError):
        ttask.get_merge_config(task_defn)
Exemple #2
0
async def do_merge(config, task, repo_path):
    """Perform a merge day operation.

    This function takes its inputs from task's payload.

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

    Raises:
        TaskverificationError: from get_merge_config if the payload is invalid.

    Returns:
        list: A list of the branches that need pushing, and the corresponding revision.
              This is unlike other actions as the list of outgoing changes is
              not related to the number of commands we've performed, but we do need
              to know which branches to push.
    """
    merge_config = get_merge_config(task)

    from_branch = merge_config.get("from_branch")
    to_branch = merge_config.get("to_branch")

    await run_hg_command(config,
                         "pull",
                         "https://hg.mozilla.org/mozilla-unified",
                         repo_path=repo_path)

    # Used if end_tag is set.
    await run_hg_command(config, "up", "-C", to_branch, repo_path=repo_path)
    to_fx_major_version = get_version("browser/config/version.txt",
                                      repo_path).major_number
    base_to_rev = await get_revision(config, repo_path, branch=to_branch)

    if from_branch:
        await run_hg_command(config,
                             "up",
                             "-C",
                             from_branch,
                             repo_path=repo_path)
        base_from_rev = await get_revision(config,
                                           repo_path,
                                           branch=from_branch)

    base_tag = merge_config.get("base_tag")
    if base_tag:
        base_tag = base_tag.format(major_version=get_version(
            "browser/config/version.txt", repo_path).major_number)
        tag_message = f"No bug - tagging {base_from_rev} with {base_tag} a=release DONTBUILD CLOSED TREE"
        await run_hg_command(config,
                             "tag",
                             "-m",
                             tag_message,
                             "-r",
                             base_from_rev,
                             "-f",
                             base_tag,
                             repo_path=repo_path)

    tagged_from_rev = await get_revision(config, repo_path, branch=".")

    # TODO This shouldn't be run on esr, according to old configs.
    # perhaps: hg push -r bookmark("release") esrNN
    # Perform the kludge-merge.
    if merge_config.get("merge_old_head", False):
        await run_hg_command(config,
                             "debugsetparents",
                             tagged_from_rev,
                             base_to_rev,
                             repo_path=repo_path)
        await run_hg_command(
            config,
            "commit",
            "-m",
            "Merge old head via |hg debugsetparents {} {}| CLOSED TREE DONTBUILD a=release"
            .format(tagged_from_rev, base_to_rev),
            repo_path=repo_path,
        )
        await preserve_tags(config, repo_path, to_branch)

    end_tag = merge_config.get("end_tag")  # tag the end of the to repo
    if end_tag:
        end_tag = end_tag.format(major_version=to_fx_major_version)
        tag_message = f"No bug - tagging {base_to_rev} with {end_tag} a=release DONTBUILD CLOSED TREE"
        await run_hg_command(config,
                             "tag",
                             "-m",
                             tag_message,
                             "-r",
                             base_to_rev,
                             "-f",
                             end_tag,
                             repo_path=repo_path)

    await apply_rebranding(config, repo_path, merge_config)

    diff_output = await run_hg_command(config,
                                       "diff",
                                       repo_path=repo_path,
                                       return_output=True)
    path = os.path.join(config["artifact_dir"], "public", "logs",
                        "{}.diff".format(to_branch))
    makedirs(os.path.dirname(path))
    with open(path, "w") as fh:
        fh.write(diff_output)

    await run_hg_command(
        config,
        "commit",
        "-m",
        "Update configs. IGNORE BROKEN CHANGESETS CLOSED TREE NO BUG a=release ba=release",
        repo_path=repo_path)
    push_revision_to = await get_revision(config, repo_path, branch=".")

    # Do we need to perform multiple pushes for the push stage? If so, return
    # what to do.
    desired_pushes = list()
    if merge_config.get("from_repo"):
        desired_pushes.append((merge_config["from_repo"], tagged_from_rev))
    if merge_config.get("to_repo"):
        desired_pushes.append((merge_config["to_repo"], push_revision_to))
    return desired_pushes
def test_get_merge_config(task_defn, config):
    task_defn["payload"]["merge_info"] = config
    assert ttask.get_merge_config(task_defn) == config