コード例 #1
0
    def test_commit(self):
        """Create NewGitCheckout with a specific commit.

    This test depends on the fact that the whitespace.txt file was added to the
    repo in a particular commit.
    See https://skia.googlesource.com/common/+/c2200447734f13070fb3b2808dea58847241ab0e
    ('Initial commit of whitespace.txt')
    """
        filename = 'whitespace.txt'
        hash_without_file = 'f63e1cfff23615157e28942af5f5e8298351cb10'
        hash_with_file = 'c2200447734f13070fb3b2808dea58847241ab0e'

        with git_utils.NewGitCheckout(repository=LOCAL_REPO,
                                      commit=hash_without_file) as checkout:
            filepath = os.path.join(checkout.root, filename)
            self.assertEquals(
                hash_without_file, checkout.commithash(),
                '"%s" != "%s"' % (hash_without_file, checkout.commithash()))
            self.assertFalse(os.path.exists(filepath),
                             'file %s should not exist' % filepath)

        with git_utils.NewGitCheckout(repository=LOCAL_REPO,
                                      commit=hash_with_file) as checkout:
            filepath = os.path.join(checkout.root, filename)
            self.assertEquals(
                hash_with_file, checkout.commithash(),
                '"%s" != "%s"' % (hash_with_file, checkout.commithash()))
            self.assertTrue(os.path.exists(filepath),
                            'file %s should exist' % filepath)
コード例 #2
0
def _add_cl_comment(issue, comment):
  # Depot tools needs a checkout to use "git cl" even though we are just adding
  # a comment to a change unrelated to the checkout.
  # TODO(rmistry): Try using the Gerrit API?
  with git_utils.NewGitCheckout(repository=utils.SKIA_REPO):
    add_comment_cmd = ['git', 'cl', 'comments', '-i', str(issue), '-a', comment]
    subprocess.check_call(add_comment_cmd)
コード例 #3
0
def create_new_branch(new_branch, branch_at):
    '''Create a temporary checkout of the repo, create the new branch and push.'''
    b = new_branch[len(REFS_HEADS_PREFIX):]
    with git_utils.NewGitCheckout(SKIA_REPO, local=_REPO_ROOT):
        git.git('checkout', '-b', b)
        git.git('reset', '--hard', branch_at)
        git.git('push', '--set-upstream', 'origin', b)
コード例 #4
0
def main(target_dir, gitcookies):
    with git_utils.NewGitCheckout(repository=SKIA_REPO):
        # First verify that there are no gen_tasks diffs.
        gen_tasks = os.path.join(os.getcwd(), 'infra', 'bots', 'gen_tasks.go')
        try:
            subprocess.check_call(['go', 'run', gen_tasks, '--test'])
        except subprocess.CalledProcessError as e:
            print >> sys.stderr, (
                'gen_tasks.go failed, not uploading SKP update:\n\n%s' %
                e.output)
            sys.exit(1)

        # Skip GCE Auth in depot_tools/gerrit_utils.py. Use gitcookies instead.
        os.environ['SKIP_GCE_AUTH_FOR_GIT'] = 'True'
        os.environ['GIT_COOKIES_PATH'] = gitcookies
        os.environ['USE_CIPD_GCE_AUTH'] = 'True'
        # Upload the new version, land the update CL as the update-skps user.
        config_dict = {
            'user.name': SKIA_COMMITTER_NAME,
            'user.email': SKIA_COMMITTER_EMAIL,
            'http.cookiefile': gitcookies,
        }
        with git_utils.GitLocalConfig(config_dict):
            with git_utils.GitBranch(branch_name='update_skp_version',
                                     commit_msg=COMMIT_MSG,
                                     commit_queue=True):
                upload_script = os.path.join(os.getcwd(), 'infra', 'bots',
                                             'assets', 'skp', 'upload.py')
                subprocess.check_call(
                    ['python', upload_script, '-t', target_dir])
                subprocess.check_call(['go', 'run', gen_tasks])
                subprocess.check_call([
                    'git', 'add',
                    os.path.join('infra', 'bots', 'tasks.json')
                ])
