Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 # Copyright 2016 The Chromium Authors. All rights reserved. | |
| 2 # Use of this source code is governed by a BSD-style license that can be | |
| 3 # found in the LICENSE file. | |
| 4 """A continious builder for build repo which simulates recipes.""" | |
|
martiniss
2016/02/29 22:35:14
typo
| |
| 5 | |
| 6 DEPS = [ | |
| 7 'depot_tools/bot_update', | |
| 8 'depot_tools/gclient', | |
| 9 'depot_tools/git', | |
| 10 'file', | |
| 11 'recipe_engine/path', | |
| 12 'recipe_engine/properties', | |
| 13 'recipe_engine/python', | |
| 14 'recipe_engine/raw_io', | |
| 15 'recipe_engine/step', | |
| 16 ] | |
| 17 | |
| 18 | |
| 19 def has_commit_msg_hook(api, repo_hooks): | |
| 20 files = api.file.listdir('check hooks', repo_hooks) | |
| 21 for a in files or []: | |
| 22 if a == 'commit-msg': | |
| 23 return True | |
| 24 return False | |
| 25 | |
| 26 | |
| 27 def run_git(api, repo, env): | |
| 28 def git(*a, **kw): | |
| 29 if a and a[0] == 'cl' and '-v' not in a: | |
| 30 a = list(a) + ['-v', '-v'] | |
| 31 kw['env'] = env | |
| 32 kw['cwd'] = repo | |
| 33 return api.git(*a, **kw) | |
| 34 return git | |
| 35 | |
| 36 def set_repo_user_email(api, git): | |
| 37 step = api.python.inline('check netrc for chromium.googlesource.com', """ | |
| 38 import os, sys | |
| 39 # TODO(tandrii): Windows :( | |
| 40 netrc = os.path.expanduser('~/.netrc') | |
| 41 if os.path.exists(netrc): | |
| 42 with open(netrc, 'r') as f: | |
| 43 for l in f: | |
| 44 l = l.strip() | |
| 45 if l.startswith('#') or 'chromium.googlesource.com' not in l: | |
| 46 continue | |
| 47 login = l.split()[3] | |
| 48 assert login.startswith('git-') | |
| 49 # example: git-tandrii.chromium.org | |
| 50 user, domain = login[len('git-'):].split('.', 1) | |
| 51 print '%s@%s' % (user, domain) | |
| 52 sys.exit(0) | |
| 53 print 'NOT FOUND' | |
| 54 """, stdout=api.raw_io.output('out'), | |
| 55 step_test_data=lambda: api.raw_io.test_api.stream_output('user@chromium.or g\n', stream='stdout')) | |
| 56 email = step.stdout.strip() | |
| 57 if email == 'NOT FOUND': | |
| 58 # Assume GCE bot. | |
| 59 email = '182615506979@project.gserviceaccount.com' | |
| 60 name = 'chrome-on-gce-bot' | |
| 61 else: | |
| 62 name = email.split('@')[0] | |
| 63 git('config', '--local', 'user.email', email) | |
| 64 git('config', '--local', 'user.name', name) | |
| 65 | |
| 66 | |
| 67 def RunSteps(api): | |
| 68 api.gclient.set_config('depot_tools') | |
| 69 api.bot_update.ensure_checkout(force=True, patch_root='depot_tools') | |
| 70 # Make sure our checkout of depot_tools is used. | |
| 71 env = {'PATH': api.path.pathsep.join([str(api.path['checkout']), '%(PATH)s'])} | |
| 72 api.step('path["depot_tools"] is %s' % (api.path['depot_tools']), cmd=None) | |
| 73 | |
| 74 repo = api.path['slave_build'].join('test_repo') | |
| 75 repo_hooks = repo.join('.git', 'hooks') | |
| 76 | |
| 77 # Delete the whole repo to be absolutely sure that everything is OK. | |
| 78 # api.file.rmtree('remove repo', repo) | |
| 79 api.python.inline('remove repo workaround for http://crbug.com/589201', | |
| 80 """ | |
| 81 import shutil, sys, os | |
| 82 shutil.rmtree(sys.argv[1], ignore_errors=True) | |
| 83 """, args=[str(repo)]) | |
| 84 | |
| 85 api.git.checkout( | |
| 86 url='https://chromium.googlesource.com/playground/gerrit-cq/normal', | |
| 87 ref='master', | |
| 88 dir_path=repo) | |
| 89 git = run_git(api, repo, env) | |
| 90 | |
| 91 set_repo_user_email(api, git) | |
| 92 git('cl', '--version', name='version') | |
| 93 git('branch', '-D', 'feature', 'refs/heads/git_cl_uploads/feature', | |
| 94 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
| |
| 95 api.file.remove('remove hooks', repo_hooks.join('commit-msg'), ok_ret='any') | |
| 96 git('new-branch', 'feature') | |
| 97 api.file.write('hack hack', repo.join('patchset.data'), | |
| 98 '%s-%s-%s' % (api.properties['mastername'], | |
| 99 api.properties['buildername'], | |
| 100 api.properties['buildnumber'])) | |
| 101 git('add', 'patchset.data') | |
| 102 git('commit', '-m', 'Normal message.') | |
| 103 git('cl', 'upload', '--squash', '-f', name='git cl upload') | |
| 104 try: | |
| 105 if has_commit_msg_hook(api, repo_hooks): | |
| 106 api.step.active_result.presentation.status = api.step.FAILURE | |
| 107 raise api.step.StepFailure('commit-msg hook got installed') | |
| 108 api.step('First stage is over. SUCCESS!', cmd=None) | |
| 109 | |
| 110 finally: | |
| 111 # Gerrit equivalent is Abandon. | |
| 112 # TODO(tandrii): make sure this works for sanity of Gerrit :) | |
| 113 # git('cl', 'set-close', name='git cl set-close') | |
| 114 pass | |
| 115 | |
| 116 | |
| 117 def GenTests(api): | |
| 118 yield ( | |
| 119 api.test('normal') + | |
| 120 api.properties.generic( | |
| 121 mastername='chromium.infra', | |
| 122 buildername='depot_tools Gerrit Git Cl', | |
| 123 revision='deadbeaf', | |
| 124 ) | |
| 125 ) | |
| OLD | NEW |