Beispiel #1
0
def update_prod_branch(repo, repo_dir, hash_to_rebase):
    """Method to update the prod branch of the given repo to the given hash.

    @param repo: Name of the git repo to be updated.
    @param repo_dir: path to the cloned repo.
    @param hash_to_rebase: Hash to rebase the prod branch to. If it is None,
                           prod branch will rebase to prod-next branch.

    @returns the range of the pushed commits as a string. E.g 123...345
    @raises subprocess.CalledProcessError on a command failure.
    """
    with infra.chdir(repo_dir):
        print 'Updating %s prod branch.' % repo
        rebase_to = hash_to_rebase if hash_to_rebase else 'origin/prod-next'
        infra.local_runner('git rebase %s prod' % rebase_to,
                           stream_output=True)
        result = infra.local_runner('git push origin prod', stream_output=True)
        print 'Successfully pushed %s prod branch!\n' % repo

        # Get the pushed commit range, which is used to get the pushed commits
        # using git log E.g. 123..456, then run git log --oneline 123..456.
        grep = re.search('(\w)*\.\.(\w)*', result)

    if not grep:
        raise AutoDeployException(
            'Fail to get pushed commits for repo %s from git push log: %s' %
            (repo, result))
    return grep.group(0)
Beispiel #2
0
def kick_off_deploy():
    """Method to kick off deploy script to deploy changes to lab servers.

    @raises subprocess.CalledProcessError on a repo command failure.
    """
    print 'Start deploying changes to all lab servers...'
    with infra.chdir(AUTOTEST_DIR):
        # Then kick off the deploy script.
        deploy_cmd = ('runlocalssh ./site_utils/deploy_server.py --afe=%s' %
                      MASTER_AFE)
        infra.local_runner(deploy_cmd, stream_output=True)
        print 'Successfully deploy changes to all lab servers.!'
def get_pushed_commits(repo, repo_dir, pushed_commits_range):
    """Method to get the pushed commits.

    @param repo: Name of the updated git repo.
    @param repo_dir: path to the cloned repo.
    @param pushed_commits_range: The range of the pushed commits. E.g 123...345
    @return: the commits that are pushed to prod branch. The format likes this:
             "git log --oneline A...B | grep autotest
              A xxxx
              B xxxx"
    @raises subprocess.CalledProcessError on a command failure.
    """
    print 'Getting pushed CLs for %s repo.' % repo
    if not pushed_commits_range:
        return '\n%s:\nNo new changes since last push.' % repo

    with infra.chdir(repo_dir):
        get_commits_cmd = 'git log --oneline %s' % pushed_commits_range

        pushed_commits = infra.local_runner(
                get_commits_cmd, stream_output=True)
        if repo == 'autotest':
            autotest_commits = ''
            for cl in pushed_commits.splitlines():
                if 'autotest' in cl:
                    autotest_commits += '%s\n' % cl

            pushed_commits = autotest_commits

        print 'Successfully got pushed CLs for %s repo!\n' % repo
        displayed_cmd = get_commits_cmd
        if repo == 'autotest':
          displayed_cmd += ' | grep autotest'
        return '\n%s:\n%s\n%s\n' % (repo, displayed_cmd, pushed_commits)
Beispiel #4
0
def clone_prod_branch(repo):
    """Method to clone the prod branch for a given repo under /tmp/ dir.

    @param repo: Name of the git repo to be cloned.

    @returns path to the cloned repo.
    @raises subprocess.CalledProcessError on a command failure.
    @raised revision_control.GitCloneError when git clone fails.
    """
    repo_dir = '/tmp/%s' % repo
    print 'Cloning %s prod branch under %s' % (repo, repo_dir)
    if os.path.exists(repo_dir):
        infra.local_runner('rm -rf %s' % repo_dir)
    git_repo = revision_control.GitRepo(repo_dir, GIT_URL[repo])
    git_repo.clone(remote_branch=PROD_BRANCH)
    print 'Successfully cloned %s prod branch' % repo
    return repo_dir