コード例 #5
0
 def test_defaults(self):
     """Test NewGitCheckout created using default parameters."""
     with git_utils.NewGitCheckout(repository=LOCAL_REPO) as checkout:
         filepath = os.path.join(checkout.root, REPO_FILE)
         self.assertTrue(os.path.exists(filepath),
                         'file %s should exist' % filepath)
     # Confirm that NewGitCheckout cleaned up after itself.
     self.assertFalse(os.path.exists(filepath),
                      'file %s should not exist' % filepath)
コード例 #6
0
def main():
    parser = argparse.ArgumentParser()
    parser.add_argument("--gitcookies")
    parser.add_argument("--bookmaker_binary")
    parser.add_argument("--fiddlecli_output")
    args = parser.parse_args()

    with git_utils.NewGitCheckout(repository=SKIA_REPO):
        config_dict = {
            'user.name': SKIA_COMMITTER_NAME,
            'user.email': SKIA_COMMITTER_EMAIL,
            'http.cookiefile': args.gitcookies,
        }
        # Skip GCE Auth in depot_tools/gerrit_utils.py. Use gitcookies instead.
        os.environ['SKIP_GCE_AUTH_FOR_GIT'] = 'True'
        os.environ['GIT_COOKIES_PATH'] = args.gitcookies

        with git_utils.GitLocalConfig(config_dict):
            with git_utils.GitBranch(branch_name='update_md_files',
                                     commit_msg=COMMIT_MSG,
                                     commit_queue=True,
                                     upload=False,
                                     cc_list=CC_LIST) as git_branch:
                # Run bookmaker binary.
                cmd = [
                    args.bookmaker_binary,
                    '-b',
                    'docs',
                    '-f',
                    args.fiddlecli_output,
                    '-r',
                    'site/user/api',
                ]
                try:
                    subprocess.check_call(cmd)
                except subprocess.CalledProcessError as e:
                    print >> sys.stderr, (
                        'Running %s failed, not uploading markdowns update:\n\n%s'
                        % (cmd, e.output))
                    sys.exit(1)

                    # Verify that only files in the expected directory are going to be
                    # committed and uploaded.
                diff_files = subprocess.check_output(
                    ['git', 'diff', '--name-only'])
                for diff_file in diff_files.split():
                    if not diff_file.startswith('site/user/api/'):
                        print >> sys.stderr, (
                            'Some files in %s were not in the site/user/api dir. '
                            'Not uploading them' % diff_files)
                        sys.exit(1)
                if diff_files:
                    subprocess.check_call(['git', 'add', '-u'])
                    git_branch.commit_and_upload(False)
                else:
                    print 'No changes so nothing to upload.'
コード例 #7
0
    def test_remote(self):
        """Test NewGitCheckout with a remote repo.

    This makes requests across the network, so we may not want to run it
    very often...
    """
        with git_utils.NewGitCheckout(repository=REMOTE_REPO) as checkout:
            filepath = os.path.join(checkout.root, REPO_FILE)
            self.assertTrue(os.path.exists(filepath),
                            'file %s should exist' % filepath)
