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 8 import argparse 9 import os 10 import subprocess 11 import sys 12 13 import git_utils 14 15 16 SKIA_REPO = 'https://skia.googlesource.com/skia.git' 17 COMMIT_MSG = '''Update markdown files 18 19 Automatic commit by the Housekeeper-Nightly-Bookmaker bot. 20 21 TBR=rmistry (at] google.com 22 NO_MERGE_BUILDS 23 ''' 24 CC_LIST = ['rmistry (at] google.com', 'caryclark (at] google.com'] 25 26 27 def 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 69 if '__main__' == __name__: 70 main() 71