Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(361)

Side by Side Diff: scripts/slave/recipes/infra/git_cl.py

Issue 1835813002: WIP: add totally reproducible git cl upload hooks. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/tools/build
Patch Set: review2 Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | scripts/slave/recipes/infra/git_cl.expected/insane.json » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(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."""
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/platform',
13 'recipe_engine/properties',
14 'recipe_engine/python',
15 'recipe_engine/raw_io',
16 'recipe_engine/step',
17 ]
18
19
20 def has_commit_msg_hook(api, repo_hooks):
21 files = api.file.listdir('check hooks', repo_hooks)
22 for a in files or []:
23 if a == 'commit-msg':
24 return True
25 return False
26
27
28 def run_git(api, repo, env):
29 def git(*a, **kw):
30 if a and a[0] == 'cl' and '-v' not in a:
31 a = list(a) + ['-v', '-v']
32 kw['env'] = env
33 kw['cwd'] = repo
34 return api.git(*a, **kw)
35 return git
36
37 def set_repo_user_email(api, git):
38 step = api.python.inline('check netrc for chromium.googlesource.com', """
39 import os, sys
40 # TODO(tandrii): Windows %USERPROFILE%\.gitcookies
41 netrc = os.path.expanduser('~/.netrc')
42 if os.path.exists(netrc):
43 with open(netrc, 'r') as f:
44 for l in f:
45 l = l.strip()
46 if l.startswith('#') or 'chromium.googlesource.com' not in l:
47 continue
48 login = l.split()[3]
49 assert login.startswith('git-')
50 # example: git-tandrii.chromium.org
51 user, domain = login[len('git-'):].split('.', 1)
52 print '%s@%s' % (user, domain)
53 sys.exit(0)
54 print 'NOT FOUND'
55 """, stdout=api.raw_io.output('out'),
56 step_test_data=lambda: api.raw_io.test_api.stream_output('user@chromium.or g\n', stream='stdout'))
57 email = step.stdout.strip()
58 if email == 'NOT FOUND':
59 if api.platform.is_win:
60 # TODO(tandrii): remove tis hardcording.
61 email = 'chrome-internal-fetch@google.com'
62 name = 'win-bot'
63 else:
64 # Assume GCE bot.
65 email = '182615506979@project.gserviceaccount.com'
66 name = 'chrome-on-gce-bot'
67 else:
68 name = email.split('@')[0]
69 git('config', '--local', 'user.email', email)
70 git('config', '--local', 'user.name', name)
71
72
73 def RunSteps(api):
74 api.gclient.set_config('depot_tools')
75 api.bot_update.ensure_checkout(force=True, patch_root='depot_tools')
76 # Bootstrap git for stupid windows.
77 if api.platform.is_win:
78 api.step(
79 'bootstrap git and python on windows for patched depot_tools',
80 [api.path['checkout'].join('bootstrap', 'win', 'win_tools.bat')],
81 infra_step=True,
82 cwd=api.path['checkout'])
83 # Make sure our checkout of depot_tools is used.
84 env = {'PATH': api.path.pathsep.join([str(api.path['checkout']), '%(PATH)s'])}
85
86 repo = api.path['slave_build'].join('test_repo')
87 repo_hooks = repo.join('.git', 'hooks')
88
89 # Delete the whole repo to be absolutely sure that everything is OK.
90 # api.file.rmtree('remove repo', repo)
91 api.python.inline('remove repo workaround for http://crbug.com/589201',
92 """
93 import shutil, sys, os
94 shutil.rmtree(sys.argv[1], ignore_errors=True)
95 """, args=[str(repo)])
96
97 api.git.checkout(
98 url='https://chromium.googlesource.com/playground/gerrit-cq/normal',
99 ref='master',
100 dir_path=repo)
101 git = run_git(api, repo, env)
102
103 set_repo_user_email(api, git)
104 git('cl', '--version', name='version')
105 git('branch', '-D', 'feature', 'refs/heads/git_cl_uploads/feature',
106 ok_ret='any', name='delete old feature branch')
107 api.file.remove('remove hooks', repo_hooks.join('commit-msg'), ok_ret='any')
108 git('new-branch', 'feature')
109 api.file.write('hack hack', repo.join('patchset.data'),
110 '%s-%s-%s' % (api.properties['mastername'],
111 api.properties['buildername'],
112 api.properties['buildnumber']))
113 git('add', 'patchset.data')
114 git('commit', '-m', 'Normal message.\n\nMessage is\nlong\n')
115 git('cl', 'upload', '--squash', '-f', name='git cl upload')
116 git('config', 'branch.feature.gerritissue', stdout=api.raw_io.output())
117 issue_id = api.step.active_result.stdout.strip()
118 if not issue_id:
119 raise api.step.StepFailure('Failed to set gerrit issue id.')
120 git('config', 'branch.feature.gerritserver', stdout=api.raw_io.output())
121 gerrit_server = api.step.active_result.stdout.strip()
122
123 api.step.active_result.presentation.links['issue-%s' % issue_id] = (
124 '%s/%s' % (gerrit_server, issue_id))
125 try:
126 if has_commit_msg_hook(api, repo_hooks):
127 api.step.active_result.presentation.status = api.step.FAILURE
128 raise api.step.StepFailure('commit-msg hook got installed')
129 api.step('First stage is over. SUCCESS!', cmd=None)
130
131 api.file.write('hack hack 2', repo.join('patchset.data2'), 'almost-empty')
132 git('add', 'patchset.data2')
133 git('commit', '-m', 'Second commit message is not important')
134 git('cl', 'upload', '--squash', '-f', name='git cl upload')
135 git('config', 'branch.feature.gerritissue', stdout=api.raw_io.output())
136 issue_id_2 = api.step.active_result.stdout.strip()
137 if not issue_id_2:
138 raise api.step.StepFailure('Failed to set gerrit issue id on re-upload.')
139
140 git('config', 'branch.feature.gerritserver', stdout=api.raw_io.output())
141 gerrit_server_2 = api.step.active_result.stdout.strip()
142
143 if gerrit_server_2 != gerrit_server:
144 raise api.step.StepFailure(
145 'Changed gerrit server on re-upload (%s != %s).' % (
146 gerrit_server, gerrit_server_2))
147
148 api.step.active_result.presentation.links['issue-%s' % issue_id_2] = (
149 'https://chromium-review.googlesource.com/%s' % issue_id_2)
150 if issue_id != issue_id_2:
151 raise api.step.StepFailure('Upload of PS2 created a new issue.')
152
153 api.step('Second stage is over. SUCCESS!', cmd=None)
154 finally:
155 # Gerrit equivalent is Abandon.
156 git('cl', 'set-close', name='git cl set-close')
157
158
159 def GenTests(api):
160 yield (
161 api.test('sane') +
162 api.properties.generic(
163 mastername='chromium.infra',
164 buildername='depot_tools Gerrit Git Cl',
165 revision='deadbeaf',
166 )
167 )
168 yield (
169 api.test('insane') +
170 api.platform('win', 64) +
171 api.properties.generic(
172 mastername='chromium.infra',
173 buildername='depot_tools Gerrit Git Cl',
174 revision='deadbeaf',
175 )
176 )
OLDNEW
« no previous file with comments | « no previous file | scripts/slave/recipes/infra/git_cl.expected/insane.json » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698