Esempio n. 1
0
def bump(latest):
    merge_request_id = extract_merge_request_id_from_commit()
    labels = retrieve_labels_from_merge_request(merge_request_id)
    new_version = None
    print('MR Labels', labels)
    if "bump-major" in labels:
        print('Bump major')
        new_version = semver.bump_major(latest)
    elif "bump-minor" in labels:
        print('Bump minor')
        new_version = semver.bump_minor(latest)
    elif "bump-patch" in labels:
        print('Bump patch')
        new_version = semver.bump_patch(latest)
    elif "finalize-rc" in labels:
        print('Finalize rc')
        new_version = semver.finalize_version(latest)
    elif "bump-build":
        print('Bump build')
        new_version = semver.bump_build(new_version if new_version else latest)

    if "bump-rc" in labels and not "finalize-rc" in labels:
        print('Bump rc')
        new_version = semver.bump_prerelease(
            new_version if new_version else latest)
        new_version = semver.bump_build(new_version)

    return new_version if new_version else latest
def version_from_git_tag(project, logger):
    """ Set project version according git tags"""
    # get git info
    tags, last_commit, repo_is_dirty = _get_repo_info(
        project.get_property('semver_git_tag_repo_dir') if project.
        get_property('semver_git_tag_repo_dir') else project.basedir)
    # get last tag which satisfies SemVer
    last_semver_tag = None
    semver_regex = semver._REGEX  # pylint: disable=protected-access
    tag_list = []
    for tag in reversed(tags):
        tag_list.append(tag.name)
    logger.debug("All git tags: %s." % ','.join(tag_list))
    for tag in reversed(tags):
        match = semver_regex.match(tag.name)
        if match:
            if ((not last_semver_tag)
                    or (semver.compare(tag.name, last_semver_tag.name) == 1)):
                last_semver_tag = tag
    if not last_semver_tag:
        logger.warn("No SemVer git tag found. "
                    "Consider removing plugin pybuilder_semver_git_tag.")
        return
    else:
        logger.info("Found SemVer tag: %s" % last_semver_tag.name)
    # get last commit for HEAD
    # if dirty or last commit isn't equal last tag commit
    # - increase version and add .dev
    if last_commit != last_semver_tag.commit or repo_is_dirty:
        if repo_is_dirty:
            logger.debug("Repo is marked as dirty - use dev version.")
        else:
            logger.debug("Last tag %s has commit %s, "
                         "but last commit is %s - use dev version." %
                         (last_semver_tag.name, str(
                             last_semver_tag.commit), str(last_commit)))
        increase_part = project.get_property('semver_git_tag_increment_part')
        if increase_part == 'major':
            project.version = _add_dev(semver.bump_major(last_semver_tag.name))
        elif increase_part == 'minor':
            project.version = _add_dev(semver.bump_minor(last_semver_tag.name))
        elif increase_part == 'patch':
            project.version = _add_dev(semver.bump_patch(last_semver_tag.name))
        else:
            raise BuildFailedException(
                "Incorrect value for `semver_git_tag_increment_part` property. "
                "Has to be in (`major`, `minor`, `patch`), but %s passed." %
                project.get_property('semver_git_tag_increment_part'))
    # if not dirty and last commit is equal last tag commit
    # - it's release tag
    else:
        project.version = last_semver_tag.name
    # DISTRIBUTION_PROPERTY is also be affected
    project.set_property(
        DISTRIBUTION_PROPERTY,
        "$dir_target/dist/{0}-{1}".format(project.name, project.version))
    logger.info(
        "Project version was changed to: %s, dist_version: %s, %s: %s" %
        (project.version, project.dist_version, DISTRIBUTION_PROPERTY,
         project.get_property(DISTRIBUTION_PROPERTY)))
