Skip to content

Small fixes for the release script #2150

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 3 commits into from
Jun 21, 2023
Merged
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
42 changes: 26 additions & 16 deletions tool/release.dart
Original file line number Diff line number Diff line change
Expand Up @@ -130,8 +130,12 @@ Future<int> runRelease({
// Update the pinned version of DWDS for webdev releases.
if (package == 'webdev') {
_logInfo('Updating pinned version of DWDS.');
await _updateDwdsPin('webdev');
await _updateDwdsPin('test_common');
final newVersion = await _updateDwdsPin('webdev');
_logInfo('Add pinned DWDS info to CHANGELOG.');
final changelog = File('../webdev/CHANGELOG.md');
_addNewLine(changelog,
newLine: '- Update `dwds` constraint to `${newVersion ?? 'TODO'}`.');
}

// Remove any dependency overrides for the package:
Expand Down Expand Up @@ -229,12 +233,7 @@ void _updateVersionStrings(
final pubspec = File('../$package/pubspec.yaml');
final changelog = File('../$package/CHANGELOG.md');
if (isReset) {
final wasReplaced = _replaceInFile(
changelog,
query: currentVersion,
replaceWith: nextVersion,
);
if (!wasReplaced) _addNewLine(changelog, newLine: '## $nextVersion');
_addNewLine(changelog, newLine: '## $nextVersion');
_replaceInFile(pubspec, query: currentVersion, replaceWith: nextVersion);
} else {
for (final file in [pubspec, changelog]) {
Expand Down Expand Up @@ -296,7 +295,8 @@ String _removeWip(String wipVersion) {
return wipVersion.split('-wip').first;
}

Future<void> _updateDwdsPin(String package) async {
/// Returns the new pinned DWDS version on success.
Future<String?> _updateDwdsPin(String package) async {
final pubOutdatedProcess = await Process.run(
'dart',
[
Expand All @@ -307,21 +307,31 @@ Future<void> _updateDwdsPin(String package) async {
workingDirectory: '../$package',
);
final lines = pubOutdatedProcess.stdout.split('\n') as List<String>;
String? nextDwdsVersion;
String? currentDwdsVersion;
for (final line in lines) {
if (line.trim().startsWith('dwds')) {
final segments =
line.trim().split(' ').where((segment) => segment != ' ');
final nextVersion = segments.last;
final currentVersion =
nextDwdsVersion = segments.last;
currentDwdsVersion =
segments.lastWhere((segment) => segment.startsWith('*')).substring(1);
_logInfo('Changing DWDS pin from $currentVersion to $nextVersion');
_replaceInFile(
File('../$package/pubspec.yaml'),
query: currentVersion,
replaceWith: nextVersion,
);
break;
}
}
final next = nextDwdsVersion ?? '';
final current = currentDwdsVersion ?? '';
if (next.isNotEmpty && current.isNotEmpty) {
_logInfo('Changing DWDS pin from $current to $next');
_replaceInFile(
File('../$package/pubspec.yaml'),
query: current,
replaceWith: next,
);
return nextDwdsVersion;
}
_logWarning('Unable to determine DWDS version to pin.');
return null;
}

void _logInfo(String message) {
Expand Down