blob: 4e36724175801ba514f44bdb61cfe7c86f9dc226 [file] [log] [blame]
Rico Windb4621c12017-08-28 12:48:53 +02001#!/usr/bin/env python
2# Copyright (c) 2017, the R8 project authors. Please see the AUTHORS file
3# for details. All rights reserved. Use of this source code is governed by a
4# BSD-style license that can be found in the LICENSE file.
5
6import d8
7import os
8import r8
Rico Wind0c24ae72017-09-08 11:33:56 +02009import subprocess
Rico Windb4621c12017-08-28 12:48:53 +020010import sys
11import utils
12
Rico Wind792e8c72017-08-30 09:43:46 +020013ARCHIVE_BUCKET = 'r8-releases'
Rico Windb4621c12017-08-28 12:48:53 +020014
15def GetVersion():
16 r8_version = r8.run(['--version'], build = False).strip()
17 d8_version = d8.run(['--version'], build = False).strip()
18 # The version printed is "D8 vVERSION_NUMBER" and "R8 vVERSION_NUMBER"
19 # Sanity check that versions match.
20 if d8_version.split()[1] != r8_version.split()[1]:
21 raise Exception(
22 'Version mismatch: \n%s\n%s' % (d8_version, r8_version))
23 return d8_version.split()[1]
24
Rico Wind0c24ae72017-09-08 11:33:56 +020025def GetGitBranches():
26 return subprocess.check_output(['git', 'show', '-s', '--pretty=%d', 'HEAD'])
Rico Windb4621c12017-08-28 12:48:53 +020027
Rico Wind0c24ae72017-09-08 11:33:56 +020028def GetGitHash():
29 return subprocess.check_output(['git', 'rev-parse', 'HEAD']).strip()
Rico Windb4621c12017-08-28 12:48:53 +020030
Rico Wind0c24ae72017-09-08 11:33:56 +020031def IsMaster(version):
Rico Wind2f720292017-10-06 14:32:12 +020032 branches = subprocess.check_output(['git', 'branch', '-r', '--contains',
Rico Wind0c24ae72017-09-08 11:33:56 +020033 'HEAD'])
34 if not version.endswith('-dev'):
35 # Sanity check, we don't want to archive on top of release builds EVER
36 # Note that even though we branch, we never push the bots to build the same
37 # commit as master on a branch since we always change the version to
38 # not have dev (or we crash here :-)).
39 if 'origin/master' in branches:
40 raise Exception('We are seeing origin/master in a commit that '
41 'don\'t have -dev in version')
42 return False;
43 if not 'origin/master' in branches:
44 raise Exception('We are not seeing origin/master '
45 'in a commit that have -dev in version')
46 return True;
47
48def GetStorageDestination(storage_prefix, version, file_name, is_master):
49 # We archive master commits under raw/master instead of directly under raw
50 archive_dir = 'raw/master' if is_master else 'raw'
51 return '%s%s/%s/%s/%s' % (storage_prefix, ARCHIVE_BUCKET, archive_dir,
52 version, file_name)
53
54def GetUploadDestination(version, file_name, is_master):
55 return GetStorageDestination('gs://', version, file_name, is_master)
56
57def GetUrl(version, file_name, is_master):
Rico Windb4621c12017-08-28 12:48:53 +020058 return GetStorageDestination('http://storage.googleapis.com/',
Rico Wind0c24ae72017-09-08 11:33:56 +020059 version, file_name, is_master)
Rico Windb4621c12017-08-28 12:48:53 +020060
61def Main():
62 if not 'BUILDBOT_BUILDERNAME' in os.environ:
63 raise Exception('You are not a bot, don\'t archive builds')
64 version = GetVersion()
Rico Wind0c24ae72017-09-08 11:33:56 +020065 is_master = IsMaster(version)
66 if is_master:
67 # On master we use the git hash to archive with
68 print 'On master, using git hash for archiving'
69 version = GetGitHash()
70
Rico Wind74fab302017-10-02 07:25:33 +020071 for jar in [utils.D8_JAR, utils.R8_JAR, utils.COMPATDX_JAR]:
Rico Windb4621c12017-08-28 12:48:53 +020072 file_name = os.path.basename(jar)
Rico Wind0c24ae72017-09-08 11:33:56 +020073 destination = GetUploadDestination(version, file_name, is_master)
Rico Windb4621c12017-08-28 12:48:53 +020074 print('Uploading %s to %s' % (jar, destination))
75 utils.upload_file_to_cloud_storage(jar, destination)
Rico Wind0c24ae72017-09-08 11:33:56 +020076 print('File available at: %s' % GetUrl(version, file_name, is_master))
Rico Windb4621c12017-08-28 12:48:53 +020077
78if __name__ == '__main__':
79 sys.exit(Main())