コード例 #8
0
def main():
    parser = argparse.ArgumentParser()
    parser.add_argument("--gitcookies")
    parser.add_argument("--repo_name")
    parser.add_argument("--tasks_json")
    args = parser.parse_args()

    skia_repo = SKIA_REPO_TEMPLATE % args.repo_name
    with git_utils.NewGitCheckout(repository=skia_repo):
        # Fetch and checkout the meta/config branch.
        subprocess.check_call(
            ['git', 'fetch', skia_repo, 'refs/meta/config:cfg'])
        subprocess.check_call(['git', 'checkout', 'cfg'])

        # Create list of tryjobs from tasks_json.
        tryjobs = []
        with open(args.tasks_json) as tasks_json:
            data = json.load(tasks_json)
            for job in data['jobs'].keys():
                if not job.startswith('Upload-'):
                    tryjobs.append(job)
        tryjobs.sort()

        # Write to buildbucket.config.
        buildbucket_config = os.path.join(os.getcwd(), 'buildbucket.config')
        with open(buildbucket_config, 'w') as f:

            if args.repo_name == 'skia':
                addChromiumTrybots(f)

            # Adding all Skia jobs.
            f.write('[bucket "skia.primary"]\n')
            for job in tryjobs:
                f.write('\tbuilder = ' + job + '\n')

        # Push the change as the update-meta-config user.
        config_dict = {
            'user.name': SKIA_COMMITTER_NAME,
            'user.email': SKIA_COMMITTER_EMAIL,
            'http.cookiefile': args.gitcookies,
        }
        with git_utils.GitLocalConfig(config_dict):
            subprocess.check_call(['git', 'add', 'buildbucket.config'])
            try:
                subprocess.check_call([
                    'git', 'commit', '-m',
                    'Update builders in buildbucket.config'
                ])
            except subprocess.CalledProcessError:
                print 'No changes to buildbucket.config'
                return

            subprocess.check_call(
                ['git', 'push', skia_repo, 'cfg:refs/meta/config'])
コード例 #9
0
def update_milestone(m):
  '''Update SkMilestone.h to match the given milestone number.'''
  with git_utils.NewGitCheckout(SKIA_REPO, local=_REPO_ROOT):
    with git_utils.GitBranch(
        'update_milestone', UPDATE_MILESTONE_COMMIT_MSG % m):
      with open(SK_MILESTONE_H, 'r+') as f:
        contents = re.sub(
            SK_MILESTONE_RE, SK_MILESTONE_TMPL % str(m), f.read(), flags=re.M)
        f.seek(0)
        f.write(contents)
        f.truncate()
      git.git('diff')
コード例 #10
0
def main():
    parser = argparse.ArgumentParser()
    parser.add_argument("--bookmaker_binary")
    parser.add_argument("--fiddlecli_output")
    args = parser.parse_args()

    with git_utils.NewGitCheckout(repository=SKIA_REPO):
        with git_utils.GitBranch(branch_name='update_md_files',
                                 commit_msg=COMMIT_MSG,
                                 commit_queue=False,
                                 upload=False,
                                 cc_list=CC_LIST) as git_branch:
            # Run bookmaker binary.
            cmd = [
                args.bookmaker_binary,
                '-b',
                'docs',
                '-f',
                args.fiddlecli_output,
                '-r',
                'site/user/api',
            ]
            try:
                subprocess.check_call(cmd)
            except subprocess.CalledProcessError as e:
                print >> sys.stderr, (
                    'Running %s failed, not uploading markdowns update:\n\n%s'
                    % (cmd, e.output))
                sys.exit(1)

            # Verify that only files in the expected directory are going to be
            # committed and uploaded.
            diff_files = subprocess.check_output(
                ['git', 'diff', '--name-only'])
            for diff_file in diff_files.split():
                if not diff_file.startswith('site/user/api/'):
                    print >> sys.stderr, (
                        'Some files in %s were not in the site/user/api dir. '
                        'Not uploading them' % diff_files)
                    sys.exit(1)
            if diff_files:
                subprocess.check_call(['git', 'add', '-u'])
                git_branch.commit_and_upload(False)
            else:
                print 'No changes so nothing to upload.'
