Exemplo n.º 1
0
def increment_version_for_artifact(build_type, artifact_id):

    if not build_type:
        raise ValueError('build_type cannot be empty.')

    if not artifact_id:
        raise ValueError('artifact_id cannot be empty.')

    version_file = os.path.normpath('eng/versioning/version_' +
                                    build_type.name + '.txt')
    print('version_file=' + version_file)

    artifact_found = False
    newlines = []
    with open(version_file, encoding='utf-8') as f:
        for raw_line in f:
            stripped_line = raw_line.strip()
            if not stripped_line or stripped_line.startswith('#'):
                newlines.append(raw_line)
            else:
                module = CodeModule(stripped_line)
                # Tick up the version here. If the version is already a pre-release
                # version then just increment the revision. Otherwise increment the
                # minor version, zero the patch and add "-beta.1" to the end
                # https://github.com/Azure/azure-sdk/blob/master/docs/policies/releases.md#java
                if module.artifact_id == artifact_id and hasattr(
                        module, 'current'):
                    artifact_found = True
                    vmatch = version_regex_named.match(module.current)
                    if (vmatch.group('prerelease') is not None):
                        prever = prerelease_regex_named.match(
                            vmatch.group('prerelease'))
                        rev = int(prever.group('revision'))
                        rev += 1
                        new_version = '{}.{}.{}-beta.{}'.format(
                            vmatch.group('major'), vmatch.group('minor'),
                            vmatch.group('patch'), str(rev))
                    else:
                        minor = int(vmatch.group('minor'))
                        minor += 1
                        new_version = '{}.{}.{}-beta.1'.format(
                            vmatch.group('major'), minor, 0)
                    print(
                        'artifact_id {}, previous version={}, new current version={}'
                        .format(artifact_id, module.current, new_version))
                    module.current = new_version
                newlines.append(module.string_for_version_file())

    if not artifact_found:
        raise ValueError(
            'artifact_id ({}) was not found in version file {}'.format(
                artifact_id, version_file))

    with open(version_file, 'w', encoding='utf-8') as f:
        for line in newlines:
            f.write(line)
def set_dev_zero_version(build_type, build_qualifier):
    version_file = os.path.normpath('eng/versioning/version_' + build_type.name + '.txt')
    print('version_file=' + version_file)

    # Assuming a build qualifier of the form: "dev.20200204.123"
    # Converts "dev.20200204.123" -> "dev.20200204.0"
    zero_qualifier = build_qualifier[:build_qualifier.rfind('.') + 1] + '0'

    newlines = []
    with open(version_file, encoding='utf8') as f:
        for raw_line in f:
            stripped_line = raw_line.strip()

            if not stripped_line or stripped_line.startswith('#'):
                newlines.append(raw_line)
                continue

            module = CodeModule(stripped_line)

            if module.name in items_we_should_not_update:
                newlines.append(module.string_for_version_file())
                continue

            if module.name.startswith('unreleased_') or module.name.startswith('beta_'):
                newlines.append(module.string_for_version_file())
                continue

            if hasattr(module, 'current'):

                if 'dev' in module.current:
                    newlines.append(module.string_for_version_file())
                    continue

                set_both = module.current == module.dependency

                if '-' in module.current:
                    # if the module is 1.2.3-beta.x, strip off everything after the '-' and add the qualifier
                    module.current = module.current[:module.current.rfind('-') + 1] + zero_qualifier
                else:
                    # if the module is a GA version 1.2.3, add '-' and the qualifier
                    module.current += '-' + zero_qualifier
                # The resulting version must be a valid SemVer
                match = version_regex_named.match(module.current)
                if not match:
                    raise ValueError('{}\'s current version + build qualifier {} is not a valid semver version'.format(module.name, module.current + build_qualifier))

                if set_both:
                    module.dependency = module.current

                print(f'updating {module.name} to use dependency={module.dependency}, current={module.current}')
                newlines.append(module.string_for_version_file())

    with open(version_file, 'w', encoding='utf-8') as f:
        for line in newlines:
            f.write(line)
