Chromium Code Reviews| Index: scripts/slave/recipes/infra/git_cl.py |
| diff --git a/scripts/slave/recipes/infra/git_cl.py b/scripts/slave/recipes/infra/git_cl.py |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..ecabf399ce23becdc5e846ed71a5f3d83f7145d1 |
| --- /dev/null |
| +++ b/scripts/slave/recipes/infra/git_cl.py |
| @@ -0,0 +1,125 @@ |
| +# Copyright 2016 The Chromium Authors. All rights reserved. |
| +# Use of this source code is governed by a BSD-style license that can be |
| +# found in the LICENSE file. |
| +"""A continious builder for build repo which simulates recipes.""" |
|
martiniss
2016/02/29 22:35:14
typo
|
| + |
| +DEPS = [ |
| + 'depot_tools/bot_update', |
| + 'depot_tools/gclient', |
| + 'depot_tools/git', |
| + 'file', |
| + 'recipe_engine/path', |
| + 'recipe_engine/properties', |
| + 'recipe_engine/python', |
| + 'recipe_engine/raw_io', |
| + 'recipe_engine/step', |
| +] |
| + |
| + |
| +def has_commit_msg_hook(api, repo_hooks): |
| + files = api.file.listdir('check hooks', repo_hooks) |
| + for a in files or []: |
| + if a == 'commit-msg': |
| + return True |
| + return False |
| + |
| + |
| +def run_git(api, repo, env): |
| + def git(*a, **kw): |
| + if a and a[0] == 'cl' and '-v' not in a: |
| + a = list(a) + ['-v', '-v'] |
| + kw['env'] = env |
| + kw['cwd'] = repo |
| + return api.git(*a, **kw) |
| + return git |
| + |
| +def set_repo_user_email(api, git): |
| + step = api.python.inline('check netrc for chromium.googlesource.com', """ |
| + import os, sys |
| + # TODO(tandrii): Windows :( |
| + netrc = os.path.expanduser('~/.netrc') |
| + if os.path.exists(netrc): |
| + with open(netrc, 'r') as f: |
| + for l in f: |
| + l = l.strip() |
| + if l.startswith('#') or 'chromium.googlesource.com' not in l: |
| + continue |
| + login = l.split()[3] |
| + assert login.startswith('git-') |
| + # example: git-tandrii.chromium.org |
| + user, domain = login[len('git-'):].split('.', 1) |
| + print '%s@%s' % (user, domain) |
| + sys.exit(0) |
| + print 'NOT FOUND' |
| + """, stdout=api.raw_io.output('out'), |
| + step_test_data=lambda: api.raw_io.test_api.stream_output('user@chromium.org\n', stream='stdout')) |
| + email = step.stdout.strip() |
| + if email == 'NOT FOUND': |
| + # Assume GCE bot. |
| + email = '182615506979@project.gserviceaccount.com' |
| + name = 'chrome-on-gce-bot' |
| + else: |
| + name = email.split('@')[0] |
| + git('config', '--local', 'user.email', email) |
| + git('config', '--local', 'user.name', name) |
| + |
| + |
| +def RunSteps(api): |
| + api.gclient.set_config('depot_tools') |
| + api.bot_update.ensure_checkout(force=True, patch_root='depot_tools') |
| + # Make sure our checkout of depot_tools is used. |
| + env = {'PATH': api.path.pathsep.join([str(api.path['checkout']), '%(PATH)s'])} |
| + api.step('path["depot_tools"] is %s' % (api.path['depot_tools']), cmd=None) |
| + |
| + repo = api.path['slave_build'].join('test_repo') |
| + repo_hooks = repo.join('.git', 'hooks') |
| + |
| + # Delete the whole repo to be absolutely sure that everything is OK. |
| + # api.file.rmtree('remove repo', repo) |
| + api.python.inline('remove repo workaround for http://crbug.com/589201', |
| + """ |
| + import shutil, sys, os |
| + shutil.rmtree(sys.argv[1], ignore_errors=True) |
| + """, args=[str(repo)]) |
| + |
| + api.git.checkout( |
| + url='https://chromium.googlesource.com/playground/gerrit-cq/normal', |
| + ref='master', |
| + dir_path=repo) |
| + git = run_git(api, repo, env) |
| + |
| + set_repo_user_email(api, git) |
| + git('cl', '--version', name='version') |
| + git('branch', '-D', 'feature', 'refs/heads/git_cl_uploads/feature', |
| + ok_ret='any', name='delete old feature branch') |
|
martiniss
2016/02/29 22:35:14
I think this should be the literal word any, not t
tandrii(chromium)
2016/03/01 09:48:48
nope, actually 'any'
https://github.com/luci/recip
|
| + api.file.remove('remove hooks', repo_hooks.join('commit-msg'), ok_ret='any') |
| + git('new-branch', 'feature') |
| + api.file.write('hack hack', repo.join('patchset.data'), |
| + '%s-%s-%s' % (api.properties['mastername'], |
| + api.properties['buildername'], |
| + api.properties['buildnumber'])) |
| + git('add', 'patchset.data') |
| + git('commit', '-m', 'Normal message.') |
| + git('cl', 'upload', '--squash', '-f', name='git cl upload') |
| + try: |
| + if has_commit_msg_hook(api, repo_hooks): |
| + api.step.active_result.presentation.status = api.step.FAILURE |
| + raise api.step.StepFailure('commit-msg hook got installed') |
| + api.step('First stage is over. SUCCESS!', cmd=None) |
| + |
| + finally: |
| + # Gerrit equivalent is Abandon. |
| + # TODO(tandrii): make sure this works for sanity of Gerrit :) |
| + # git('cl', 'set-close', name='git cl set-close') |
| + pass |
| + |
| + |
| +def GenTests(api): |
| + yield ( |
| + api.test('normal') + |
| + api.properties.generic( |
| + mastername='chromium.infra', |
| + buildername='depot_tools Gerrit Git Cl', |
| + revision='deadbeaf', |
| + ) |
| + ) |