Esempio n. 3
0
def _prepare_repo(repo_class, repo_path, mocker, monkeypatch, caplog):
    with caplog.at_level(logging.ERROR):  # Set log level to avoid to overcharge logs with GitPython logs
        # Initialize repository for testing
        repo = repo_class.init(path=repo_path)

        # Monkey patch and Mock _repo.git.push function so we do not need to effectively push to remotes during tests.
        # We cannot patch the git.push function due to GitPython implementation of Git class with __slots__
        # (c.f. https://github.com/gitpython-developers/GitPython/blob/master/git/cmd.py)
        # So we need to monkey path the full _repo.git attribute
        class MockGit(Git):
            def push(self, *args, **kwargs):
                pass

        monkeypatch.setattr(repo, 'git', value=MockGit(repo.working_dir))
        mocker.patch.object(repo.git, 'push')

        # Add files, commits and tags to the repository
        version = '0.0.0'
        for i, file in enumerate(repo.untracked_files):
            repo.git.add(file)
            repo.git.commit(file, '-m', 'add {file}'.format(file=file))
            if i % 2 == 0:
                repo.create_tag('v{version}'.format(version=version),
                                message='Release v{version}'.format(version=version))
                if i > 0 and i % 8 == 0:
                    version = semver.bump_major(version)
                elif i > 0 and i % 4 == 0:
                    version = semver.bump_minor(version)
                else:
                    version = semver.bump_patch(version)

        repo.create_remote('origin', '[email protected]:nmvalera/boilerplate-python.git')
    return repo
Esempio n. 4
0
    def next_version(self):
        """
        Based on the changelog, calculate what the next version would be. This is done by iterating
        over all issues in order and incrementing the version number according to each issue
        version modifier.

        Returns:
             str: The semantic version string
        """

        result = self._current_version

        self._debug('Determining next version...')

        for issue in self._sort(self.all_issues, reverse=False):

            if issue.version_modifier == ChangelogIssue.PATCH:
                result = semver.bump_patch(result)

            if issue.version_modifier == ChangelogIssue.MINOR:
                result = semver.bump_minor(result)

            if issue.version_modifier == ChangelogIssue.MAJOR:
                result = semver.bump_major(result)

            self._debug('Applied issue on incremental result.',
                        issue_title=issue.title,
                        result=result,
                        version_modifier=issue.version_modifier)

        result = None if result == self._current_version else result

        self._debug('Determined next version.', next_version=result)

        return result
Esempio n. 5
0
def version_string(path=None, *, valid_semver=False):
    version = None
    try:
        tag = subprocess.check_output('git describe --tags --exact-match',
                                      shell=True,
                                      cwd=path)
        version = tag.strip().decode("utf-8", "strict")
    except subprocess.CalledProcessError:
        describe = subprocess.check_output("git describe --tags",
                                           shell=True,
                                           cwd=path)
        tag, additional_commits, commitish = describe.strip().decode(
            "utf-8", "strict").rsplit("-", maxsplit=2)
        commitish = commitish[1:]
        if valid_semver:
            version_info = semver.parse_version_info(tag)
            if not version_info.prerelease:
                version = semver.bump_patch(
                    tag
                ) + "-alpha.0.plus." + additional_commits + "+" + commitish
            else:
                version = tag + ".plus." + additional_commits + "+" + commitish
        else:
            version = commitish
    return version
Esempio n. 6
0
def bump_version(version, increment_type):
    if increment_type == 'major':
        return semver.bump_major(version)
    elif increment_type == 'minor':
        return semver.bump_minor(version)
    elif increment_type == 'patch':
        return semver.bump_patch(version)
def version_string(path=None, *, valid_semver=False):
    version = None
    tag = subprocess.run('git describe --tags --exact-match', shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE, cwd=path)
    if tag.returncode == 0:
        version = tag.stdout.strip().decode("utf-8", "strict")
    else:
        describe = subprocess.run("git describe --tags --always", shell=True, stdout=subprocess.PIPE, cwd=path)
        describe = describe.stdout.strip().decode("utf-8", "strict").rsplit("-", maxsplit=2)
        if len(describe) == 3:
            tag, additional_commits, commitish = describe
            commitish = commitish[1:]
        else:
            tag = "0.0.0"
            commit_count = subprocess.run("git rev-list --count HEAD", shell=True, stdout=subprocess.PIPE, cwd=path)
            additional_commits = commit_count.stdout.strip().decode("utf-8", "strict")
            commitish = describe[0]
        if valid_semver:
            version_info = semver.parse_version_info(tag)
            if not version_info.prerelease:
                version = semver.bump_patch(tag) + "-alpha.0.plus." + additional_commits + "+" + commitish
            else:
                version = tag + ".plus." + additional_commits + "+" + commitish
        else:
            version = commitish
    return version
