| OLD | NEW |
| (Empty) | |
| 1 #!/usr/bin/python |
| 2 |
| 3 # Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file |
| 4 # for details. All rights reserved. Use of this source code is governed by a |
| 5 # BSD-style license that can be found in the LICENSE file. |
| 6 |
| 7 |
| 8 import os |
| 9 import json |
| 10 import re |
| 11 import sys |
| 12 |
| 13 import bot |
| 14 import bot_utils |
| 15 |
| 16 utils = bot_utils.GetUtils() |
| 17 |
| 18 VERSION_BUILDER = r'version-checker' |
| 19 |
| 20 def VersionConfig(name, is_buildbot): |
| 21 version_pattern = re.match(VERSION_BUILDER, name) |
| 22 if not version_pattern: |
| 23 return None |
| 24 # We don't really use this, but we create it anyway to use the standard |
| 25 # bot execution model. |
| 26 return bot.BuildInfo('none', 'none', 'release', 'linux') |
| 27 |
| 28 def GetLatestVersionFromGCS(channel): |
| 29 namer = bot_utils.GCSNamer(channel=channel) |
| 30 gsutil = bot_utils.GSUtil() |
| 31 gcs_version_path = namer.version_filepath('latest') |
| 32 print 'Getting latest version from: %s' % gcs_version_path |
| 33 version_json = gsutil.cat(gcs_version_path) |
| 34 version_map = json.loads(version_json) |
| 35 return version_map['version'] |
| 36 |
| 37 def ValidateChannelVersion(latest_version, channel): |
| 38 repo_version = utils.ReadVersionFile() |
| 39 assert repo_version.channel == channel |
| 40 if channel == bot_utils.Channel.STABLE: |
| 41 assert int(repo_version.prerelease) == 0 |
| 42 assert int(repo_version.prerelease_patch) == 0 |
| 43 |
| 44 version_re = r'(\d+)\.(\d+)\.(\d+)(-dev\.(\d+)\.(\d+))?' |
| 45 |
| 46 latest_match = re.match(version_re, latest_version) |
| 47 latest_major = int(latest_match.group(1)) |
| 48 latest_minor = int(latest_match.group(2)) |
| 49 latest_patch = int(latest_match.group(3)) |
| 50 # We don't use these on stable. |
| 51 latest_prerelease = int(latest_match.group(5) or 0) |
| 52 latest_prerelease_patch = int(latest_match.group(6) or 0) |
| 53 |
| 54 if latest_major < int(repo_version.major): |
| 55 return True |
| 56 if latest_minor < int(repo_version.minor): |
| 57 return True |
| 58 if latest_patch < int(repo_version.patch): |
| 59 return True |
| 60 if latest_prerelease < int(repo_version.prerelease): |
| 61 return True |
| 62 if latest_prerelease_patch < int(repo_version.prerelease_patch): |
| 63 return True |
| 64 return False |
| 65 |
| 66 def VersionSteps(build_info): |
| 67 with bot.BuildStep('Version file sanity checking'): |
| 68 bot_name, _ = bot.GetBotName() |
| 69 channel = bot_utils.GetChannelFromName(bot_name) |
| 70 if channel == bot_utils.Channel.BLEEDING_EDGE: |
| 71 print 'No sanity checking on bleeding edge' |
| 72 else: |
| 73 assert (channel == bot_utils.Channel.STABLE or |
| 74 channel == bot_utils.Channel.DEV) |
| 75 latest_version = GetLatestVersionFromGCS(channel) |
| 76 version = utils.GetVersion() |
| 77 print 'Latests version on GCS: %s' % latest_version |
| 78 print 'Version currently building: %s' % version |
| 79 if not ValidateChannelVersion(latest_version, channel): |
| 80 print "Validation failed" |
| 81 sys.exit(1) |
| 82 if latest_version == version: |
| 83 print 'Version file has not been updated' |
| 84 sys.exit(1) |
| 85 else: |
| 86 print 'Version file changed, sanity checks passed' |
| 87 |
| 88 if __name__ == '__main__': |
| 89 # We pass in None for build_step to avoid building. |
| 90 bot.RunBot(VersionConfig, VersionSteps, build_step=None) |
| OLD | NEW |