示例#1
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)
    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:
        commit_msg = 'Automatic version bump CLOSED TREE NO BUG a=release'
        await run_hg_command(context,
                             'commit',
                             '-m',
                             commit_msg,
                             local_repo=context.repo)
示例#2
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
示例#3
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)
    next_version = bump_info['next_version']
    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")
        curr_version = _get_version(abs_file)

        if StrictVersion(next_version) < StrictVersion(curr_version):
            log.warning("Version bumping skipped due to conflicting values: "
                        "(next version {} is < current version {})".format(
                            next_version, curr_version))
            continue
        elif StrictVersion(next_version) == StrictVersion(curr_version):
            log.info("Version bumping skipped due to unchanged values")
            continue
        else:
            changed = True
            replace_ver_in_file(file=abs_file,
                                curr_version=curr_version,
                                new_version=next_version)
    if changed:
        commit_msg = 'Automatic version bump CLOSED TREE NO BUG a=release'
        await run_hg_command(context,
                             'commit',
                             '-m',
                             commit_msg,
                             local_repo=context.repo)
def test_bump_missing_bump_info(task_defn):
    with pytest.raises(TaskVerificationError):
        ttask.get_version_bump_info(task_defn)
def test_bump_info(task_defn, bump_info):
    task_defn["payload"]["version_bump_info"] = bump_info
    tested_info = ttask.get_version_bump_info(task_defn)
    assert tested_info == bump_info
示例#6
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)
示例#7
0
def test_bump_missing_bump_info(task_defn):
    with pytest.raises(TaskVerificationError):
        stask.get_version_bump_info(task_defn)
示例#8
0
def test_bump_info(task_defn, bump_info):
    task_defn['payload']['version_bump_info'] = bump_info
    tested_info = stask.get_version_bump_info(task_defn)
    assert tested_info == bump_info
示例#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