Exemplo n.º 3
0
def increment_library_version(build_type, artifact_id, group_id):

    version_file = os.path.normpath('eng/versioning/version_' + build_type.name + '.txt')
    print('version_file=' + version_file)
    library_to_update = group_id + ':' + artifact_id

    artifact_found = False
    newlines = []
    with open(version_file, encoding='utf-8') as f:
        for raw_line in f:
            stripped_line = raw_line.strip()
            if not stripped_line or stripped_line.startswith('#'):
                newlines.append(raw_line)
            else:
                module = CodeModule(stripped_line)
                # Tick up the version here. If the version is already a pre-release
                # version then just increment the revision. Otherwise increment the
                # minor version, zero the patch and add "-beta.1" to the end
                # https://github.com/Azure/azure-sdk/blob/master/docs/policies/releases.md#java
                if module.name == library_to_update and hasattr(module, 'current'):
                    artifact_found = True
                    vmatch = version_regex_named.match(module.current)
                    if (vmatch.group('prerelease') is not None):
                        prever = prerelease_regex_named.match(vmatch.group('prerelease'))
                        # This is the case where, somehow, the versioning verification has failed and
                        # the prerelease verification doesn't match "beta.X"
                        if prever is None:
                            raise ValueError('library_to_update ({}:{}) has an invalid prerelease version ({}) which should be of the format beta.X'.format(library_to_update, module.current, vmatch.group('prerelease')))
                        rev = int(prever.group('revision'))
                        rev += 1
                        new_version = '{}.{}.{}-beta.{}'.format(vmatch.group('major'), vmatch.group('minor'), vmatch.group('patch'), str(rev))
                    else:
                        minor = int(vmatch.group('minor'))
                        minor += 1
                        new_version = '{}.{}.{}-beta.1'.format(vmatch.group('major'), minor, 0)
                    # The dependency version only needs to be updated it if is different from the current version. 
                    # This would be the case where a library hasn't been released yet and has been released (either GA or preview)
                    if (module.dependency != module.current):
                        print('library_to_update {}, previous dependency version={}, new dependency version={}'.format(library_to_update, module.dependency, module.current))
                        module.dependency = module.current
                    print('library_to_update {}, previous version={}, new current version={}'.format(library_to_update, module.current, new_version))
                    module.current = new_version
                newlines.append(module.string_for_version_file())

    if not artifact_found:
       raise ValueError('library_to_update ({}) was not found in version file {}'.format(library_to_update, version_file))

    with open(version_file, 'w', encoding='utf-8') as f:
        for line in newlines:
            f.write(line)
def update_versions_file_for_nightly_devops(build_type, build_qualifier, artifact_id, group_id):

    version_file = os.path.normpath('eng/versioning/version_' + build_type.name + '.txt')
    print('version_file=' + version_file)
    library_to_update = group_id + ':' + artifact_id
    print('adding build_qualifier({}) to {}'.format(build_qualifier, library_to_update))
    version_map = {}
    newlines = []
    artifact_found = False
    with open(version_file, encoding='utf-8') as f:
        for raw_line in f:
            stripped_line = raw_line.strip()
            if not stripped_line or stripped_line.startswith('#'):
                newlines.append(raw_line)
            else:
                module = CodeModule(stripped_line)
                # basically we don't want to change any of the parent versions here, only
                # library versions
                if module.name in items_we_should_not_update:
                    newlines.append(module.string_for_version_file())
                    continue
                if library_to_update == module.name:
                    artifact_found = True
                    if hasattr(module, 'current'):
                        set_both = False
                        # In the case where the current and dependency are both equal then both
                        # need to be updated. In theory, this should only really happen when a
                        # new library has been added and has not yet been released but can also
                        # happen if a library has just been released and the devops build kicks
                        # of before the human submits the PR to increase the current version. Being
                        # that it's a devops build and both versions are being updated this should
                        # be OK.
                        if module.current == module.dependency:
                            set_both = True
                        if '-' in module.current:
                            # if the module is 1.2.3-beta.x, strip off everything after the '-' and add the qualifier
                            module.current = module.current[:module.current.rfind('-') + 1] + build_qualifier
                        else:
                            module.current += '-' + build_qualifier
                        match = version_regex_named.match(module.current)
                        if not match:
                            raise ValueError('{}\'s current version + build qualifier {} is not a valid semver version'.format(module.name, module.current + build_qualifier))
                        if set_both:
                            module.dependency = module.current

                # If the library is not the update target and is unreleased, use
                # a version range based on the build qualifier as the dependency
                # version so that packages from this build that are released to
                # the dev feed will depend on a version that should be found in
                # the dev feed.
                # This script runs once for each artifact so it makes no
                # changes in the case where a dependency version has already
                # been modified.
                elif (module.name.startswith('unreleased_') or module.name.startswith('beta_'))  and not module.dependency.startswith('['):
                    # Assuming a build qualifier of the form: "dev.20200204.1"
                    # Converts "dev.20200204.1" -> "dev.20200204."
                    unreleased_build_qualifier = build_qualifier[:build_qualifier.rfind('.') + 1]

                    if '-' in module.dependency:
                        # if the module is 1.2.3-beta.x, strip off everything after the '-' and add the qualifier
                        module.dependency = module.dependency[:module.dependency.rfind('-') + 1] + unreleased_build_qualifier
                    else:
                        module.dependency += '-' + unreleased_build_qualifier

                    print(f'updating unreleased/beta dependency {module.name} to use dependency version range: "{module.dependency}"')

                version_map[module.name] = module
                newlines.append(module.string_for_version_file())

    if not artifact_found:
       raise ValueError('library_to_update ({}) was not found in version file {}'.format(library_to_update, version_file))

    with open(version_file, 'w', encoding='utf-8') as f:
        for line in newlines:
            f.write(line)