Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Sign in
Toggle navigation
F
Front-End
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
abdullh.alsoleman
Front-End
Commits
e593a863
Unverified
Commit
e593a863
authored
Oct 20, 2021
by
Christopher Fujino
Committed by
GitHub
Oct 20, 2021
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[flutter_conductor] validate git parsed version and release branch match (#92064)
parent
8f574c29
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
124 additions
and
4 deletions
+124
-4
globals.dart
dev/conductor/core/lib/src/globals.dart
+2
-1
start.dart
dev/conductor/core/lib/src/start.dart
+2
-1
version.dart
dev/conductor/core/lib/src/version.dart
+46
-1
start_test.dart
dev/conductor/core/test/start_test.dart
+1
-1
version_test.dart
dev/conductor/core/test/version_test.dart
+73
-0
No files found.
dev/conductor/core/lib/src/globals.dart
View file @
e593a863
...
...
@@ -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
),
...
...
dev/conductor/core/lib/src/start.dart
View file @
e593a863
...
...
@@ -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
);
...
...
dev/conductor/core/lib/src/version.dart
View file @
e593a863
...
...
@@ -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
)
{
...
...
dev/conductor/core/test/start_test.dart
View file @
e593a863
...
...
@@ -310,7 +310,7 @@ void main() {
const
String
revision3
=
'123abc'
;
const
String
previousDartRevision
=
'171876a4e6cf56ee6da1f97d203926bd7afda7ef'
;
const
String
nextDartRevision
=
'f6c91128be6b77aef8351e1e3a9d07c85bc2e46e'
;
const
String
previousVersion
=
'1.2.0-
1
.0.pre'
;
const
String
previousVersion
=
'1.2.0-
3
.0.pre'
;
const
String
nextVersion
=
'1.2.0'
;
const
String
incrementLevel
=
'z'
;
...
...
dev/conductor/core/test/version_test.dart
View file @
e593a863
...
...
@@ -81,4 +81,77 @@ void main() {
},
onPlatform:
<
String
,
dynamic
>{
'windows'
:
const
Skip
(
'Flutter Conductor only supported on macos/linux'
),
});
group
(
'.ensureValid()'
,
()
{
test
(
'throws when x does not match'
,
()
{
const
String
versionString
=
'1.2.3-4.5.pre'
;
const
String
candidateBranch
=
'flutter-3.2-candidate.4'
;
final
Version
version
=
Version
.
fromString
(
versionString
);
expect
(
()
=>
version
.
ensureValid
(
candidateBranch
,
'n'
),
throwsExceptionWith
(
'Parsed version
$versionString
has a different x value than '
'candidate branch
$candidateBranch
'
,
),
);
});
test
(
'throws when y does not match'
,
()
{
const
String
versionString
=
'1.2.3'
;
const
String
candidateBranch
=
'flutter-1.15-candidate.4'
;
final
Version
version
=
Version
.
fromString
(
versionString
);
expect
(
()
=>
version
.
ensureValid
(
candidateBranch
,
'm'
),
throwsExceptionWith
(
'Parsed version
$versionString
has a different y value than '
'candidate branch
$candidateBranch
'
,
),
);
});
test
(
'throws when m does not match'
,
()
{
const
String
versionString
=
'1.2.3-4.5.pre'
;
const
String
candidateBranch
=
'flutter-1.2-candidate.0'
;
final
Version
version
=
Version
.
fromString
(
versionString
);
expect
(
()
=>
version
.
ensureValid
(
candidateBranch
,
'n'
),
throwsExceptionWith
(
'Parsed version
$versionString
has a different m value than '
'candidate branch
$candidateBranch
'
,
),
);
});
test
(
'does not validate m if version type is stable'
,
()
{
const
String
versionString
=
'1.2.0'
;
const
String
candidateBranch
=
'flutter-1.2-candidate.98'
;
final
Version
version
=
Version
.
fromString
(
versionString
);
expect
(
()
=>
version
.
ensureValid
(
candidateBranch
,
'n'
),
isNot
(
throwsException
),
);
});
test
(
'throws on malformed candidate branch'
,
()
{
const
String
versionString
=
'1.2.0'
;
const
String
candidateBranch
=
'stable'
;
final
Version
version
=
Version
.
fromString
(
versionString
);
expect
(
()
=>
version
.
ensureValid
(
candidateBranch
,
'z'
),
throwsExceptionWith
(
'Candidate branch
$candidateBranch
does not match the pattern'
,
),
);
});
test
(
'does not validate m if incrementLetter is m'
,
()
{
const
String
versionString
=
'1.2.0-0.0.pre'
;
const
String
candidateBranch
=
'flutter-1.2-candidate.42'
;
final
Version
version
=
Version
.
fromString
(
versionString
);
expect
(
()
=>
version
.
ensureValid
(
candidateBranch
,
'm'
),
isNot
(
throwsException
),
);
});
});
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment