Skip to content

Commit ec9e07d

Browse files
authored
[ Tool ] Fix flutter upgrade stating that an upgrade is available on main when up to date (flutter#172141)
The `frameworkVersion` string written to the version files wasn't actually parsable by `GitTagVersion` as it didn't match the format output by `git`. This change updates the `frameworkVersion` format to use a `-` instead of a `.` before the commit count and adds support to the version parsing regex to handle both `.` and `-` separators before the commit count. Fixes flutter#172091
1 parent 6474b04 commit ec9e07d

File tree

3 files changed

+34
-10
lines changed

3 files changed

+34
-10
lines changed

dev/bots/utils.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -740,7 +740,7 @@ Future<void> _runFromList(
740740
/// Returns null if the contents are good. Returns a string if they are bad.
741741
/// The string is an error message.
742742
Future<String?> verifyVersion(File file) async {
743-
final RegExp pattern = RegExp(r'^(\d+)\.(\d+)\.(\d+)((-\d+\.\d+)?\.pre(\.\d+)?)?$');
743+
final RegExp pattern = RegExp(r'^(\d+)\.(\d+)\.(\d+)((-\d+\.\d+)?\.pre([-\.]\d+)?)?$');
744744
if (!file.existsSync()) {
745745
return 'The version logic failed to create the Flutter version file.';
746746
}

packages/flutter_tools/lib/src/version.dart

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1073,7 +1073,7 @@ class GitTagVersion {
10731073
/// return '1.2.3-4.5.pre-6-gabc123').
10741074
static GitTagVersion parseVersion(String version) {
10751075
final versionPattern = RegExp(
1076-
r'^(\d+)\.(\d+)\.(\d+)(-\d+\.\d+\.pre)?(?:-(\d+)-g([a-f0-9]+))?$',
1076+
r'^(\d+)\.(\d+)\.(\d+)(-\d+\.\d+\.pre)?(?:[-\.](\d+)(?:-g([a-f0-9]+))?)?$',
10771077
);
10781078
final Match? match = versionPattern.firstMatch(version.trim());
10791079
if (match == null) {
@@ -1128,14 +1128,14 @@ class GitTagVersion {
11281128
}
11291129
if (hotfix != null) {
11301130
// This is an unexpected state where untagged commits exist past a hotfix
1131-
return '$x.$y.$z+hotfix.${hotfix! + 1}.pre.$commits';
1131+
return '$x.$y.$z+hotfix.${hotfix! + 1}.pre-$commits';
11321132
}
11331133
if (devPatch != null && devVersion != null) {
11341134
// The next tag that will contain this commit will be the next candidate
11351135
// branch, which will increment the devVersion.
1136-
return '$x.$y.0-${devVersion! + 1}.0.pre.$commits';
1136+
return '$x.$y.0-${devVersion! + 1}.0.pre-$commits';
11371137
}
1138-
return '$x.$y.${z! + 1}-0.0.pre.$commits';
1138+
return '$x.$y.${z! + 1}-0.0.pre-$commits';
11391139
}
11401140
}
11411141

packages/flutter_tools/test/general.shard/version_test.dart

Lines changed: 29 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1242,7 +1242,16 @@ void main() {
12421242

12431243
// Master channel
12441244
gitTagVersion = GitTagVersion.parse('1.2.0-4.5.pre-13-g$hash');
1245-
expect(gitTagVersion.frameworkVersionFor(hash), '1.2.0-5.0.pre.13');
1245+
expect(gitTagVersion.frameworkVersionFor(hash), '1.2.0-5.0.pre-13');
1246+
expect(gitTagVersion.gitTag, '1.2.0-4.5.pre');
1247+
expect(gitTagVersion.devVersion, 4);
1248+
expect(gitTagVersion.devPatch, 5);
1249+
1250+
// Master channel
1251+
// Format from old version files used '.' instead of '-' for the commit count.
1252+
// See https://github.com/flutter/flutter/issues/172091#issuecomment-3071202443
1253+
gitTagVersion = GitTagVersion.parse('1.2.0-4.5.pre.13');
1254+
expect(gitTagVersion.frameworkVersionFor(hash), '1.2.0-5.0.pre-13');
12461255
expect(gitTagVersion.gitTag, '1.2.0-4.5.pre');
12471256
expect(gitTagVersion.devVersion, 4);
12481257
expect(gitTagVersion.devPatch, 5);
@@ -1264,7 +1273,7 @@ void main() {
12641273
expect(gitTagVersion.devPatch, 5);
12651274

12661275
gitTagVersion = GitTagVersion.parse('1.2.3-13-g$hash');
1267-
expect(gitTagVersion.frameworkVersionFor(hash), '1.2.4-0.0.pre.13');
1276+
expect(gitTagVersion.frameworkVersionFor(hash), '1.2.4-0.0.pre-13');
12681277
expect(gitTagVersion.gitTag, '1.2.3');
12691278
expect(gitTagVersion.devVersion, null);
12701279
expect(gitTagVersion.devPatch, null);
@@ -1278,14 +1287,29 @@ void main() {
12781287

12791288
// new tag release format, stable channel
12801289
gitTagVersion = GitTagVersion.parse('1.2.3-13-g$hash');
1281-
expect(gitTagVersion.frameworkVersionFor(hash), '1.2.4-0.0.pre.13');
1290+
expect(gitTagVersion.frameworkVersionFor(hash), '1.2.4-0.0.pre-13');
12821291
expect(gitTagVersion.gitTag, '1.2.3');
12831292
expect(gitTagVersion.devVersion, null);
12841293
expect(gitTagVersion.devPatch, null);
12851294

1295+
// new tag release format, beta channel, old version file format
1296+
// Format from old version files used '.' instead of '-' for the commit count.
1297+
// See https://github.com/flutter/flutter/issues/172091#issuecomment-3071202443
1298+
gitTagVersion = GitTagVersion.parse('1.2.3-4.5.pre.0');
1299+
expect(gitTagVersion.frameworkVersionFor(hash), '1.2.3-4.5.pre');
1300+
expect(gitTagVersion.gitTag, '1.2.3-4.5.pre');
1301+
expect(gitTagVersion.devVersion, 4);
1302+
expect(gitTagVersion.devPatch, 5);
1303+
12861304
expect(
12871305
GitTagVersion.parse('98.76.54-32-g$hash').frameworkVersionFor(hash),
1288-
'98.76.55-0.0.pre.32',
1306+
'98.76.55-0.0.pre-32',
1307+
);
1308+
// Format from old version files used '.' instead of '-' for the commit count.
1309+
// See https://github.com/flutter/flutter/issues/172091#issuecomment-3071202443
1310+
expect(
1311+
GitTagVersion.parse('98.76.54.32-g$hash').frameworkVersionFor(hash),
1312+
'98.76.55-0.0.pre-32',
12891313
);
12901314
expect(GitTagVersion.parse('10.20.30-0-g$hash').frameworkVersionFor(hash), '10.20.30');
12911315
expect(testLogger.traceText, '');
@@ -1379,7 +1403,7 @@ void main() {
13791403
workingDirectory: '.',
13801404
);
13811405
// reported version should increment the m
1382-
expect(gitTagVersion.frameworkVersionFor(headRevision), '1.2.0-3.0.pre.12');
1406+
expect(gitTagVersion.frameworkVersionFor(headRevision), '1.2.0-3.0.pre-12');
13831407
});
13841408

13851409
testUsingContext('determine does not call fetch --tags', () {

0 commit comments

Comments
 (0)