Skip to content

Commit 3b7f266

Browse files
authored
Small fixes for the release script (#2150)
1 parent 45446ec commit 3b7f266

File tree

1 file changed

+26
-16
lines changed

1 file changed

+26
-16
lines changed

tool/release.dart

Lines changed: 26 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -130,8 +130,12 @@ Future<int> runRelease({
130130
// Update the pinned version of DWDS for webdev releases.
131131
if (package == 'webdev') {
132132
_logInfo('Updating pinned version of DWDS.');
133-
await _updateDwdsPin('webdev');
134133
await _updateDwdsPin('test_common');
134+
final newVersion = await _updateDwdsPin('webdev');
135+
_logInfo('Add pinned DWDS info to CHANGELOG.');
136+
final changelog = File('../webdev/CHANGELOG.md');
137+
_addNewLine(changelog,
138+
newLine: '- Update `dwds` constraint to `${newVersion ?? 'TODO'}`.');
135139
}
136140

137141
// Remove any dependency overrides for the package:
@@ -229,12 +233,7 @@ void _updateVersionStrings(
229233
final pubspec = File('../$package/pubspec.yaml');
230234
final changelog = File('../$package/CHANGELOG.md');
231235
if (isReset) {
232-
final wasReplaced = _replaceInFile(
233-
changelog,
234-
query: currentVersion,
235-
replaceWith: nextVersion,
236-
);
237-
if (!wasReplaced) _addNewLine(changelog, newLine: '## $nextVersion');
236+
_addNewLine(changelog, newLine: '## $nextVersion');
238237
_replaceInFile(pubspec, query: currentVersion, replaceWith: nextVersion);
239238
} else {
240239
for (final file in [pubspec, changelog]) {
@@ -296,7 +295,8 @@ String _removeWip(String wipVersion) {
296295
return wipVersion.split('-wip').first;
297296
}
298297

299-
Future<void> _updateDwdsPin(String package) async {
298+
/// Returns the new pinned DWDS version on success.
299+
Future<String?> _updateDwdsPin(String package) async {
300300
final pubOutdatedProcess = await Process.run(
301301
'dart',
302302
[
@@ -307,21 +307,31 @@ Future<void> _updateDwdsPin(String package) async {
307307
workingDirectory: '../$package',
308308
);
309309
final lines = pubOutdatedProcess.stdout.split('\n') as List<String>;
310+
String? nextDwdsVersion;
311+
String? currentDwdsVersion;
310312
for (final line in lines) {
311313
if (line.trim().startsWith('dwds')) {
312314
final segments =
313315
line.trim().split(' ').where((segment) => segment != ' ');
314-
final nextVersion = segments.last;
315-
final currentVersion =
316+
nextDwdsVersion = segments.last;
317+
currentDwdsVersion =
316318
segments.lastWhere((segment) => segment.startsWith('*')).substring(1);
317-
_logInfo('Changing DWDS pin from $currentVersion to $nextVersion');
318-
_replaceInFile(
319-
File('../$package/pubspec.yaml'),
320-
query: currentVersion,
321-
replaceWith: nextVersion,
322-
);
319+
break;
323320
}
324321
}
322+
final next = nextDwdsVersion ?? '';
323+
final current = currentDwdsVersion ?? '';
324+
if (next.isNotEmpty && current.isNotEmpty) {
325+
_logInfo('Changing DWDS pin from $current to $next');
326+
_replaceInFile(
327+
File('../$package/pubspec.yaml'),
328+
query: current,
329+
replaceWith: next,
330+
);
331+
return nextDwdsVersion;
332+
}
333+
_logWarning('Unable to determine DWDS version to pin.');
334+
return null;
325335
}
326336

327337
void _logInfo(String message) {

0 commit comments

Comments
 (0)