Esempio n. 8
0
def version_bump(ctx, major=False, minor=False, patch=False, version=''):

    """Makes the version bump in the required files"""

    import semver

    f = open("VERSION", "r")
    fversion = f.readline().strip('\n')
    f.close()

    if version:
        nversion = version
    else:
        version = fversion

        if major:
            nversion = semver.bump_major(version)
        elif minor:
            nversion = semver.bump_minor(version)
        elif patch:
            nversion = semver.bump_patch(version)
        else:
            print("No version change")

    print("Old version {} New version {}".format(fversion, nversion))

    ctx.run("sed -i -e 's/:version: .*/:version: {}/' README.rst".format(nversion))

    f = open("VERSION", "w")
    f.write(nversion)
    f.close()
Esempio n. 9
0
 def bump(latest):
     commit_message = git('show-branch', '--no-name', 'HEAD')
     if re.search(r'\[bump major\]', commit_message):
         return semver.bump_major(latest)
     if re.search(r'\[bump minor\]', commit_message):
         return semver.bump_minor(latest)
     return semver.bump_patch(latest)
def update_metadata(metadata, version_increment, provider, checksum,
                    serve_local):
    """
    Update the Vagrant box metadata.

    :param metadata: metadata to update
    :param version_increment: how to increment the version
    :param provider: for which provider to update the metadata
    :param checksum: new checksum for the box data
    :param serve_local: whether or not to serve the box locally
    :return: updated metadata
    :rtype: dict
    """
    if version_increment == 'major':
        metadata['version'] = bump_major(metadata['version'])
    elif version_increment == 'minor':
        metadata['version'] = bump_minor(metadata['version'])
    elif version_increment == 'patch':
        metadata['version'] = bump_patch(metadata['version'])

    current_provider_data = None
    for provider_data in metadata['providers']:
        if provider_data['name'] == provider:
            current_provider_data = provider_data
            break

    current_provider_data['checksum'] = checksum
    if serve_local:
        current_provider_data['url'] = serve_local

    return metadata
Esempio n. 11
0
    def bump(self,
             major=None,
             minor=None,
             patch=None,
             status=None,
             build=None):
        """Bump the version."""

        # Number positions are mutually exclusive.
        if major:
            self._current = semver.bump_major(self._original)
        elif minor:
            self._current = semver.bump_minor(self._original)
        elif patch:
            self._current = semver.bump_patch(self._original)
        else:
            self._current = self._original

        # Set the status.
        if status:
            self._current += "-%s" % status
        elif self.object.prerelease:
            self._current += "-%s" % self.object.prerelease
        else:
            pass

        # Set the build.
        if build:
            self._current += "+%s" % build
        elif self.object.build:
            self._current += "+%s" % self.object.build
        else:
            pass

        self.object = semver.parse_version_info(self._current)
Esempio n. 12
0
 def run(self):
     version, date = re.search(DATE_MATCH, requests.get(DOCS_URL).text).groups()
     return {
         "timestamp": arrow.get(date, "MMMM DD, YYYY").replace(days=+1).timestamp,
         "current": version,
         "next": semver.bump_patch(version),
     }
def bump_version(repopath):
    """Visit `repopath` and find a VERSION file, 
    increase that semver by one.

    """
    versionpath = os.path.join(repopath, "VERSION")
    try:
        with open(versionpath) as fo:
            ver = fo.read()
    except:
        user_message(
            "Unable to find / open VERSION file {}".format(versionpath))
        return

    try:
        nextver = semver.bump_patch(ver)
    except ValueError:
        user_message("The version in {} {} is not valid semver".format(
            versionpath, ver))
        return

    user_message("Current version is {} - hit Y to bump it to {}".format(
        ver, nextver))
    yn = input("Y/N: ")
    if yn == "Y":
        with open(versionpath, "w") as fo:
            fo.write(nextver)
    else:
        user_message("No action taken")
