1# 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_REPO = 'https://skia.googlesource.com/skia.git' 17COMMIT_MSG = '''Update markdown files 18 19Automatic commit by the Housekeeper-Nightly-Bookmaker bot. 20 21TBR=rmistry@google.com 22NO_MERGE_BUILDS 23''' 24CC_LIST = ['rmistry@google.com', 'caryclark@google.com'] 25 26 27def main(): 28 parser = argparse.ArgumentParser() 29 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): 34 with git_utils.GitBranch(branch_name='update_md_files', 35 commit_msg=COMMIT_MSG, 36 commit_queue=False, 37 upload=False, 38 cc_list=CC_LIST) as git_branch: 39 # Run bookmaker binary. 40 cmd = [args.bookmaker_binary, 41 '-a', 'docs/status.json', 42 '-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) 52 53 # 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/'): 58 print >> sys.stderr, ( 59 'Some files in %s were not in the site/user/api dir. ' 60 'Not uploading them' % diff_files) 61 sys.exit(1) 62 if diff_files: 63 subprocess.check_call(['git', 'add', '-u']) 64 git_branch.commit_and_upload(True) 65 else: 66 print 'No changes so nothing to upload.' 67 68 69if '__main__' == __name__: 70 main() 71