diff --git a/dev/tools/lib/roll_dev.dart b/dev/tools/lib/roll_dev.dart index cc7b13202a..cc766b3148 100644 --- a/dev/tools/lib/roll_dev.dart +++ b/dev/tools/lib/roll_dev.dart @@ -25,6 +25,7 @@ const String kUpstreamRemote = 'git@github.com:flutter/flutter.git'; void main(List args) { final ArgParser argParser = ArgParser(allowTrailingOptions: false); + argParser.addOption( kIncrement, help: 'Specifies which part of the x.y.z version number to increment. Required.', @@ -38,9 +39,9 @@ void main(List args) { ); argParser.addOption( kCommit, - help: 'Specifies which git commit to roll to the dev branch.', + help: 'Specifies which git commit to roll to the dev branch. Required.', valueHelp: 'hash', - defaultsTo: 'upstream/master', + defaultsTo: null, // This option is required ); argParser.addOption( kOrigin, @@ -57,6 +58,7 @@ void main(List args) { ); argParser.addFlag(kYes, negatable: false, abbr: 'y', help: 'Skip the confirmation prompt.'); argParser.addFlag(kHelp, negatable: false, help: 'Show this help message.', hide: true); + ArgResults argResults; try { argResults = argParser.parse(args); @@ -73,7 +75,7 @@ void main(List args) { final bool autoApprove = argResults[kYes] as bool; final bool help = argResults[kHelp] as bool; - if (help || level == null) { + if (help || level == null || commit == null) { print('roll_dev.dart --increment=level --commit=hash • update the version tags and roll a new dev build.\n'); print(argParser.usage); exit(0); @@ -165,23 +167,31 @@ void main(List args) { } String getFullTag() { + const String glob = '*.*.*-*.*.pre'; return getGitOutput( - 'describe --match *.*.*-dev.*.* --first-parent --long --tags', + 'describe --match $glob --first-parent --long --tags', 'obtain last released version number', ); } Match parseFullTag(String version) { - final RegExp versionPattern = RegExp(r'^([0-9]+)\.([0-9]+)\.([0-9]+)-dev\.([0-9]+)\.([0-9]+)-([0-9]+)-g([a-f0-9]+)$'); + // of the form: x.y.z-m.n.pre-c-g + final RegExp versionPattern = RegExp( + r'^(\d+)\.(\d+)\.(\d+)-(\d+)\.(\d+)\.pre-(\d+)-g([a-f0-9]+)$'); return versionPattern.matchAsPrefix(version); } String getVersionFromParts(List parts) { + // where parts correspond to [x, y, z, m, n] from tag assert(parts.length == 5); final StringBuffer buf = StringBuffer() + // take x, y, and z ..write(parts.take(3).join('.')) - ..write('-dev.') - ..write(parts.skip(3).join('.')); + ..write('-') + // skip x, y, and z, take m and n + ..write(parts.skip(3).take(2).join('.')) + ..write('.pre'); + // return a string that looks like: '1.2.3-4.5.pre' return buf.toString(); } diff --git a/dev/tools/test/roll_dev_test.dart b/dev/tools/test/roll_dev_test.dart new file mode 100644 index 0000000000..f456fa44ce --- /dev/null +++ b/dev/tools/test/roll_dev_test.dart @@ -0,0 +1,54 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'package:dev_tools/roll_dev.dart'; +import './common.dart'; + +void main() { + group('parseFullTag', () { + test('returns match on valid version input', () { + final List validTags = [ + '1.2.3-1.2.pre-3-gabc123', + '10.2.30-12.22.pre-45-gabc123', + '1.18.0-0.0.pre-0-gf0adb240a', + '2.0.0-1.99.pre-45-gf0adb240a', + '12.34.56-78.90.pre-12-g9db2703a2', + '0.0.1-0.0.pre-1-g07601eb95ff82f01e870566586340ed2e87b9cbb', + '958.80.144-6.224.pre-7803-g06e90', + ]; + for (final String validTag in validTags) { + final Match match = parseFullTag(validTag); + expect(match, isNotNull, reason: 'Expected $validTag to be parsed'); + } + }); + + test('returns null on invalid version input', () { + final List invalidTags = [ + '1.2.3-dev.1.2-3-gabc123', + '1.2.3-1.2-3-gabc123', + 'v1.2.3', + '2.0.0', + 'v1.2.3-1.2.pre-3-gabc123', + '10.0.1-0.0.pre-gf0adb240a', + '10.0.1-0.0.pre-3-gggggggggg', + '1.2.3-1.2.pre-3-abc123', + '1.2.3-1.2.pre-3-gabc123_', + ]; + for (final String invalidTag in invalidTags) { + final Match match = parseFullTag(invalidTag); + expect(match, null, reason: 'Expected $invalidTag to not be parsed'); + } + }); + }); + + group('getVersionFromParts', () { + test('returns correct string from valid parts', () { + List parts = [1, 2, 3, 4, 5]; + expect(getVersionFromParts(parts), '1.2.3-4.5.pre'); + + parts = [11, 2, 33, 1, 0]; + expect(getVersionFromParts(parts), '11.2.33-1.0.pre'); + }); + }); +}