Esempio n. 14
0
def patch():
    v = get_version()
    nv = semver.bump_patch(v)
    if options["human"]:
        click.echo("{} -> {}".format(v, nv))
    else:
        click.echo(nv)
    write_version(nv)
Esempio n. 15
0
def next_tag(actual_tag, sim_tags, sim2actual, repo, ignorelist):
    last_tag = sim_tags[-1]

    runner = runtests.TestRunner(
        "test",
        repo=repo,
        cache="out/cache-"+actual_tag
    )

    nf_viol, bc_viol = cvt(runner, sim_tags, actual_tag,
                           semver.bump_patch(last_tag), sim2actual, ignorelist)
    if not nf_viol and not bc_viol:
        return semver.bump_patch(last_tag)
    elif not bc_viol:
        return semver.bump_minor(last_tag)
    else:
        return semver.bump_major(last_tag)
def patch():
    v = get_version()
    nv = semver.bump_patch(v)
    if options["human"]:
        click.echo("{} -> {}".format(v, nv))
    else:
        click.echo(nv)
    write_version(nv)
Esempio n. 17
0
 def increment_version(self, new_version: Optional[str] = None) -> None:
     self._sqlalchemy_object = Deployment(
         name=self._sqlalchemy_object.name,
         version=(new_version
                  or semver.bump_patch(self._sqlalchemy_object.version)))
     self._vault_objects = {
         k: self._vault_object_from_dict(v.definition)
         for k, v in self._vault_objects.items()
     }
Esempio n. 18
0
 def run(self):
     version, date = re.search(DATE_MATCH,
                               requests.get(DOCS_URL).text).groups()
     return {
         'timestamp': arrow.get(date,
                                'MMMM DD, YYYY').replace(days=+1).timestamp,
         'current': version,
         'next': semver.bump_patch(version)
     }
Esempio n. 19
0
 def transform_special_version(special_version: str, previous_version: str) -> str:
     if special_version in ["patch", "p"]:
         return semver.bump_patch(previous_version)
     elif special_version in ["minor", "m"]:
         return semver.bump_minor(previous_version)
     elif special_version in ["major", "M"]:
         return semver.bump_major(previous_version)
     else:
         raise "Unreachable: `transform_special_version` should never be called with invalid special version"
def bump(latest):
    merge_request = get_last_merge_request()
    labels = merge_request.labels

    if "bump-minor" in labels:
        return semver.bump_minor(latest)
    elif "bump-major" in labels:
        return semver.bump_major(latest)
    else:
        return semver.bump_patch(latest)
def bump(latest):
    merge_request_id = extract_merge_request_id_from_commit()
    labels = retrieve_labels_from_merge_request(merge_request_id)

    if "bump-minor" in labels:
        return semver.bump_minor(latest)
    elif "bump-major" in labels:
        return semver.bump_major(latest)
    else:
        return semver.bump_patch(latest)
Esempio n. 22
0
def bump_patch():
    version_file = open(realpath('./.version'), 'r+')
    version = semver.bump_patch(version_file.read().rstrip())

    version_file.seek(0)

    version_file.write(version)

    version_file.truncate()
    version_file.close()
Esempio n. 23
0
def bump(latest):
    merge_request_id = extract_merge_request_id_from_commit()
    labels = retrieve_labels_from_merge_request(merge_request_id)

    if "bump-minor" in labels:
        return semver.bump_minor(latest)
    elif "bump-major" in labels:
        return semver.bump_major(latest)
    else:
        return semver.bump_patch(latest)
