blob: c5b7ac30d0ae7c7f59953a521069a628baeb7986 [file] [log] [blame]
borenet1ed2ae42016-07-26 11:52:17 -07001# 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
8import argparse
9import os
10import subprocess
11import sys
Ravi Mistrybadc1372016-11-23 08:38:18 -050012import urllib2
borenet1ed2ae42016-07-26 11:52:17 -070013
Ravi Mistrybd2d1112016-11-17 08:13:51 -050014import git_utils
borenet1ed2ae42016-07-26 11:52:17 -070015
Eric Boren78179312018-04-23 08:35:45 -040016
borenet1ed2ae42016-07-26 11:52:17 -070017COMMIT_MSG = '''Update SKP version
18
19Automatic commit by the RecreateSKPs bot.
20
Eric Boren78179312018-04-23 08:35:45 -040021TBR=rmistry@google.com
borenet1ed2ae42016-07-26 11:52:17 -070022NO_MERGE_BUILDS
Eric Boren78179312018-04-23 08:35:45 -040023'''
borenet1ed2ae42016-07-26 11:52:17 -070024SKIA_REPO = 'https://skia.googlesource.com/skia.git'
25
26
Eric Boren78179312018-04-23 08:35:45 -040027def main(target_dir):
Eric Borend41c1872019-01-25 12:05:59 -050028 # 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 Mistrye7d34b12016-12-06 08:14:12 -050035 with git_utils.NewGitCheckout(repository=SKIA_REPO):
Ravi Mistrybadc1372016-11-23 08:38:18 -050036 # First verify that there are no gen_tasks diffs.
Eric Borend41c1872019-01-25 12:05:59 -050037 tmp_infrabots_dir = os.path.join(os.getcwd(), 'infra', 'bots')
38 tmp_gen_tasks = os.path.join(tmp_infrabots_dir, 'gen_tasks.go')
Ravi Mistrybadc1372016-11-23 08:38:18 -050039 try:
Eric Borend41c1872019-01-25 12:05:59 -050040 subprocess.check_call(['go', 'run', tmp_gen_tasks, '--test'])
Ravi Mistrybadc1372016-11-23 08:38:18 -050041 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)
borenet8a91da92016-10-18 05:20:26 -070045
Eric Borene7950e32018-04-26 08:49:38 -040046 # Upload the new version, land the update CL as the recreate-skps user.
Eric Boren78179312018-04-23 08:35:45 -040047 with git_utils.GitBranch(branch_name='update_skp_version',
48 commit_msg=COMMIT_MSG,
49 commit_queue=True):
Eric Borend41c1872019-01-25 12:05:59 -050050 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 Boren78179312018-04-23 08:35:45 -040065 subprocess.check_call([
66 'git', 'add', os.path.join('infra', 'bots', 'tasks.json')])
borenet1ed2ae42016-07-26 11:52:17 -070067
68
69if '__main__' == __name__:
70 parser = argparse.ArgumentParser()
71 parser.add_argument("--target_dir")
Eric Borend41c1872019-01-25 12:05:59 -050072 parser.add_argument("--chromium_path")
borenet1ed2ae42016-07-26 11:52:17 -070073 args = parser.parse_args()
Eric Boren78179312018-04-23 08:35:45 -040074 main(args.target_dir)