Skip to content

Update version tool logic for dev versions #4536

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 7 commits into from
Oct 7, 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
2 changes: 2 additions & 0 deletions tool/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ Verify:

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

> 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`).

#### Update the CHANGELOG.md (for non-dev releases)

* Use the tool `generate-changelog` to automatically update the `packages/devtools/CHANGELOG.md` file.
Expand Down
28 changes: 21 additions & 7 deletions tool/update_version.dart
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ void writeVersionToChangelog(File changelog, String version) {
}
changelog.writeAsString([
versionString,
'TODO: update changelog\n',
isDevVersion(version) ? '* Dev version\n' : 'TODO: update changelog\n',
...lines,
].joinWithNewLine());
}
Expand Down Expand Up @@ -189,8 +189,8 @@ void writeVersionToIndexHtml(
indexHtml.writeAsStringSync(revisedLines.joinWithNewLine());
}

String incrementDevVersion(String currentVersion) {
final alreadyHasDevVersion = RegExp(r'-dev\.\d+').hasMatch(currentVersion);
String incrementDevVersion(String currentVersion, String devType) {
final alreadyHasDevVersion = isDevVersion(currentVersion);
if (alreadyHasDevVersion) {
final devVerMatch = RegExp(
r'^(?<prefix>\d+\.\d+\.\d+.*-dev\.)(?<devVersion>\d+)(?<suffix>.*)$')
Expand All @@ -208,10 +208,15 @@ String incrementDevVersion(String currentVersion) {
return newVersion;
}
} else {
return '$currentVersion-dev.0';
final nextVersion = incrementVersionByType(currentVersion, devType);
return '$nextVersion-dev.0';
}
}

bool isDevVersion(String version) {
return RegExp(r'-dev\.\d+').hasMatch(version);
}

const pubspecVersionPrefix = 'version:';
const editablePubspecSections = [
pubspecVersionPrefix,
Expand Down Expand Up @@ -279,9 +284,12 @@ class AutoUpdateCommand extends Command {
AutoUpdateCommand() {
argParser.addOption('type',
abbr: 't',
allowed: ['dev', 'patch', 'minor', 'major'],
allowed: ['dev', 'dev,patch', 'dev,major', 'patch', 'minor', 'major'],
allowedHelp: {
'dev': 'bumps the version to the next dev pre-release value',
'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',
Expand All @@ -300,7 +308,13 @@ class AutoUpdateCommand extends Command {
}
switch (type) {
case 'dev':
newVersion = incrementDevVersion(currentVersion);
newVersion = incrementDevVersion(currentVersion, 'minor');
break;
case 'dev,patch':
newVersion = incrementDevVersion(currentVersion, 'patch');
break;
case 'dev,major':
newVersion = incrementDevVersion(currentVersion, 'major');
break;
default:
newVersion = incrementVersionByType(currentVersion, type);
Expand Down