Skip to content

Commit b6e6bfc

Browse files
munificentkevmoo
andauthored
Update grinder script. (#1627)
Update grinder script. The workflow for shipping dart_style used to be that we published a new version on pub and then rolled it into the Dart SDK. That meant that the dart_style version number in the SDK accurately described what was in dart_style. A few years ago, we changed to rolling into the SDK first. That lets us validate dart_style inside google3 before irrevocably publishing, which is a good thing. But it has an unfortunate side effect. If you run `dart format --version`, it shows the *previous* version number of dart_style because the version number only gets bumped when we publish. This is really confusing if you're trying to debug the formatter in the SDK and it appears to be an older version than it actually is. To fix that, I'm tweaking the workflow slightly. When we begin working on a new version of the formatter, we bump the version number in the pubspec to, say, 3.4.5-wip. At that point, we immediately update the version number constant shown by `--version` to "3.4.5" (the version it *will* be). That way, when it gets rolled into the SDK, it prints the upcoming version number. When a version of dart_style is about to be published, we remove `-wip` from the pubspec but the constant printed by `--version` is already done. To make this workflow a little less error-prone, I updated the grinder script to add tasks for starting a new patch, minor, and major version. I also updated the docs for the old task now that we use the workflow automation for publishing. Co-authored-by: Kevin Moore <[email protected]>
1 parent 67ba681 commit b6e6bfc

File tree

2 files changed

+63
-42
lines changed

2 files changed

+63
-42
lines changed

lib/src/cli/formatter_options.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import 'show.dart';
1212
import 'summary.dart';
1313

1414
// Note: The following line of code is modified by tool/grind.dart.
15-
const dartStyleVersion = '3.0.0';
15+
const dartStyleVersion = '3.0.1-wip';
1616

1717
/// Global options that affect how the formatter produces and uses its outputs.
1818
final class FormatterOptions {

tool/grind.dart

Lines changed: 62 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -26,48 +26,57 @@ Future<void> validate() async {
2626
Dart.run('bin/format.dart', arguments: ['.']);
2727
}
2828

29+
/// Increments the patch version of the current version.
30+
@Task()
31+
Future<void> patch() async {
32+
var version = _readVersion();
33+
_updateVersion(
34+
Version(version.major, version.minor, version.patch + 1, pre: 'wip'));
35+
}
36+
37+
/// Increments the minor version of the current version.
38+
@Task()
39+
Future<void> minor() async {
40+
var version = _readVersion();
41+
_updateVersion(Version(version.major, version.minor + 1, 0, pre: 'wip'));
42+
}
43+
44+
/// Increments the major version of the current version.
45+
@Task()
46+
Future<void> major() async {
47+
var version = _readVersion();
48+
_updateVersion(Version(version.major + 1, 0, 0, pre: 'wip'));
49+
}
50+
2951
/// Gets ready to publish a new version of the package.
3052
///
3153
/// To publish a version, you need to:
3254
///
33-
/// 1. Make sure the version in the pubspec is a "-dev" number. This should
34-
/// already be the case since you've already landed patches that change
35-
/// the formatter and bumped to that as a consequence.
36-
///
37-
/// 2. Run this task:
38-
///
39-
/// pub run grinder bump
40-
///
41-
/// 3. Commit the change to a branch.
42-
///
43-
/// 4. Send it out for review:
44-
///
45-
/// git cl upload
55+
/// 1. Make sure the version in the pubspec is a "-wip" number. This should
56+
/// already be the case since you've already landed patches that change
57+
/// the formatter and bumped to that as a consequence.
4658
///
47-
/// 5. After the review is complete, land it:
59+
/// 2. Run this task:
4860
///
49-
/// git cl land
61+
/// ```
62+
/// dart run grinder bump
63+
/// ```
5064
///
51-
/// 6. Tag the commit:
65+
/// 3. Commit the change to a branch, push it to GitHub, and review and merge
66+
/// it there.
5267
///
53-
/// git tag -a "<version>" -m "<version>"
54-
/// git push origin <version>
68+
/// 4. After the PR is merged using the publishing automation to publish the
69+
/// new version:
5570
///
56-
/// 7. Publish the package:
57-
///
58-
/// pub lish
71+
/// https://github.com/dart-lang/ecosystem/wiki/Publishing-automation
5972
@Task()
6073
@Depends(validate)
61-
Future<void> bump() async {
62-
// Read the version from the pubspec.
63-
var pubspecFile = getFile('pubspec.yaml');
64-
var pubspec = pubspecFile.readAsStringSync();
65-
var version =
66-
Version.parse((yaml.loadYaml(pubspec) as Map)['version'] as String);
74+
Future<void> ship() async {
75+
var version = _readVersion();
6776

68-
// Require a "-dev" version since we don't otherwise know what to bump it to.
77+
// Require a "-wip" version since we don't otherwise know what to bump it to.
6978
if (!version.isPreRelease) {
70-
throw StateError('Cannot publish non-dev version $version.');
79+
throw StateError('Cannot publish non-wip version $version.');
7180
}
7281

7382
// Don't allow versions like "1.2.3-dev+4" because it's not clear if the
@@ -76,25 +85,37 @@ Future<void> bump() async {
7685
throw StateError('Cannot publish build version $version.');
7786
}
7887

79-
var bumped = Version(version.major, version.minor, version.patch);
88+
// Remove the pre-release suffix.
89+
_updateVersion(Version(version.major, version.minor, version.patch));
90+
}
91+
92+
/// Reads the current package version from the pubspec.
93+
Version _readVersion() {
94+
var pubspecFile = getFile('pubspec.yaml');
95+
var pubspec = pubspecFile.readAsStringSync();
96+
return Version.parse((yaml.loadYaml(pubspec) as Map)['version'] as String);
97+
}
98+
99+
/// Sets version numbers in the dart_style repository with [version].
100+
void _updateVersion(Version version) {
101+
// Read the version from the pubspec.
102+
var pubspecFile = getFile('pubspec.yaml');
103+
var pubspec = pubspecFile.readAsStringSync();
80104

81105
// Update the version in the pubspec.
82-
pubspec = pubspec.replaceAll(_versionPattern, 'version: $bumped');
106+
pubspec = pubspec.replaceAll(_versionPattern, 'version: $version');
83107
pubspecFile.writeAsStringSync(pubspec);
84108

85-
// Update the version constant in formatter_options.dart.
109+
// Update the version constant in formatter_options.dart (minus any
110+
// pre-release prefix). We do this eagerly so that the version number shown
111+
// by `dart format --version` is the version that *will* be published, even
112+
// though we roll into the Dart SDK before publishing the final version.
113+
var withoutPrerelease = Version(version.major, version.minor, version.patch);
86114
var versionFile = getFile('lib/src/cli/formatter_options.dart');
87115
var versionSource = versionFile.readAsStringSync().replaceAll(
88116
RegExp(r"const dartStyleVersion = '[^']+';"),
89-
"const dartStyleVersion = '$bumped';");
117+
"const dartStyleVersion = '$withoutPrerelease';");
90118
versionFile.writeAsStringSync(versionSource);
91119

92-
// Update the version in the CHANGELOG.
93-
var changelogFile = getFile('CHANGELOG.md');
94-
var changelog = changelogFile
95-
.readAsStringSync()
96-
.replaceAll(version.toString(), bumped.toString());
97-
changelogFile.writeAsStringSync(changelog);
98-
99-
log("Updated version to '$bumped'.");
120+
log("Updated version to '$version'.");
100121
}

0 commit comments

Comments
 (0)