Esempio n. 24
0
def main():
    """
    Main method.

    This method holds what you want to execute when
    the script is run on command line.
    """
    args = get_arguments()
    setup_logging(args)

    version_path = os.path.abspath(os.path.join(
        os.path.dirname(__file__),
        '..',
        '..',
        '.VERSION'
    ))

    try:
        version_text = open(version_path).read().strip()
    except Exception:
        print ('Could not open or read the .VERSION file')
        sys.exit(1)

    try:
        semver.parse(version_text)
    except ValueError:
        print ('The .VERSION file contains an invalid version: "{0}"'.format(
            version_text
        ))
        sys.exit(1)

    new_version = version_text
    if args.version:
        try:
            if semver.parse(args.version):
                new_version = args.version
        except Exception:
            print ('Could not parse "{0}" as a version'.format(
                args.version
            ))
            sys.exit(1)
    elif args.bump_major:
        new_version = semver.bump_major(version_text)
    elif args.bump_minor:
        new_version = semver.bump_minor(version_text)
    elif args.bump_patch:
        new_version = semver.bump_patch(version_text)

    try:
        with open(version_path, 'w') as version_file:
            version_file.write(new_version)
    except Exception:
        print ('Could not write the .VERSION file')
        sys.exit(1)
    print new_version
Esempio n. 25
0
def bump_version(current: str,
                 major: bool = False,
                 minor: bool = False,
                 patch: bool = False):
    if major:
        return semver.bump_major(current)
    if minor:
        return semver.bump_minor(current)
    if patch:
        return semver.bump_patch(current)
    return current
Esempio n. 26
0
def bump_version(latest):
    merge_request_id = extract_merge_request_id_from_commit()
    labels = retrieve_labels_from_merge_request(merge_request_id)

    if "bump::major" in str(labels):
        bump = semver.bump_major(latest)
    elif "bump::minor" in str(labels):
        bump = semver.bump_minor(latest)
    else:
        bump = semver.bump_patch(latest)

    return bump
    def release(self, release_type, local_template, current_version):
        product_version = current_version
        if release_type == 'build':
            product_version = semver.bump_build(current_version)
        if release_type == 'major':
            product_version = semver.bump_major(current_version)
        if release_type == 'minor':
            product_version = semver.bump_minor(current_version)
        if release_type == 'patch':
            product_version = semver.bump_patch(current_version)

        self.release_new_build(local_template, product_version)
Esempio n. 28
0
def new_version(bump_type, commit_hash):
    reload(app_info)
    template = Template(RELEASE_TEMPLATE)
    new_ver = app_info.version
    if bump_type == "major":
        new_ver = semver.bump_major(app_info.version)
    if bump_type == "minor":
        new_ver = semver.bump_minor(app_info.version)
    if bump_type == "patch":
        new_ver = semver.bump_patch(app_info.version)
    res = template.render({"version": new_ver, "commit_hash": commit_hash})
    with open("caffeine/app_info.py", "w") as f:
        f.write(res)
Esempio n. 29
0
def bump_version(component: str, version: str) -> str:
    sem_version = version.replace("v", "")
    bumped = ""
    if component == "major":
        bumped = semver.bump_major(sem_version)
    elif component == "minor":
        bumped = semver.bump_minor(sem_version)
    elif component == "patch":
        bumped = semver.bump_patch(sem_version)
    else:
        bumped = version

    return "v{}".format(bumped)
Esempio n. 30
0
def bump_tag_version(repo, current_version, selection=None):
    """Bump the tag version using semantic versioning."""
    current_version = current_version.replace("v", "")
    while True:
        if not selection:
            print '----------------------------------------\n'
            print '0: Bump major version {} -> {} \n'.format(current_version, semver.bump_major(current_version))
            print '1: Bump minor version {} -> {} \n'.format(current_version, semver.bump_minor(current_version))
            print '2: Bump patch version {} -> {} \n'.format(current_version, semver.bump_patch(current_version))
            selection = raw_input("Choose version number component to increment: ")
        if selection == "0" or selection == "major":
            return "v" + semver.bump_major(current_version)
            break
        elif selection == "1" or selection == "minor":
            return "v" + semver.bump_minor(current_version)
            break
        elif selection == "2" or selection == "patch":
            return "v" + semver.bump_patch(current_version)
            break
        else:
            print "Invalid selection. Please make a valid selection."
            selection = None
