Skip to content

Commit 2d8e9c2

Browse files
authored
Adds a script for the release steps of dwds and webdev (#2049)
1 parent afee8c7 commit 2d8e9c2

File tree

4 files changed

+312
-31
lines changed

4 files changed

+312
-31
lines changed

dwds/CONTRIBUTING.md

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -83,20 +83,13 @@ the example app and connect to DWDS.
8383

8484
## Step 2: Publish DWDS to pub
8585

86-
- Make sure you are on the Dart stable SDK version (check with `dart --version`)
87-
- From each of the subdirectories (`/dwds`, `/frontend_server_client`,
88-
`/frontend_server_common`, and `/webdev`) update dependencies with
89-
`dart pub upgrade`
90-
- Update the version number in `dwds/pubspec.yaml` and `dwds/CHANGELOG.md`
91-
- From `/dwds` run `dart run build_runner build`, this will build and update the
92-
version in `/dwds/lib/src/version.dart`
93-
- Submit a PR with those changes (example PR:
94-
https://github.com/dart-lang/webdev/pull/1456). _Note: Ensure your PR doesn’t
95-
have any dependency overrides._
96-
- Once the PR is submitted, pull from master and `run dart pub publish`
97-
- Finally, go to https://github.com/dart-lang/webdev/releases and create a new
98-
release, eg https://github.com/dart-lang/webdev/releases/tag/dwds-v12.0.0. You
99-
might need to delete some of the content of the autogenerated notes.
86+
- From the `/tool` directory in the mono-repo root, run: `dart run release.dart -p dwds`
87+
- Submit a PR with those changes (example PR: https://github.com/dart-lang/webdev/pull/1456)
88+
- Once the PR is submitted, go to https://github.com/dart-lang/webdev/releases and create a new
89+
release, eg https://github.com/dart-lang/webdev/releases/tag/dwds-v12.0.0. This should trigger
90+
the auto-publisher. Verify that the package is published.
91+
- From the `/tool` directory in the mono-repo root, run: `dart run release.dart --reset -p dwds`
92+
- Submit a PR with those changes.
10093

10194
> _Note: To have the right permissions for publishing, you need to be invited to
10295
> the tools.dart.dev. A member of the Dart team should be able to add you at

tool/pubspec.yaml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
name: tool
2+
publish_to: none
3+
description: >-
4+
Common tools for the mono-repo.
5+
environment:
6+
sdk: ">=3.0.0-134.0.dev <4.0.0"
7+
8+
dev_dependencies:
9+
args: ^2.4.0

tool/release.dart

Lines changed: 287 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,287 @@
1+
// Copyright (c) 2023, the Dart project authors. Please see the AUTHORS file
2+
// for details. All rights reserved. Use of this source code is governed by a
3+
// BSD-style license that can be found in the LICENSE file.
4+
5+
import 'dart:io';
6+
7+
import 'package:args/args.dart';
8+
9+
const _packageOption = 'package';
10+
const _versionOption = 'version';
11+
const _resetFlag = 'reset';
12+
const _skipStableCheckFlag = 'skipStableCheck';
13+
14+
/// Note: Must be run from the /tool directory.
15+
///
16+
/// To prepare DWDS for release:
17+
/// `dart run release.dart -p dwds`
18+
///
19+
/// To prepare WebDev for release:
20+
/// `dart run release.dart -p webdev`
21+
///
22+
/// To reset DWDS after a release:
23+
/// `dart run release.dart --reset -p dwds -v -[[dev version]]`
24+
///
25+
/// To reset WebDev after a release:
26+
/// `dart run release.dart --reset -p webdev -v -[[dev version]]`
27+
28+
void main(List<String> arguments) async {
29+
final parser = ArgParser()
30+
..addOption(
31+
_packageOption,
32+
abbr: 'p',
33+
allowed: [
34+
'webdev',
35+
'dwds',
36+
],
37+
)
38+
..addOption(_versionOption, abbr: 'v')
39+
..addFlag(_resetFlag, abbr: 'r')
40+
..addFlag(_skipStableCheckFlag, abbr: 's');
41+
42+
final argResults = parser.parse(arguments);
43+
final package = argResults[_packageOption] as String?;
44+
if (package == null) {
45+
_logWarning('Please specify package with either --p=dwds or --p=webdev');
46+
return;
47+
}
48+
49+
final isReset = argResults[_resetFlag] as bool?;
50+
final newVersion = argResults[_versionOption] as String?;
51+
final skipStableCheck = argResults[_skipStableCheckFlag] as bool?;
52+
53+
int exitCode;
54+
if (isReset == true) {
55+
exitCode = runReset(
56+
package: package,
57+
newVersion: newVersion,
58+
);
59+
} else {
60+
exitCode = await runRelease(
61+
package: package,
62+
newVersion: newVersion,
63+
skipStableCheck: skipStableCheck,
64+
);
65+
}
66+
if (exitCode != 0) {
67+
_logWarning('Run terminated unexpectedly with exit code: $exitCode');
68+
}
69+
}
70+
71+
int runReset({
72+
required String package,
73+
String? newVersion,
74+
}) {
75+
// Check that a new dev version has been provided.
76+
final currentVersion = _readVersionFile(package);
77+
if (newVersion == null || !newVersion.contains('dev')) {
78+
_logInfo(
79+
'''
80+
Please provide the next dev version for $package, e.g. -v 3.0.1-dev
81+
Current version is $currentVersion.
82+
''',
83+
);
84+
return 1;
85+
}
86+
87+
// Update the version strings in CHANGELOG and pubspec.yaml.
88+
_updateVersionStrings(
89+
package,
90+
currentVersion: currentVersion,
91+
nextVersion: newVersion,
92+
isReset: true,
93+
);
94+
95+
return 0;
96+
}
97+
98+
Future<int> runRelease({
99+
required String package,
100+
String? newVersion,
101+
bool? skipStableCheck,
102+
}) async {
103+
// Check that we are on a stable version of Dart.
104+
if (skipStableCheck != true) {
105+
final checkVersionProcess = await Process.run('dart', ['--version']);
106+
final versionInfo = checkVersionProcess.stdout as String;
107+
if (!versionInfo.contains('stable')) {
108+
_logWarning(
109+
'''
110+
Expected to be on stable version of Dart, instead on:
111+
$versionInfo
112+
To skip this check, re-run with --skipStableCheck
113+
''',
114+
);
115+
return checkVersionProcess.exitCode;
116+
}
117+
}
118+
119+
// Update the pinned version of DWDS for webdev releases.
120+
if (package == 'webdev') {
121+
_logInfo('Updating pinned version of DWDS.');
122+
await _updateDwdsPin(package);
123+
}
124+
125+
// Run dart pub upgrade.
126+
for (final packagePath in [
127+
'../dwds',
128+
'../webdev',
129+
'../frontend_server_common',
130+
'../frontend_server_client',
131+
'../test_common',
132+
]) {
133+
_logInfo('Upgrading pub packages for $packagePath');
134+
final pubUpgradeProcess = await Process.run(
135+
'dart',
136+
[
137+
'pub',
138+
'upgrade',
139+
],
140+
workingDirectory: packagePath,
141+
);
142+
final upgradeErrors = pubUpgradeProcess.stderr as String;
143+
if (upgradeErrors.isNotEmpty) {
144+
_logWarning(upgradeErrors);
145+
return pubUpgradeProcess.exitCode;
146+
}
147+
}
148+
149+
// Update the version strings in CHANGELOG and pubspec.yaml.
150+
final currentVersion = _readVersionFile(package);
151+
final nextVersion = newVersion ?? _removeDev(currentVersion);
152+
_updateVersionStrings(
153+
package,
154+
currentVersion: currentVersion,
155+
nextVersion: nextVersion,
156+
);
157+
158+
// Build the package.
159+
final exitCode = _buildPackage(package);
160+
return exitCode;
161+
}
162+
163+
Future<int> _buildPackage(String package) async {
164+
_logInfo('Building $package');
165+
final buildProcess = await Process.run(
166+
'dart',
167+
['run', 'build_runner', 'build'],
168+
workingDirectory: '../$package',
169+
);
170+
171+
final buildErrors = buildProcess.stderr as String;
172+
if (buildErrors.isNotEmpty) {
173+
_logWarning(buildErrors);
174+
}
175+
return buildProcess.exitCode;
176+
}
177+
178+
void _updateVersionStrings(
179+
String package, {
180+
required String nextVersion,
181+
required String currentVersion,
182+
bool isReset = false,
183+
}) {
184+
_logInfo('Updating $package from $currentVersion to $nextVersion');
185+
final pubspec = File('../$package/pubspec.yaml');
186+
final changelog = File('../$package/CHANGELOG.md');
187+
if (isReset) {
188+
_addNewLine(changelog, newLine: '## $nextVersion');
189+
_replaceInFile(pubspec, query: currentVersion, replaceWith: nextVersion);
190+
} else {
191+
for (final file in [pubspec, changelog]) {
192+
_replaceInFile(file, query: currentVersion, replaceWith: nextVersion);
193+
}
194+
}
195+
}
196+
197+
void _addNewLine(
198+
File file, {
199+
required String newLine,
200+
}) {
201+
final newLines = [newLine, '', ...file.readAsLinesSync()];
202+
final content = newLines.joinWithNewLine();
203+
return file.writeAsStringSync(content);
204+
}
205+
206+
void _replaceInFile(
207+
File file, {
208+
required String query,
209+
required String replaceWith,
210+
}) {
211+
final newLines = <String>[];
212+
for (final line in file.readAsLinesSync()) {
213+
if (line.contains(query)) {
214+
newLines.add(line.replaceAll(query, replaceWith));
215+
} else {
216+
newLines.add(line);
217+
}
218+
}
219+
final content = newLines.joinWithNewLine();
220+
return file.writeAsStringSync(content);
221+
}
222+
223+
String _readVersionFile(String package) {
224+
final versionFile = File('../$package/lib/src/version.dart');
225+
final lines = versionFile.readAsLinesSync();
226+
for (final line in lines) {
227+
if (line.startsWith('const packageVersion =')) {
228+
final version = line
229+
.split('=')
230+
.last
231+
.split('')
232+
.where((char) => char != ';' && char != "'" && char != '"')
233+
.join('');
234+
return version.trim();
235+
}
236+
}
237+
throw Exception('Could not read version in $package/lib/src/version.dart');
238+
}
239+
240+
String _removeDev(String devVersion) {
241+
if (!devVersion.contains('dev')) {
242+
throw Exception('$devVersion is not a dev version.');
243+
}
244+
return devVersion.split('-dev').first;
245+
}
246+
247+
Future<void> _updateDwdsPin(String package) async {
248+
final pubOutdatedProcess = await Process.run(
249+
'dart',
250+
[
251+
'pub',
252+
'outdated',
253+
'--no-dependency-overrides',
254+
],
255+
workingDirectory: '../$package',
256+
);
257+
final lines = pubOutdatedProcess.stdout.split('\n') as List<String>;
258+
for (final line in lines) {
259+
if (line.trim().startsWith('dwds')) {
260+
final segments =
261+
line.trim().split(' ').where((segment) => segment != ' ');
262+
final nextVersion = segments.last;
263+
final currentVersion =
264+
segments.lastWhere((segment) => segment.startsWith('*')).substring(1);
265+
_logInfo('Changing DWDS pin from $currentVersion to $nextVersion');
266+
_replaceInFile(
267+
File('../$package/pubspec.yaml'),
268+
query: currentVersion,
269+
replaceWith: nextVersion,
270+
);
271+
}
272+
}
273+
}
274+
275+
void _logInfo(String message) {
276+
stdout.writeln(message);
277+
}
278+
279+
void _logWarning(String warning) {
280+
stderr.writeln(warning);
281+
}
282+
283+
extension JoinExtension on List<String> {
284+
String joinWithNewLine() {
285+
return '${join('\n')}\n';
286+
}
287+
}

webdev/CONTRIBUTING.md

Lines changed: 9 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,13 @@
11
## Instructions on releasing Webdev
22

3-
- Make sure you are on the Dart stable SDK version (check with `dart --version`)
4-
- Update the DWDS version in `/webdev/pubspec.yaml` to match the newly released
5-
DWDS version, and update the Webdev version to the new version number. Also,
6-
comment out the dependency_override so that Webdev is now depending on the
7-
version of DWDS on pub (which should have just been published) instead of the
8-
local version.
9-
- Update `/webdev/CHANGELOG.md` to match the new webdev version
10-
- From `/webdev`, run `dart pub upgrade`
11-
- From `/webdev` run `dart run build_runner build`, this will build and update
12-
the version in `webdev/lib/src/version.dart`
13-
- Before submitting your PR, test that everything is working by following
3+
- From the `/tool` directory in the mono-repo root, run: `dart run release.dart -p webdev`
4+
- Open a PR with those changes (example PR:
5+
https://github.com/dart-lang/webdev/pull/1498)
6+
- Note: Before submitting your PR, test that everything is working by following
147
instructions in the `webdev/example` [README](/example/README.md) to run the
158
example app and connect to Dart DevTools.
16-
- Submit a PR with those changes (example PR:
17-
https://github.com/dart-lang/webdev/pull/1498)
18-
- Once the PR is submitted, pull from master and run `dart pub publish`
19-
- Finally, go to https://github.com/dart-lang/webdev/releases and create a new
20-
release, eg https://github.com/dart-lang/webdev/releases/tag/webdev-v2.7.8.
21-
You might need to delete some of the content of the autogenerated notes.
9+
- Once the PR is submitted, go to https://github.com/dart-lang/webdev/releases and create a new
10+
release, eg https://github.com/dart-lang/webdev/releases/tag/webdev-3.0.0. This should trigger
11+
the auto-publisher. Verify that the package is published.
12+
- From the `/tool` directory in the mono-repo root, run: `dart run release.dart --reset -p webdev`
13+
- Submit a PR with those changes.

0 commit comments

Comments
 (0)