blob: 6ee5ba13a7b2341a54f9345e6ebca73b317f7b3f [file] [log] [blame]
Ravi Mistryedc4f3e2017-12-08 12:58:20 -05001# Copyright 2017 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
5"""Update and upload markdown files using the output of fiddlecli."""
6
7
8import argparse
9import os
10import subprocess
11import sys
12
13import git_utils
14
15
16SKIA_COMMITTER_EMAIL = 'update-docs@skia.org'
17SKIA_COMMITTER_NAME = 'Update Docs'
18SKIA_REPO = 'https://skia.googlesource.com/skia.git'
19COMMIT_MSG = '''Update markdown files
20
21Automatic commit by the Housekeeper-Nightly-Bookmaker bot.
22
23TBR=%s
24NO_MERGE_BUILDS
25''' % SKIA_COMMITTER_EMAIL
26CC_LIST = ['rmistry@google.com', 'caryclark@google.com']
27
28
29def main():
30 parser = argparse.ArgumentParser()
31 parser.add_argument("--gitcookies")
32 parser.add_argument("--bookmaker_binary")
33 parser.add_argument("--fiddlecli_output")
34 args = parser.parse_args()
35
36 with git_utils.NewGitCheckout(repository=SKIA_REPO):
37 config_dict = {
38 'user.name': SKIA_COMMITTER_NAME,
39 'user.email': SKIA_COMMITTER_EMAIL,
40 'http.cookiefile': args.gitcookies,
41 }
42 # Skip GCE Auth in depot_tools/gerrit_utils.py. Use gitcookies instead.
43 os.environ['SKIP_GCE_AUTH_FOR_GIT'] = 'True'
44 os.environ['GIT_COOKIES_PATH'] = args.gitcookies
45
46 with git_utils.GitLocalConfig(config_dict):
47 with git_utils.GitBranch(branch_name='update_md_files',
48 commit_msg=COMMIT_MSG,
49 commit_queue=True,
50 upload=False,
51 cc_list=CC_LIST) as git_branch:
52 # Run bookmaker binary.
53 cmd = [args.bookmaker_binary,
54 '-b', 'docs',
55 '-f', args.fiddlecli_output,
56 '-r', 'site/user/api',
57 ]
58 try:
59 subprocess.check_call(cmd)
60 except subprocess.CalledProcessError as e:
61 print >> sys.stderr, (
62 'Running %s failed, not uploading markdowns update:\n\n%s' % (
63 cmd, e.output))
64 sys.exit(1)
65
66 # Verify that only files in the expected directory are going to be
67 # committed and uploaded.
68 diff_files = subprocess.check_output(['git', 'diff', '--name-only'])
69 for diff_file in diff_files.split():
70 if not diff_file.startswith('site/user/api/'):
71 print >> sys.stderr, (
72 'Some files in %s were not in the site/user/api dir. '
73 'Not uploading them' % diff_files)
74 sys.exit(1)
75 if diff_files:
76 subprocess.check_call(['git', 'add', '-u'])
Ravi Mistry4793d3b2017-12-13 16:49:43 -050077 git_branch.commit_and_upload(True)
Ravi Mistryedc4f3e2017-12-08 12:58:20 -050078 else:
79 print 'No changes so nothing to upload.'
80
81
82if '__main__' == __name__:
83 main()