Esempio n. 31
0
def set_version_from_git_tag(project, logger):
    """ Set project version according git tags"""
    # get git info
    version_prefix = project.get_property('semver_git_tag_version_prefix')
    repo_path = _get_repo_path(project)
    tags, last_commit, repo_is_dirty = _get_repo_info(repo_path,
                                                      version_prefix)
    tag_list = []
    for tag in tags:
        tag_list.append(tag.name)
    logger.debug("All git tags: %s." % ','.join(tag_list))
    # get last tag which satisfies SemVer
    last_semver_tag = _seek_last_semver_tag(tags)
    if not last_semver_tag:
        logger.warn("No SemVer git tag found. "
                    "Consider removing plugin pybuilder_semver_git_tag.")
        return
    else:
        logger.info("Found SemVer tag: %s" % last_semver_tag.name)
    # get last commit for HEAD
    # if dirty or last commit isn't equal last tag commit
    # - increase version and add .dev
    if last_commit != last_semver_tag.commit or repo_is_dirty:
        if repo_is_dirty:
            logger.debug("Repo is marked as dirty - use dev version.")
        else:
            logger.debug("Last tag %s has commit %s, "
                         "but last commit is %s - use dev version." %
                         (last_semver_tag.name, str(
                             last_semver_tag.commit), str(last_commit)))
        increase_part = project.get_property('semver_git_tag_increment_part')
        if increase_part == 'major':
            project.version = _add_dev(semver.bump_major(last_semver_tag.name))
        elif increase_part == 'minor':
            project.version = _add_dev(semver.bump_minor(last_semver_tag.name))
        elif increase_part == 'patch':
            project.version = _add_dev(semver.bump_patch(last_semver_tag.name))
        else:
            raise BuildFailedException(
                "Incorrect value for `semver_git_tag_increment_part` property. "
                "Has to be in (`major`, `minor`, `patch`), but `%s` passed." %
                project.get_property('semver_git_tag_increment_part'))
    # if not dirty and last commit is equal last tag commit
    # - it's release tag
    else:
        project.version = last_semver_tag.name
        if project.get_property('semver_git_tag_changelog'):
            check_changelog(project.expand_path('$semver_git_tag_changelog'),
                            repo_path, last_semver_tag, tags, logger)
    logger.info("Project version was set to: %s, dist_version: %s" %
                (project.version, project.dist_version))
Esempio n. 32
0
def bump(latest):

    minor_bump_label = os.environ.get("MINOR_BUMP_LABEL") or "bump-minor"
    major_bump_label = os.environ.get("MAJOR_BUMP_LABEL") or "bump-major"

    merge_request_id = extract_merge_request_id_from_commit()
    labels = retrieve_labels_from_merge_request(merge_request_id)

    if minor_bump_label in labels:
        return semver.bump_minor(latest)
    elif major_bump_label in labels:
        return semver.bump_major(latest)
    else:
        return semver.bump_patch(latest)
Esempio n. 33
0
def postrelease(_ctx, version):
    """
    Finalise the release
    Running this task will:
     - bump the version to the next dev version
     - push changes to master
    """
    new_version = semver.bump_patch(version) + "-dev"
    info(f"Bumping version numbers to {new_version} and committing")
    set_pyversion(new_version)
    run(f"git checkout -b postrelease-{version}")
    run(f"git add {package_name()}/_version.py")
    run('git commit -m "Back to dev"')
    run(f"git push origin postrelease-{version}")
Esempio n. 34
0
 def tag(self, version, message=''):
     if version == "bump" or not version:
         old_version = self.book.meta._version
         if old_version:
             version = old_version
         else:
             version = '0.0.1'
     while version in self.book.local_repo.git.tags:
         version = semver.bump_patch(version)
     self.book.meta.metadata['_version'] = version
     self.book.save_meta()
     self.update('tag: {}. {}'.format(version, message))
     ref = self.book.local_repo.tag(version)
     self.push()
     logger.info("tagged and pushed %s" % str(ref))
