Skip to content

Commit 99f9215

Browse files
authored
Update version tool logic for dev versions (#4536)
1 parent be074aa commit 99f9215

File tree

2 files changed

+23
-7
lines changed

2 files changed

+23
-7
lines changed

tool/README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,8 @@ Verify:
5555

5656
These packages always have their version numbers updated in lock, so we don't have to worry about versioning.
5757

58+
> Note: Updating to a new `dev` version will automatically prepare the version for a new `minor` release (eg, `2.17.0` will become `2.18.0-dev.0`). To update to a `major` or `patch` release instead, specify either `dev,patch` or `dev,major` (eg, `dart tool/update_version.dart auto --type dev,patch`).
59+
5860
#### Update the CHANGELOG.md (for non-dev releases)
5961

6062
* Use the tool `generate-changelog` to automatically update the `packages/devtools/CHANGELOG.md` file.

tool/update_version.dart

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ void writeVersionToChangelog(File changelog, String version) {
158158
}
159159
changelog.writeAsString([
160160
versionString,
161-
'TODO: update changelog\n',
161+
isDevVersion(version) ? '* Dev version\n' : 'TODO: update changelog\n',
162162
...lines,
163163
].joinWithNewLine());
164164
}
@@ -189,8 +189,8 @@ void writeVersionToIndexHtml(
189189
indexHtml.writeAsStringSync(revisedLines.joinWithNewLine());
190190
}
191191

192-
String incrementDevVersion(String currentVersion) {
193-
final alreadyHasDevVersion = RegExp(r'-dev\.\d+').hasMatch(currentVersion);
192+
String incrementDevVersion(String currentVersion, String devType) {
193+
final alreadyHasDevVersion = isDevVersion(currentVersion);
194194
if (alreadyHasDevVersion) {
195195
final devVerMatch = RegExp(
196196
r'^(?<prefix>\d+\.\d+\.\d+.*-dev\.)(?<devVersion>\d+)(?<suffix>.*)$')
@@ -208,10 +208,15 @@ String incrementDevVersion(String currentVersion) {
208208
return newVersion;
209209
}
210210
} else {
211-
return '$currentVersion-dev.0';
211+
final nextVersion = incrementVersionByType(currentVersion, devType);
212+
return '$nextVersion-dev.0';
212213
}
213214
}
214215

216+
bool isDevVersion(String version) {
217+
return RegExp(r'-dev\.\d+').hasMatch(version);
218+
}
219+
215220
const pubspecVersionPrefix = 'version:';
216221
const editablePubspecSections = [
217222
pubspecVersionPrefix,
@@ -279,9 +284,12 @@ class AutoUpdateCommand extends Command {
279284
AutoUpdateCommand() {
280285
argParser.addOption('type',
281286
abbr: 't',
282-
allowed: ['dev', 'patch', 'minor', 'major'],
287+
allowed: ['dev', 'dev,patch', 'dev,major', 'patch', 'minor', 'major'],
283288
allowedHelp: {
284-
'dev': 'bumps the version to the next dev pre-release value',
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',
285293
'patch': 'bumps the version to the next patch value',
286294
'minor': 'bumps the version to the next minor value',
287295
'major': 'bumps the version to the next major value',
@@ -300,7 +308,13 @@ class AutoUpdateCommand extends Command {
300308
}
301309
switch (type) {
302310
case 'dev':
303-
newVersion = incrementDevVersion(currentVersion);
311+
newVersion = incrementDevVersion(currentVersion, 'minor');
312+
break;
313+
case 'dev,patch':
314+
newVersion = incrementDevVersion(currentVersion, 'patch');
315+
break;
316+
case 'dev,major':
317+
newVersion = incrementDevVersion(currentVersion, 'major');
304318
break;
305319
default:
306320
newVersion = incrementVersionByType(currentVersion, type);

0 commit comments

Comments
 (0)