Skip to content

Commit 2a4139e

Browse files
authored
Update-version script changes (flutter#4910)
a --dry-run flag has been added to print information about what kind of update will happen a --type release has been added which strips the any pre release versions The different types of auto update now only update their respected part of the semver
1 parent 2b98deb commit 2a4139e

File tree

2 files changed

+76
-28
lines changed

2 files changed

+76
-28
lines changed

tool/README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,10 @@ Run the `tool/update_version.dart` script to update the DevTools version.
4646
```shell
4747
dart tool/update_version.dart auto --type patch
4848
```
49+
- Pre-release versions can be stripped with:
50+
```shell
51+
dart tool/update_version.dart auto --type release
52+
```
4953

5054
Verify:
5155
* that this script updated the pubspecs under packages/

tool/update_version.dart

Lines changed: 72 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ void writeVersionToIndexHtml(
189189
indexHtml.writeAsStringSync(revisedLines.joinWithNewLine());
190190
}
191191

192-
String incrementDevVersion(String currentVersion, String devType) {
192+
String incrementDevVersion(String currentVersion) {
193193
final alreadyHasDevVersion = isDevVersion(currentVersion);
194194
if (alreadyHasDevVersion) {
195195
final devVerMatch = RegExp(
@@ -208,8 +208,17 @@ String incrementDevVersion(String currentVersion, String devType) {
208208
return newVersion;
209209
}
210210
} else {
211-
final nextVersion = incrementVersionByType(currentVersion, devType);
212-
return '$nextVersion-dev.0';
211+
return '$currentVersion-dev.0';
212+
}
213+
}
214+
215+
String stripPreReleases(String currentVersion) {
216+
final devVerMatch =
217+
RegExp(r'^(?<semver>\d+\.\d+\.\d+).*$').firstMatch(currentVersion);
218+
if (devVerMatch == null) {
219+
throw 'Could not strip pre-releases from version: $currentVersion';
220+
} else {
221+
return devVerMatch.namedGroup('semver')!;
213222
}
214223
}
215224

@@ -280,48 +289,83 @@ class AutoUpdateCommand extends Command {
280289
final name = 'auto';
281290
@override
282291
final description = 'Automatically update devtools to a new version.';
283-
284292
AutoUpdateCommand() {
285-
argParser.addOption('type',
286-
abbr: 't',
287-
allowed: ['dev', 'dev,patch', 'dev,major', 'patch', 'minor', 'major'],
288-
allowedHelp: {
289-
'dev':
290-
'bumps the version to the next dev pre-release value (minor by default)',
291-
'dev,patch': 'bumps the version to the next dev pre-patch value',
292-
'dev,major': 'bumps the version to the next dev pre-major value',
293-
'patch': 'bumps the version to the next patch value',
294-
'minor': 'bumps the version to the next minor value',
295-
'major': 'bumps the version to the next major value',
296-
},
297-
mandatory: true,
298-
help: 'Bumps the devtools version by the selected type.');
293+
argParser.addOption(
294+
'type',
295+
abbr: 't',
296+
allowed: ['release', 'dev', 'patch', 'minor', 'major'],
297+
allowedHelp: {
298+
'release': [
299+
'strips any pre-release versions from the version.',
300+
'Examples:',
301+
'\t1.2.3 => 1.2.3',
302+
'\t1.2.3-dev.4 => 1.2.3',
303+
].join('\n'),
304+
'dev': [
305+
'bumps the version to the next dev pre-release value (minor by default).',
306+
'Examples:',
307+
'\t1.2.3 => 1.2.3-dev.0',
308+
'\t1.2.3-dev.4 => 1.2.3-dev.5',
309+
].join('\n'),
310+
'patch': [
311+
'bumps the version to the next patch value.',
312+
'Examples:',
313+
'\t1.2.3 => 1.2.4',
314+
'\t1.2.3-dev.4 => 1.2.4',
315+
].join('\n'),
316+
'minor': [
317+
'bumps the version to the next minor value.',
318+
'Examples:',
319+
'\t1.2.3 => 1.3.0',
320+
'\t1.2.3-dev.4 => 1.3.0',
321+
].join('\n'),
322+
'major': [
323+
'bumps the version to the next major value.',
324+
'Examples:',
325+
'\t1.2.3 => 2.0.0',
326+
'\t1.2.3-dev.4 => 2.0.0',
327+
].join('\n'),
328+
},
329+
mandatory: true,
330+
help: 'Bumps the devtools version by the selected type.',
331+
);
332+
argParser.addFlag(
333+
'dry-run',
334+
abbr: 'd',
335+
defaultsTo: false,
336+
help: 'Displays the version change that would happen, without performing '
337+
'it.',
338+
);
299339
}
300340

301341
@override
302-
void run() {
342+
void run() async {
303343
final type = argResults!['type'].toString();
344+
final isDryRun = argResults!['dry-run'];
304345
final currentVersion = versionFromPubspecFile();
305346
String? newVersion;
306347
if (currentVersion == null) {
307348
throw 'Could not automatically determine current version.';
308349
}
309350
switch (type) {
310-
case 'dev':
311-
newVersion = incrementDevVersion(currentVersion, 'minor');
312-
break;
313-
case 'dev,patch':
314-
newVersion = incrementDevVersion(currentVersion, 'patch');
351+
case 'release':
352+
newVersion = stripPreReleases(currentVersion);
315353
break;
316-
case 'dev,major':
317-
newVersion = incrementDevVersion(currentVersion, 'major');
354+
case 'dev':
355+
newVersion = incrementDevVersion(currentVersion);
318356
break;
319357
default:
320358
newVersion = incrementVersionByType(currentVersion, type);
359+
if (newVersion == null) {
360+
throw 'Failed to determine the newVersion.';
361+
}
321362
}
322-
if (newVersion == null) {
323-
throw 'Failed to determine the newVersion.';
363+
print('Updating from $currentVersion to $newVersion');
364+
365+
if (isDryRun) {
366+
return;
324367
}
368+
325369
performTheVersionUpdate(
326370
currentVersion: currentVersion,
327371
newVersion: newVersion,

0 commit comments

Comments
 (0)