Esempio n. 35
0
def postrelease(ctx, version):
    """
    Finalise the release
    Running this task will:
     - bump the version to the next dev version
     - push changes to master
    """
    new_version = semver.bump_patch(version) + "-dev"
    info(f"Bumping version numbers to {new_version} and committing")
    set_pyversion(new_version)
    set_jsversion(new_version)
    run("git add package.json package-lock.json "
        "dash_bootstrap_components/_version.py")
    run('git commit -m "Back to dev"')
    run("git push origin master")
def main():
  release_type = sys.argv[1]

  current_version = get_current_version()

  if release_type == "patch":
    release_version = semver.bump_patch(current_version)
  elif release_type == "minor":
    release_version = semver.bump_minor(current_version)
  elif release_type == "major":
    release_version = semver.bump_major(current_version)
  else:
    raise Exception("Please pick one patch/minor/major")
  
  update_version(release_version)
  sys.stdout.write(release_version)
Esempio n. 37
0
    def bump(self, major=False, minor=False, patch=False, status=None, build=None):
        # Get the current version as an instance.
        current_info = semver.parse_version_info(self.identifier)

        # Get the new version.
        if major:
            new_version = semver.bump_major(self.identifier)
        elif minor:
            new_version = semver.bump_minor(self.identifier)
        elif patch:
            new_version = semver.bump_patch(self.identifier)
        else:
            new_version = self.identifier

        # Update the status.
        if status:
            status = status
        elif current_info.prerelease:
            status = current_info.prerelease
        else:
            status = None

        if status:
            info = semver.parse_version_info(new_version)

            new_version = "%s.%s.%s-%s" % (
                info.major,
                info.minor,
                info.patch,
                status
            )

        # Update the build.
        if build:
            info = semver.parse_version_info(new_version)

            new_version = "%s.%s.%s-%s+%s" % (
                info.major,
                info.minor,
                info.patch,
                info.prerelease,
                build
            )

        # Return the new version.
        new_version = new_version.strip()
        return new_version
Esempio n. 38
0
def match(version, spec):
  if version[0] == 'v':
    version = version[1:]
  if spec[0] == '^':
    base = spec[1:]
    parsed_base = semver.parse(base)
    if parsed_base['major'] > 0:
      top = semver.bump_major(base)
    elif parsed_base['minor'] > 0:
      top = semver.bump_minor(base)
    else:
      top = semver.bump_patch(base)
    return semver.match(version, ">="+base) and semver.match(version, "<="+top)
  else:
    try:
      return semver.match(version, spec)
    except ValueError:
      # this happens when the spec isn't an expression, in which case we need an exact match
      return semver.parse(version) == semver.parse(spec)
Esempio n. 39
0
def main():
    parser = argparse.ArgumentParser(description='judge your types')
    parser.add_argument('module', metavar='MODULE', default=None,
                        help='module to import and check')
    parser.add_argument('version', nargs='?', metavar='VERSION', default=None,
                        help='current version of the package')
    parser.add_argument('-o', '--out', default=None,
                        help='save current type definitions to this file')
    parser.add_argument('-f', '--file', default=None,
                        help='load type definitions from this file')
    args = parser.parse_args()

    sys.path.append(os.getcwd())
    m = importlib.import_module(args.module)

    previous_types = None
    if args.file is not None:
        with open(args.file) as f:
            previous_types = json.load(f)

    types = represent_type_hints_module(m)

    if previous_types:
        judgement = judge(previous_types, types)
        if args.version:
            v = args.version
            if judgement == 0:
                v = semver.bump_patch(v)
            elif judgement == 1:
                v = semver.bump_minor(v)
            elif judgement == 2:
                v = semver.bump_major(v)
            print(v)
        else:
            print({0: 'patch', 1: 'minor', 2: 'major'}.get(judgement))

    if args.out:
        if args.out != '-':
            with open(args.out, 'w') as f:
                json.dump(types, f, sort_keys=True, indent=4)
        else:
            print(json.dumps(types, sort_keys=True, indent=4))