コード例 #11
0
def main(target_dir):
    # We're going to sync a new, clean Skia checkout to upload the CL to update
    # the SKPs. However, we want to use the scripts from the current checkout,
    # in order to facilitate running this as a try job.
    infrabots_dir = os.path.dirname(os.path.realpath(__file__))
    skp_dir = os.path.join(infrabots_dir, 'assets', 'skp')
    upload_py = os.path.join(skp_dir, 'upload.py')

    with git_utils.NewGitCheckout(repository=utils.SKIA_REPO):
        # First verify that there are no gen_tasks diffs.
        tmp_infrabots_dir = os.path.join(os.getcwd(), 'infra', 'bots')
        tmp_gen_tasks = os.path.join(tmp_infrabots_dir, 'gen_tasks.go')
        try:
            subprocess.check_call(['go', 'run', tmp_gen_tasks, '--test'])
        except subprocess.CalledProcessError as e:
            print >> sys.stderr, (
                'gen_tasks.go failed, not uploading SKP update:\n\n%s' %
                e.output)
            sys.exit(1)

        # Upload the new version, land the update CL as the recreate-skps user.
        with git_utils.GitBranch(branch_name='update_skp_version',
                                 commit_msg=COMMIT_MSG,
                                 commit_queue=True):
            upload_cmd = ['python', upload_py, '-t', target_dir]
            if args.chromium_path:
                chromium_revision = subprocess.check_output(
                    ['git', 'rev-parse', 'HEAD'],
                    cwd=args.chromium_path).rstrip()
                upload_cmd.extend([
                    '--extra_tags',
                    'chromium_revision:%s' % chromium_revision
                ])
            subprocess.check_call(upload_cmd)
            # We used upload.py from the repo that this script lives in, NOT the temp
            # repo we've created. Therefore, the VERSION file was written in that repo
            # so we need to copy it to the temp repo in order to commit it.
            src = os.path.join(skp_dir, 'VERSION')
            dst = os.path.join(os.getcwd(), 'infra', 'bots', 'assets', 'skp',
                               'VERSION')
            subprocess.check_call(['cp', src, dst])
            subprocess.check_call(['go', 'run', tmp_gen_tasks])
            subprocess.check_call(
                ['git', 'add',
                 os.path.join('infra', 'bots', 'tasks.json')])
コード例 #12
0
    def test_subdir(self):
        """Create NewGitCheckout with a specific subdirectory."""
        subdir = os.path.dirname(REPO_FILE)
        file_within_subdir = os.path.basename(REPO_FILE)

        containing_dir = tempfile.mkdtemp()
        try:
            with git_utils.NewGitCheckout(
                    repository=LOCAL_REPO,
                    subdir=subdir,
                    containing_dir=containing_dir) as checkout:
                self.assertTrue(
                    checkout.root.startswith(containing_dir),
                    'checkout.root %s should be within %s' %
                    (checkout.root, containing_dir))
                filepath = os.path.join(checkout.root, file_within_subdir)
                self.assertTrue(os.path.exists(filepath),
                                'file %s should exist' % filepath)
        finally:
            os.rmdir(containing_dir)
コード例 #13
0
def main():
  with git_utils.NewGitCheckout(repository=SKIA_REPO):
    # First verify that there are no gen_tasks diffs.
    gen_tasks = os.path.join(os.getcwd(), 'infra', 'bots', 'gen_tasks.go')
    try:
      subprocess.check_call(['go', 'run', gen_tasks, '--test'])
    except subprocess.CalledProcessError as e:
      print >> sys.stderr, (
         'gen_tasks.go failed, not updating Go DEPS:\n\n%s' % e.output)
      sys.exit(1)

    # Upload the new version, land the update CL as the update-go-deps user.
    with git_utils.GitBranch(branch_name='update_go_deps_version',
                             commit_msg=COMMIT_MSG,
                             commit_queue=True):
      script = os.path.join(
          os.getcwd(), 'infra', 'bots', 'assets', 'go_deps',
          'create_and_upload.py')
      subprocess.check_call(['python', script])
      subprocess.check_call(['go', 'run', gen_tasks])
      subprocess.check_call([
          'git', 'add', os.path.join('infra', 'bots', 'tasks.json')])