Skip to content

Update-version script changes #4910

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 16 commits into from
Dec 12, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions tool/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,10 @@ Run the `tool/update_version.dart` script to update the DevTools version.
```shell
dart tool/update_version.dart auto --type patch
```
- Pre-release versions can be stripped with:
```shell
dart tool/update_version.dart auto --type release
```

Verify:
* that this script updated the pubspecs under packages/
Expand Down
100 changes: 72 additions & 28 deletions tool/update_version.dart
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ void writeVersionToIndexHtml(
indexHtml.writeAsStringSync(revisedLines.joinWithNewLine());
}

String incrementDevVersion(String currentVersion, String devType) {
String incrementDevVersion(String currentVersion) {
final alreadyHasDevVersion = isDevVersion(currentVersion);
if (alreadyHasDevVersion) {
final devVerMatch = RegExp(
Expand All @@ -208,8 +208,17 @@ String incrementDevVersion(String currentVersion, String devType) {
return newVersion;
}
} else {
final nextVersion = incrementVersionByType(currentVersion, devType);
return '$nextVersion-dev.0';
return '$currentVersion-dev.0';
}
}

String stripPreReleases(String currentVersion) {
final devVerMatch =
RegExp(r'^(?<semver>\d+\.\d+\.\d+).*$').firstMatch(currentVersion);
if (devVerMatch == null) {
throw 'Could not strip pre-releases from version: $currentVersion';
} else {
return devVerMatch.namedGroup('semver')!;
}
}

Expand Down Expand Up @@ -280,48 +289,83 @@ class AutoUpdateCommand extends Command {
final name = 'auto';
@override
final description = 'Automatically update devtools to a new version.';

AutoUpdateCommand() {
argParser.addOption('type',
abbr: 't',
allowed: ['dev', 'dev,patch', 'dev,major', 'patch', 'minor', 'major'],
allowedHelp: {
'dev':
'bumps the version to the next dev pre-release value (minor by default)',
'dev,patch': 'bumps the version to the next dev pre-patch value',
'dev,major': 'bumps the version to the next dev pre-major value',
'patch': 'bumps the version to the next patch value',
'minor': 'bumps the version to the next minor value',
'major': 'bumps the version to the next major value',
},
mandatory: true,
help: 'Bumps the devtools version by the selected type.');
argParser.addOption(
'type',
abbr: 't',
allowed: ['release', 'dev', 'patch', 'minor', 'major'],
allowedHelp: {
'release': [
'strips any pre-release versions from the version.',
'Examples:',
'\t1.2.3 => 1.2.3',
'\t1.2.3-dev.4 => 1.2.3',
].join('\n'),
'dev': [
'bumps the version to the next dev pre-release value (minor by default).',
'Examples:',
'\t1.2.3 => 1.2.3-dev.0',
'\t1.2.3-dev.4 => 1.2.3-dev.5',
].join('\n'),
'patch': [
'bumps the version to the next patch value.',
'Examples:',
'\t1.2.3 => 1.2.4',
'\t1.2.3-dev.4 => 1.2.4',
].join('\n'),
'minor': [
'bumps the version to the next minor value.',
'Examples:',
'\t1.2.3 => 1.3.0',
'\t1.2.3-dev.4 => 1.3.0',
].join('\n'),
'major': [
'bumps the version to the next major value.',
'Examples:',
'\t1.2.3 => 2.0.0',
'\t1.2.3-dev.4 => 2.0.0',
].join('\n'),
},
mandatory: true,
help: 'Bumps the devtools version by the selected type.',
);
argParser.addFlag(
'dry-run',
abbr: 'd',
defaultsTo: false,
help: 'Displays the version change that would happen, without performing '
'it.',
);
}

@override
void run() {
void run() async {
final type = argResults!['type'].toString();
final isDryRun = argResults!['dry-run'];
final currentVersion = versionFromPubspecFile();
String? newVersion;
if (currentVersion == null) {
throw 'Could not automatically determine current version.';
}
switch (type) {
case 'dev':
newVersion = incrementDevVersion(currentVersion, 'minor');
break;
case 'dev,patch':
newVersion = incrementDevVersion(currentVersion, 'patch');
case 'release':
newVersion = stripPreReleases(currentVersion);
break;
case 'dev,major':
newVersion = incrementDevVersion(currentVersion, 'major');
case 'dev':
newVersion = incrementDevVersion(currentVersion);
break;
default:
newVersion = incrementVersionByType(currentVersion, type);
if (newVersion == null) {
throw 'Failed to determine the newVersion.';
}
}
if (newVersion == null) {
throw 'Failed to determine the newVersion.';
print('Updating from $currentVersion to $newVersion');

if (isDryRun) {
return;
}

performTheVersionUpdate(
currentVersion: currentVersion,
newVersion: newVersion,
Expand Down