Unverified Commit 8b70641c authored by Christopher Fujino's avatar Christopher Fujino Committed by GitHub

[flutter_conductor] support commits past tagged stable release (#95349)

* support commits past tagged stable release

* make better expectations
parent 935d1478
......@@ -26,6 +26,7 @@ enum VersionType {
/// A master channel flutter version from git describe.
///
/// Example: '1.2.3-4.0.pre-10-gabc123'.
/// Example: '1.2.3-10-gabc123'.
gitDescribe,
}
......@@ -33,7 +34,7 @@ final Map<VersionType, RegExp> versionPatterns = <VersionType, RegExp>{
VersionType.stable: RegExp(r'^(\d+)\.(\d+)\.(\d+)$'),
VersionType.development: RegExp(r'^(\d+)\.(\d+)\.(\d+)-(\d+)\.(\d+)\.pre$'),
VersionType.latest: RegExp(r'^(\d+)\.(\d+)\.(\d+)-(\d+)\.(\d+)\.pre\.(\d+)$'),
VersionType.gitDescribe: RegExp(r'^(\d+)\.(\d+)\.(\d+)-(\d+)\.(\d+)\.pre-(\d+)-g[a-f0-9]+$'),
VersionType.gitDescribe: RegExp(r'^(\d+)\.(\d+)\.(\d+)-((\d+)\.(\d+)\.pre-)?(\d+)-g[a-f0-9]+$'),
};
class Version {
......@@ -63,9 +64,8 @@ class Version {
assert(commits != null);
break;
case VersionType.gitDescribe:
throw ConductorException(
'VersionType.gitDescribe not supported! Use VersionType.latest instead.',
);
assert(commits != null);
break;
}
}
......@@ -130,19 +130,20 @@ class Version {
match = versionPatterns[VersionType.gitDescribe]!.firstMatch(versionString);
if (match != null) {
// parse latest
final List<int> parts = match.groups(
<int>[1, 2, 3, 4, 5, 6],
).map(
(String? s) => int.parse(s!),
).toList();
final int x = int.parse(match.group(1)!);
final int y = int.parse(match.group(2)!);
final int z = int.parse(match.group(3)!);
final int? m = int.tryParse(match.group(5) ?? '');
final int? n = int.tryParse(match.group(6) ?? '');
final int commits = int.parse(match.group(7)!);
return Version(
x: parts[0],
y: parts[1],
z: parts[2],
m: parts[3],
n: parts[4],
commits: parts[5],
type: VersionType.latest,
x: x,
y: y,
z: z,
m: m,
n: n,
commits: commits,
type: VersionType.gitDescribe,
);
}
throw Exception('${versionString.trim()} cannot be parsed');
......
......@@ -7,6 +7,24 @@ import 'package:conductor_core/src/version.dart';
import './common.dart';
void main() {
group('Version.fromString()', () {
test('parses commits past a tagged stable', () {
const String versionString = '2.8.0-1-g2ef5ad67fe';
final Version version;
try {
version = Version.fromString(versionString);
} on Exception catch (exception) {
fail('Failed parsing "$versionString" with:\n$exception');
}
expect(version.x, 2);
expect(version.y, 8);
expect(version.z, 0);
expect(version.m, isNull);
expect(version.n, isNull);
expect(version.commits, 1);
expect(version.type, VersionType.gitDescribe);
});
});
group('Version.increment()', () {
test('throws exception on nonsensical `level`', () {
final List<String> levels = <String>['f', '0', 'xyz'];
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment