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

Unified 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, 9 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | scripts/slave/recipes/infra/git_cl.expected/insane.json » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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..c1e0bc1577a846e4c268dd256f28f8189d3a238a
--- /dev/null
+++ b/scripts/slave/recipes/infra/git_cl.py
@@ -0,0 +1,176 @@
+# 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."""
+
+DEPS = [
+ 'depot_tools/bot_update',
+ 'depot_tools/gclient',
+ 'depot_tools/git',
+ 'file',
+ 'recipe_engine/path',
+ 'recipe_engine/platform',
+ '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 %USERPROFILE%\.gitcookies
+ 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':
+ if api.platform.is_win:
+ # TODO(tandrii): remove tis hardcording.
+ email = 'chrome-internal-fetch@google.com'
+ name = 'win-bot'
+ else:
+ # 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')
+ # Bootstrap git for stupid windows.
+ if api.platform.is_win:
+ api.step(
+ 'bootstrap git and python on windows for patched depot_tools',
+ [api.path['checkout'].join('bootstrap', 'win', 'win_tools.bat')],
+ infra_step=True,
+ cwd=api.path['checkout'])
+ # Make sure our checkout of depot_tools is used.
+ env = {'PATH': api.path.pathsep.join([str(api.path['checkout']), '%(PATH)s'])}
+
+ 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')
+ 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.\n\nMessage is\nlong\n')
+ git('cl', 'upload', '--squash', '-f', name='git cl upload')
+ git('config', 'branch.feature.gerritissue', stdout=api.raw_io.output())
+ issue_id = api.step.active_result.stdout.strip()
+ if not issue_id:
+ raise api.step.StepFailure('Failed to set gerrit issue id.')
+ git('config', 'branch.feature.gerritserver', stdout=api.raw_io.output())
+ gerrit_server = api.step.active_result.stdout.strip()
+
+ api.step.active_result.presentation.links['issue-%s' % issue_id] = (
+ '%s/%s' % (gerrit_server, issue_id))
+ 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)
+
+ api.file.write('hack hack 2', repo.join('patchset.data2'), 'almost-empty')
+ git('add', 'patchset.data2')
+ git('commit', '-m', 'Second commit message is not important')
+ git('cl', 'upload', '--squash', '-f', name='git cl upload')
+ git('config', 'branch.feature.gerritissue', stdout=api.raw_io.output())
+ issue_id_2 = api.step.active_result.stdout.strip()
+ if not issue_id_2:
+ raise api.step.StepFailure('Failed to set gerrit issue id on re-upload.')
+
+ git('config', 'branch.feature.gerritserver', stdout=api.raw_io.output())
+ gerrit_server_2 = api.step.active_result.stdout.strip()
+
+ if gerrit_server_2 != gerrit_server:
+ raise api.step.StepFailure(
+ 'Changed gerrit server on re-upload (%s != %s).' % (
+ gerrit_server, gerrit_server_2))
+
+ api.step.active_result.presentation.links['issue-%s' % issue_id_2] = (
+ 'https://chromium-review.googlesource.com/%s' % issue_id_2)
+ if issue_id != issue_id_2:
+ raise api.step.StepFailure('Upload of PS2 created a new issue.')
+
+ api.step('Second stage is over. SUCCESS!', cmd=None)
+ finally:
+ # Gerrit equivalent is Abandon.
+ git('cl', 'set-close', name='git cl set-close')
+
+
+def GenTests(api):
+ yield (
+ api.test('sane') +
+ api.properties.generic(
+ mastername='chromium.infra',
+ buildername='depot_tools Gerrit Git Cl',
+ revision='deadbeaf',
+ )
+ )
+ yield (
+ api.test('insane') +
+ api.platform('win', 64) +
+ api.properties.generic(
+ mastername='chromium.infra',
+ buildername='depot_tools Gerrit Git Cl',
+ revision='deadbeaf',
+ )
+ )
« 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