Ravi Mistry | edc4f3e | 2017-12-08 12:58:20 -0500 | [diff] [blame] | 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 | |
Ravi Mistry | edc4f3e | 2017-12-08 12:58:20 -0500 | [diff] [blame] | 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 | |
Eric Boren | 7817931 | 2018-04-23 08:35:45 -0400 | [diff] [blame] | 21 | TBR=rmistry@google.com |
Ravi Mistry | edc4f3e | 2017-12-08 12:58:20 -0500 | [diff] [blame] | 22 | NO_MERGE_BUILDS |
Eric Boren | 7817931 | 2018-04-23 08:35:45 -0400 | [diff] [blame] | 23 | ''' |
Ravi Mistry | edc4f3e | 2017-12-08 12:58:20 -0500 | [diff] [blame] | 24 | CC_LIST = ['rmistry@google.com', 'caryclark@google.com'] |
| 25 | |
| 26 | |
| 27 | def main(): |
| 28 | parser = argparse.ArgumentParser() |
Ravi Mistry | edc4f3e | 2017-12-08 12:58:20 -0500 | [diff] [blame] | 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): |
Eric Boren | 7817931 | 2018-04-23 08:35:45 -0400 | [diff] [blame] | 34 | with git_utils.GitBranch(branch_name='update_md_files', |
| 35 | commit_msg=COMMIT_MSG, |
| 36 | commit_queue=True, |
| 37 | upload=False, |
| 38 | cc_list=CC_LIST) as git_branch: |
| 39 | # Run bookmaker binary. |
| 40 | cmd = [args.bookmaker_binary, |
| 41 | '-b', 'docs', |
| 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) |
Ravi Mistry | edc4f3e | 2017-12-08 12:58:20 -0500 | [diff] [blame] | 52 | |
Eric Boren | 7817931 | 2018-04-23 08:35:45 -0400 | [diff] [blame] | 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/'): |
Ravi Mistry | edc4f3e | 2017-12-08 12:58:20 -0500 | [diff] [blame] | 58 | print >> sys.stderr, ( |
Eric Boren | 7817931 | 2018-04-23 08:35:45 -0400 | [diff] [blame] | 59 | 'Some files in %s were not in the site/user/api dir. ' |
| 60 | 'Not uploading them' % diff_files) |
Ravi Mistry | edc4f3e | 2017-12-08 12:58:20 -0500 | [diff] [blame] | 61 | sys.exit(1) |
Eric Boren | 7817931 | 2018-04-23 08:35:45 -0400 | [diff] [blame] | 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.' |
Ravi Mistry | edc4f3e | 2017-12-08 12:58:20 -0500 | [diff] [blame] | 67 | |
| 68 | |
| 69 | if '__main__' == __name__: |
| 70 | main() |