blob: 3d5c3773ec29c5770f27aa785169b2e9a8464764 [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
Ravi Mistryedc4f3e2017-12-08 12:58:20 -050016SKIA_REPO = 'https://skia.googlesource.com/skia.git'
17COMMIT_MSG = '''Update markdown files
18
19Automatic commit by the Housekeeper-Nightly-Bookmaker bot.
20
Eric Boren78179312018-04-23 08:35:45 -040021TBR=rmistry@google.com
Ravi Mistryedc4f3e2017-12-08 12:58:20 -050022NO_MERGE_BUILDS
Eric Boren78179312018-04-23 08:35:45 -040023'''
Ravi Mistryedc4f3e2017-12-08 12:58:20 -050024CC_LIST = ['rmistry@google.com', 'caryclark@google.com']
25
26
27def main():
28 parser = argparse.ArgumentParser()
Ravi Mistryedc4f3e2017-12-08 12:58:20 -050029 parser.add_argument("--bookmaker_binary")
30 parser.add_argument("--fiddlecli_output")
31 args = parser.parse_args()
32
33 with git_utils.NewGitCheckout(repository=SKIA_REPO):
Eric Boren78179312018-04-23 08:35:45 -040034 with git_utils.GitBranch(branch_name='update_md_files',
35 commit_msg=COMMIT_MSG,
Ravi Mistryfaccf392018-07-19 08:43:11 -040036 commit_queue=False,
Eric Boren78179312018-04-23 08:35:45 -040037 upload=False,
38 cc_list=CC_LIST) as git_branch:
39 # Run bookmaker binary.
40 cmd = [args.bookmaker_binary,
Ravi Mistry32f547a2018-10-09 08:26:37 -040041 '-a', 'docs/status.json',
Eric Boren78179312018-04-23 08:35:45 -040042 '-f', args.fiddlecli_output,
43 '-r', 'site/user/api',
44 ]
45 try:
46 subprocess.check_call(cmd)
47 except subprocess.CalledProcessError as e:
48 print >> sys.stderr, (
49 'Running %s failed, not uploading markdowns update:\n\n%s' % (
50 cmd, e.output))
51 sys.exit(1)
Ravi Mistryedc4f3e2017-12-08 12:58:20 -050052
Eric Boren78179312018-04-23 08:35:45 -040053 # Verify that only files in the expected directory are going to be
54 # committed and uploaded.
55 diff_files = subprocess.check_output(['git', 'diff', '--name-only'])
56 for diff_file in diff_files.split():
57 if not diff_file.startswith('site/user/api/'):
Ravi Mistryedc4f3e2017-12-08 12:58:20 -050058 print >> sys.stderr, (
Eric Boren78179312018-04-23 08:35:45 -040059 'Some files in %s were not in the site/user/api dir. '
60 'Not uploading them' % diff_files)
Ravi Mistryedc4f3e2017-12-08 12:58:20 -050061 sys.exit(1)
Eric Boren78179312018-04-23 08:35:45 -040062 if diff_files:
63 subprocess.check_call(['git', 'add', '-u'])
Ravi Mistry5c43d5a2018-08-03 13:07:46 +000064 git_branch.commit_and_upload(True)
Eric Boren78179312018-04-23 08:35:45 -040065 else:
66 print 'No changes so nothing to upload.'
Ravi Mistryedc4f3e2017-12-08 12:58:20 -050067
68
69if '__main__' == __name__:
70 main()