[flutter_conductor] support commits past tagged stable release (#95349)
* support commits past tagged stable release * make better expectations
This commit is contained in:
parent
935d1478aa
commit
8b70641c11
@ -26,6 +26,7 @@ enum VersionType {
|
|||||||
/// A master channel flutter version from git describe.
|
/// A master channel flutter version from git describe.
|
||||||
///
|
///
|
||||||
/// Example: '1.2.3-4.0.pre-10-gabc123'.
|
/// Example: '1.2.3-4.0.pre-10-gabc123'.
|
||||||
|
/// Example: '1.2.3-10-gabc123'.
|
||||||
gitDescribe,
|
gitDescribe,
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -33,7 +34,7 @@ final Map<VersionType, RegExp> versionPatterns = <VersionType, RegExp>{
|
|||||||
VersionType.stable: RegExp(r'^(\d+)\.(\d+)\.(\d+)$'),
|
VersionType.stable: RegExp(r'^(\d+)\.(\d+)\.(\d+)$'),
|
||||||
VersionType.development: RegExp(r'^(\d+)\.(\d+)\.(\d+)-(\d+)\.(\d+)\.pre$'),
|
VersionType.development: RegExp(r'^(\d+)\.(\d+)\.(\d+)-(\d+)\.(\d+)\.pre$'),
|
||||||
VersionType.latest: RegExp(r'^(\d+)\.(\d+)\.(\d+)-(\d+)\.(\d+)\.pre\.(\d+)$'),
|
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 {
|
class Version {
|
||||||
@ -63,9 +64,8 @@ class Version {
|
|||||||
assert(commits != null);
|
assert(commits != null);
|
||||||
break;
|
break;
|
||||||
case VersionType.gitDescribe:
|
case VersionType.gitDescribe:
|
||||||
throw ConductorException(
|
assert(commits != null);
|
||||||
'VersionType.gitDescribe not supported! Use VersionType.latest instead.',
|
break;
|
||||||
);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -130,19 +130,20 @@ class Version {
|
|||||||
match = versionPatterns[VersionType.gitDescribe]!.firstMatch(versionString);
|
match = versionPatterns[VersionType.gitDescribe]!.firstMatch(versionString);
|
||||||
if (match != null) {
|
if (match != null) {
|
||||||
// parse latest
|
// parse latest
|
||||||
final List<int> parts = match.groups(
|
final int x = int.parse(match.group(1)!);
|
||||||
<int>[1, 2, 3, 4, 5, 6],
|
final int y = int.parse(match.group(2)!);
|
||||||
).map(
|
final int z = int.parse(match.group(3)!);
|
||||||
(String? s) => int.parse(s!),
|
final int? m = int.tryParse(match.group(5) ?? '');
|
||||||
).toList();
|
final int? n = int.tryParse(match.group(6) ?? '');
|
||||||
|
final int commits = int.parse(match.group(7)!);
|
||||||
return Version(
|
return Version(
|
||||||
x: parts[0],
|
x: x,
|
||||||
y: parts[1],
|
y: y,
|
||||||
z: parts[2],
|
z: z,
|
||||||
m: parts[3],
|
m: m,
|
||||||
n: parts[4],
|
n: n,
|
||||||
commits: parts[5],
|
commits: commits,
|
||||||
type: VersionType.latest,
|
type: VersionType.gitDescribe,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
throw Exception('${versionString.trim()} cannot be parsed');
|
throw Exception('${versionString.trim()} cannot be parsed');
|
||||||
|
@ -7,6 +7,24 @@ import 'package:conductor_core/src/version.dart';
|
|||||||
import './common.dart';
|
import './common.dart';
|
||||||
|
|
||||||
void main() {
|
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()', () {
|
group('Version.increment()', () {
|
||||||
test('throws exception on nonsensical `level`', () {
|
test('throws exception on nonsensical `level`', () {
|
||||||
final List<String> levels = <String>['f', '0', 'xyz'];
|
final List<String> levels = <String>['f', '0', 'xyz'];
|
||||||
|
Loading…
x
Reference in New Issue
Block a user