[flutter_conductor] validate git parsed version and release branch match (#92064)
This commit is contained in:
committed by
GitHub
parent
8f574c297a
commit
e593a863eb
@@ -54,7 +54,8 @@ Directory get localFlutterRoot {
|
||||
final String checkoutsDirname = fileSystem.path.normalize(
|
||||
fileSystem.path.join(
|
||||
fileSystem.path.dirname(filePath),
|
||||
'..', // flutter/dev/tools
|
||||
'..', // flutter/dev/conductor/core
|
||||
'..', // flutter/dev/conductor
|
||||
'..', // flutter/dev
|
||||
'..', // flutter
|
||||
),
|
||||
|
||||
@@ -382,7 +382,8 @@ class StartContext {
|
||||
// Get framework version
|
||||
final Version lastVersion = Version.fromString(await framework.getFullTag(
|
||||
framework.upstreamRemote.name, candidateBranch,
|
||||
exact: false));
|
||||
exact: false,
|
||||
))..ensureValid(candidateBranch, incrementLetter);
|
||||
Version nextVersion;
|
||||
if (incrementLetter == 'm') {
|
||||
nextVersion = Version.fromCandidateBranch(candidateBranch);
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
import './globals.dart' show ConductorException;
|
||||
import './globals.dart' show releaseCandidateBranchRegex, ConductorException;
|
||||
|
||||
/// Possible string formats that `flutter --version` can return.
|
||||
enum VersionType {
|
||||
@@ -251,6 +251,51 @@ class Version {
|
||||
|
||||
final VersionType type;
|
||||
|
||||
/// Validate that the parsed version is valid.
|
||||
///
|
||||
/// Will throw a [ConductorException] if the version is not possible given the
|
||||
/// [candidateBranch] and [incrementLetter].
|
||||
void ensureValid(String candidateBranch, String incrementLetter) {
|
||||
if (!const <String>{'y', 'z', 'm', 'n'}.contains(incrementLetter)) {
|
||||
throw ConductorException('Invalid incrementLetter: $incrementLetter');
|
||||
}
|
||||
final RegExpMatch? branchMatch = releaseCandidateBranchRegex.firstMatch(candidateBranch);
|
||||
if (branchMatch == null) {
|
||||
throw ConductorException(
|
||||
'Candidate branch $candidateBranch does not match the pattern '
|
||||
'${releaseCandidateBranchRegex.pattern}',
|
||||
);
|
||||
}
|
||||
|
||||
// These groups are required in the pattern, so these match groups should
|
||||
// not be null
|
||||
final String branchX = branchMatch.group(1)!;
|
||||
if (x != int.tryParse(branchX)) {
|
||||
throw ConductorException(
|
||||
'Parsed version ${toString()} has a different x value than candidate '
|
||||
'branch $candidateBranch',
|
||||
);
|
||||
}
|
||||
final String branchY = branchMatch.group(2)!;
|
||||
if (y != int.tryParse(branchY)) {
|
||||
throw ConductorException(
|
||||
'Parsed version ${toString()} has a different y value than candidate '
|
||||
'branch $candidateBranch',
|
||||
);
|
||||
}
|
||||
|
||||
// stable type versions don't have an m field set
|
||||
if (type != VersionType.stable && incrementLetter != 'm') {
|
||||
final String branchM = branchMatch.group(3)!;
|
||||
if (m != int.tryParse(branchM)) {
|
||||
throw ConductorException(
|
||||
'Parsed version ${toString()} has a different m value than candidate '
|
||||
'branch $candidateBranch',
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
String toString() {
|
||||
switch (type) {
|
||||
|
||||
Reference in New Issue
Block a user