Esempio n. 40
0
def postrelease(ctx, version):
    '''
    Finalise the release

    Running this task will:
     - commit the version changes to source control
     - tag the commit
     - push changes to master
    '''
    run('git add gmaps/_version.py')
    run('git add js/package.json')
    run('git commit -m "Bump version to {}"'.format(version))
    run('git tag -a v{} -F changelog.tmp'.format(version))
    run('git push origin master --tags')
    new_version = semver.bump_patch(version) + '-dev'
    set_pyversion(new_version)
    set_jsversion(new_version)
    run('git add gmaps/_version.py')
    run('git add js/package.json')
    run('git commit -m "Back to dev"')
    run('git push origin master')
Esempio n. 41
0
parser.add_argument('-b','--bump', dest='bump', action='store',
                    choices={'major','minor','patch'}, default='patch',
                    help='defaults to %(default)s')

args = parser.parse_args()

verfile='bprc/_version.py'

if args.bump == 'major':
    newver=semver.bump_major(__version__)

if args.bump == 'minor':
    newver=semver.bump_minor(__version__)

if args.bump == 'patch':
    newver=semver.bump_patch(__version__)

# check if there are any unstaged changes. if there are, then exit
from subprocess import call, run, PIPE
result=run('expr $(git status --porcelain 2>/dev/null| egrep "^(M| M)" | wc -l)',
            shell=True, universal_newlines=True, stdout=PIPE)

if int(result.stdout) > 0:
    print("There are unstaged changes. Please fix, and re-run.")
    sys.exit(1)

print('Git status is clean. Incrementing version number in' + verfile)
print('New version is ' + newver)
newverfile = open(verfile, 'w')
newverfile.write('__version__ = "'+ newver +'"' +"\n")
newverfile.close()
Esempio n. 42
0
 def test_should_ignore_extensions_for_bump(self):
     self.assertEqual(bump_patch('3.4.5-rc1+build4'), '3.4.6')
Esempio n. 43
0
 def test_should_bump_patch(self):
     self.assertEqual(bump_patch('3.4.5'), '3.4.6')
Esempio n. 44
0
 def _version_bump_patch(value):
     return semver.bump_patch(value)
Esempio n. 45
0
def test_should_ignore_extensions_for_bump():
    assert bump_patch('3.4.5-rc1+build4') == '3.4.6'
Esempio n. 46
0
def test_should_bump_patch():
    assert bump_patch('3.4.5') == '3.4.6'
Esempio n. 47
0
# If the rpc_rc_release and rpc_release versions match,
# then we need to increment the value of rpc_release.
if rpc_rc_release == rpc_release:

    # If the current version is a prerelease version,
    # then increment the prerelease.

    if rpc_release != "master":
        rpc_release_parts = semver.parse(rpc_release_semver)
        if rpc_release_parts['prerelease'] is not None:
            rpc_release_semver_new = semver.bump_prerelease(rpc_release_semver)
        # Otherwise, this is a standard release and we
        # just need to do a patch version increment.
        else:
            rpc_release_semver_new = semver.bump_patch(rpc_release_semver)

    # Now add the 'r' prefix back on for the final version
        rpc_release = "r" + rpc_release_semver_new

if rpc_release == 'master':
    release_data['maas_release'] = 'master'
    release_data['osa_release'] = 'master'
    release_data['rpc_release'] = 'master'
else:
    # Adjust the maas release
    release_data['maas_release'] = maas_release

    # Adjust the OSA SHA
    release_data['osa_release'] = osa_release
Esempio n. 48
0
 def bump_patch(self):
     """Bump a patch version: Z from X.Y.Z
     """
     self.version = semver.bump_patch(self.version)
Esempio n. 49
0
def version_bump_patch(context, value):
    return semver.bump_patch(value)
Esempio n. 50
0
from __future__ import print_function
import semver, os

version_file = './VERSION'

with open(version_file, encoding='utf-8') as f:
    v = f.read()

v=v.strip()

nv = semver.bump_patch(v)

print('Bumping version from {} to {}...\n'.format(v, nv))
print(nv, file=open(version_file, 'w'))