コード例 #1
0
ファイル: test_aggregate.py プロジェクト: kylef/maintain
    def test_releasing(self):
        releasers = [
            TestReleaser('1.2.3'),
            TestReleaser('1.2.3'),
        ]

        releaser = AggregateReleaser(releasers=releasers)
        releaser.release()

        released = list(map(lambda r: r.is_released, releasers))
        self.assertEqual(released, [True, True])
コード例 #2
0
    def test_releasing(self):
        releasers = [
            MockReleaser('1.2.3'),
            MockReleaser('1.2.3'),
        ]

        releaser = AggregateReleaser(releasers=releasers)
        releaser.release(None)

        released = list(map(lambda r: r.is_released, releasers))
        self.assertEqual(released, [True, True])
コード例 #3
0
ファイル: release.py プロジェクト: finngaida/maintain
def release(version, dry_run, bump, pull_request, dependents):
    if pull_request and not cmd_exists('hub'):
        click.echo('Missing dependency for hub: https://github.com/github/hub.' +
                   ' Please install `hub` and try again.')
        exit(1)

    if os.path.exists('.maintain.yml'):
        with open('.maintain.yml') as fp:
            config = yaml.load(fp.read())
    else:
        config = {}

    releaser = AggregateReleaser()

    if not version and bump:
        raise MissingParameter(param_hint='version', param_type='argument')
    elif version in ('major', 'minor', 'patch'):
        if bump:
            version = bump_version(releaser.determine_current_version(), version)
        else:
            releaser.determine_current_version()
    else:
        try:
            version = Version(version)
        except ValueError as e:
            raise click.BadParameter('{} is not a semantic version'.format(version))

    if not bump:
        current_version = releaser.determine_current_version()
        if current_version != version:
            click.echo('--no-bump was used, however the supplied version ' +
                       'is not equal to current version {} != {}'.format(current_version, version))
            exit(1)

    git_check_repository()
    git_check_branch()
    git_update()
    git_check_dirty()

    if bump:
        branch = 'master'
        if pull_request:
            branch = 'release-{}'.format(version)
            invoke(['git', 'checkout', '-b', branch])

        execute_hooks('bump', 'pre', config)

        releaser.bump(version)
        click.echo('Committing and tagging {}'.format(version))
        message = 'Release {}'.format(version)
        invoke(['git', 'commit', '-a', '-m', message])

        execute_hooks('bump', 'post', config)

        if not dry_run:
            invoke(['git', 'push', 'origin', branch])
            if pull_request:
                invoke(['hub', 'pull-request', '-m', message])

    if not dry_run and not pull_request:
        execute_hooks('publish', 'pre', config)

        invoke(['git', 'tag', '-a', str(version), '-m', 'Release {}'.format(version)])
        invoke(['git', 'push', 'origin', str(version)])

        releaser.release()

        execute_hooks('publish', 'post', config)

    if dependents and not pull_request and 'dependents' in config:
        # TODO dry run
        url = subprocess.check_output('git config --get remote.origin.url', shell=True).strip()
        map(lambda x: update_dependent(x, version, url), config['dependents'])
コード例 #4
0
ファイル: release.py プロジェクト: kylef/maintain
def release(config, version, dry_run, bump, pull_request, verbose):
    formatter = logging.Formatter('[%(levelname)s] %(message)s')
    handler = logging.StreamHandler(stream=sys.stdout)
    handler.setFormatter(formatter)
    logger.addHandler(handler)

    if verbose:
        logger.setLevel(logging.DEBUG)

    releaser = AggregateReleaser(config.release)

    git_releasers = filter(lambda releaser: isinstance(releaser, GitReleaser), releaser.releasers)
    github_releasers = filter(lambda releaser: isinstance(releaser, GitHubReleaser), releaser.releasers)

    try:
        git_releaser = next(git_releasers)
    except StopIteration:
        git_releaser = None
    except TypeError:
        if len(git_releasers) > 0:
            git_releaser = git_releasers[0]
        else:
            git_releaser = None

    try:
        github_releaser = next(github_releasers)
    except StopIteration:
        github_releaser = None
    except TypeError:
        if len(github_releasers) > 0:
            github_releaser = github_releasers[0]
        else:
            github_releaser = None

    if pull_request and not github_releaser:
        raise Exception('Used --pull-request and no GitHub remote')

    if not version:
        if bump:
            raise MissingParameter(param_hint='version', param_type='argument')

        version = releaser.determine_current_version()

    if version == 'semver':
        version = releaser.determine_next_version()
        if not version:
            raise Exception('Could not determine the next semantic version.')
    elif version in ('major', 'minor', 'patch'):
        if bump:
            version = bump_version(releaser.determine_current_version(), version)
        else:
            releaser.determine_current_version()
    elif not isinstance(version, Version):
        try:
            version = Version(version)
        except ValueError:
            raise click.BadParameter('{} is not a semantic version'.format(version))

    if not bump:
        current_version = releaser.determine_current_version()
        if current_version != version:
            click.echo('--no-bump was used, however the supplied version ' +
                       'is not equal to current version {} != {}'.format(current_version, version))
            exit(1)

    if bump:
        logger.info('Bumping {}'.format(version))

        ref = git_releaser.repo.refs.master
        if pull_request:
            branch = 'release-{}'.format(version)
            ref = git_releaser.repo.create_head(branch, git_releaser.repo.head)
            git_releaser.repo.head.set_reference(ref)

        releaser.bump(version)

        if not dry_run:
            if git_releaser.has_origin():
                git_releaser.repo.remotes.origin.push(ref)

            if pull_request:
                github_releaser.create_pull_request(version)

    if not dry_run and not pull_request:
        logger.info('Releasing {}'.format(version))
        releaser.release(version)