def clone_repository(url, branch=None, target_dir=None, quiet=False): args = ['clone', '--depth', '1'] if quiet: args.append('--quiet') if branch: args.extend(['--branch', branch]) args.append(url) if target_dir: args.append(target_dir) git(*args)
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 get_version(): 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 format_version(version): version_parts = version.split('.') version_parts[2] = f'{version_patch_prefix}{version_parts[2]}' return '.'.join(version_parts) tags = git('tag').split('\n') pattern = rf'^(\d+.){{2}}{version_patch_prefix}\d+$' sorted_versions = sorted( [ x.replace(f'{version_patch_prefix}', '') for x in tags if re.match(pattern, x) ], key=LooseVersion, reverse=True, ) if len(sorted_versions) > 0: new_version = bump(sorted_versions[0]) else: # No tags in the repository new_version = DFLT_NEW_VERSION return format_version(new_version)
def check_in(commit_message='No commit message.'): current_changes = git('status', '--porcelain=v1') if current_changes: branch = os.environ['CI_COMMIT_REF_NAME'] git('add', '-A') git('commit', '-m', f'**CI** {commit_message} [skip ci]') git('push', 'origin', f'HEAD:{branch}') else: print('Nothing to commit.')
def tag_repo(tag: str, git_dir: str = None): if git_dir: os.chdir(git_dir) git('tag', tag) git('push', 'origin', tag)