borenet | 1ed2ae4 | 2016-07-26 11:52:17 -0700 | [diff] [blame] | 1 | # Copyright 2014 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 | """Create a CL to update the SKP version.""" |
| 6 | |
| 7 | |
| 8 | import argparse |
| 9 | import os |
| 10 | import subprocess |
| 11 | import sys |
Ravi Mistry | badc137 | 2016-11-23 08:38:18 -0500 | [diff] [blame] | 12 | import urllib2 |
borenet | 1ed2ae4 | 2016-07-26 11:52:17 -0700 | [diff] [blame] | 13 | |
Ravi Mistry | bd2d111 | 2016-11-17 08:13:51 -0500 | [diff] [blame] | 14 | import git_utils |
borenet | 1ed2ae4 | 2016-07-26 11:52:17 -0700 | [diff] [blame] | 15 | |
Eric Boren | 7817931 | 2018-04-23 08:35:45 -0400 | [diff] [blame] | 16 | |
borenet | 1ed2ae4 | 2016-07-26 11:52:17 -0700 | [diff] [blame] | 17 | COMMIT_MSG = '''Update SKP version |
| 18 | |
| 19 | Automatic commit by the RecreateSKPs bot. |
| 20 | |
Eric Boren | 7817931 | 2018-04-23 08:35:45 -0400 | [diff] [blame] | 21 | TBR=rmistry@google.com |
borenet | 1ed2ae4 | 2016-07-26 11:52:17 -0700 | [diff] [blame] | 22 | NO_MERGE_BUILDS |
Eric Boren | 7817931 | 2018-04-23 08:35:45 -0400 | [diff] [blame] | 23 | ''' |
borenet | 1ed2ae4 | 2016-07-26 11:52:17 -0700 | [diff] [blame] | 24 | SKIA_REPO = 'https://skia.googlesource.com/skia.git' |
| 25 | |
| 26 | |
Eric Boren | 7817931 | 2018-04-23 08:35:45 -0400 | [diff] [blame] | 27 | def main(target_dir): |
Eric Boren | d41c187 | 2019-01-25 12:05:59 -0500 | [diff] [blame] | 28 | # We're going to sync a new, clean Skia checkout to upload the CL to update |
| 29 | # the SKPs. However, we want to use the scripts from the current checkout, |
| 30 | # in order to facilitate running this as a try job. |
| 31 | infrabots_dir = os.path.dirname(os.path.realpath(__file__)) |
| 32 | skp_dir = os.path.join(infrabots_dir, 'assets', 'skp') |
| 33 | upload_py = os.path.join(skp_dir, 'upload.py') |
| 34 | |
Ravi Mistry | e7d34b1 | 2016-12-06 08:14:12 -0500 | [diff] [blame] | 35 | with git_utils.NewGitCheckout(repository=SKIA_REPO): |
Ravi Mistry | badc137 | 2016-11-23 08:38:18 -0500 | [diff] [blame] | 36 | # First verify that there are no gen_tasks diffs. |
Eric Boren | d41c187 | 2019-01-25 12:05:59 -0500 | [diff] [blame] | 37 | tmp_infrabots_dir = os.path.join(os.getcwd(), 'infra', 'bots') |
| 38 | tmp_gen_tasks = os.path.join(tmp_infrabots_dir, 'gen_tasks.go') |
Ravi Mistry | badc137 | 2016-11-23 08:38:18 -0500 | [diff] [blame] | 39 | try: |
Eric Boren | d41c187 | 2019-01-25 12:05:59 -0500 | [diff] [blame] | 40 | subprocess.check_call(['go', 'run', tmp_gen_tasks, '--test']) |
Ravi Mistry | badc137 | 2016-11-23 08:38:18 -0500 | [diff] [blame] | 41 | except subprocess.CalledProcessError as e: |
| 42 | print >> sys.stderr, ( |
| 43 | 'gen_tasks.go failed, not uploading SKP update:\n\n%s' % e.output) |
| 44 | sys.exit(1) |
borenet | 8a91da9 | 2016-10-18 05:20:26 -0700 | [diff] [blame] | 45 | |
Eric Boren | e7950e3 | 2018-04-26 08:49:38 -0400 | [diff] [blame] | 46 | # Upload the new version, land the update CL as the recreate-skps user. |
Eric Boren | 7817931 | 2018-04-23 08:35:45 -0400 | [diff] [blame] | 47 | with git_utils.GitBranch(branch_name='update_skp_version', |
| 48 | commit_msg=COMMIT_MSG, |
| 49 | commit_queue=True): |
Eric Boren | d41c187 | 2019-01-25 12:05:59 -0500 | [diff] [blame] | 50 | upload_cmd = ['python', upload_py, '-t', target_dir] |
| 51 | if args.chromium_path: |
| 52 | chromium_revision = subprocess.check_output( |
| 53 | ['git', 'rev-parse', 'HEAD'], cwd=args.chromium_path).rstrip() |
| 54 | upload_cmd.extend([ |
| 55 | '--extra_tags', 'chromium_revision:%s' % chromium_revision]) |
| 56 | subprocess.check_call(upload_cmd) |
| 57 | # We used upload.py from the repo that this script lives in, NOT the temp |
| 58 | # repo we've created. Therefore, the VERSION file was written in that repo |
| 59 | # so we need to copy it to the temp repo in order to commit it. |
| 60 | src = os.path.join(skp_dir, 'VERSION') |
| 61 | dst = os.path.join( |
| 62 | os.getcwd(), 'infra', 'bots', 'assets', 'skp', 'VERSION') |
| 63 | subprocess.check_call(['cp', src, dst]) |
| 64 | subprocess.check_call(['go', 'run', tmp_gen_tasks]) |
Eric Boren | 7817931 | 2018-04-23 08:35:45 -0400 | [diff] [blame] | 65 | subprocess.check_call([ |
| 66 | 'git', 'add', os.path.join('infra', 'bots', 'tasks.json')]) |
borenet | 1ed2ae4 | 2016-07-26 11:52:17 -0700 | [diff] [blame] | 67 | |
| 68 | |
| 69 | if '__main__' == __name__: |
| 70 | parser = argparse.ArgumentParser() |
| 71 | parser.add_argument("--target_dir") |
Eric Boren | d41c187 | 2019-01-25 12:05:59 -0500 | [diff] [blame] | 72 | parser.add_argument("--chromium_path") |
borenet | 1ed2ae4 | 2016-07-26 11:52:17 -0700 | [diff] [blame] | 73 | args = parser.parse_args() |
Eric Boren | 7817931 | 2018-04-23 08:35:45 -0400 | [diff] [blame] | 74 | main(args.target_dir) |