Skip to content

Commit b201825

Browse files
committed
update
1 parent 54fe963 commit b201825

File tree

2 files changed

+28
-36
lines changed

2 files changed

+28
-36
lines changed

script/tool/lib/src/branch_for_batch_release_command.dart

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,13 @@ class BranchForBatchReleaseCommand extends PackageCommand {
3636
'branch',
3737
mandatory: true,
3838
abbr: 'b',
39-
help: 'The branch to push the release PR to.',
39+
help: 'The branch name to contain the release commit',
40+
);
41+
argParser.addOption(
42+
'remote',
43+
mandatory: true,
44+
abbr: 'r',
45+
help: 'The remote to push the branch to.',
4046
);
4147
}
4248

@@ -86,7 +92,7 @@ class BranchForBatchReleaseCommand extends PackageCommand {
8692
return;
8793
}
8894

89-
await _createReleaseBranch(
95+
await _generateCommitAndBranch(
9096
git: repository,
9197
package: package,
9298
branchName: branchName,
@@ -146,7 +152,7 @@ class BranchForBatchReleaseCommand extends PackageCommand {
146152
return _ReleaseInfo(newVersion, changelogs);
147153
}
148154

149-
Future<void> _createReleaseBranch({
155+
Future<void> _generateCommitAndBranch({
150156
required GitDir git,
151157
required RepositoryPackage package,
152158
required String branchName,
@@ -171,15 +177,13 @@ class BranchForBatchReleaseCommand extends PackageCommand {
171177
}
172178

173179
void _updatePubspec(RepositoryPackage package, Version newVersion) {
174-
print(' Updating pubspec.yaml to version $newVersion...');
175180
final YamlEditor editablePubspec =
176181
YamlEditor(package.pubspecFile.readAsStringSync());
177182
editablePubspec.update(<String>['version'], newVersion.toString());
178183
package.pubspecFile.writeAsStringSync(editablePubspec.toString());
179184
}
180185

181186
void _updateChangelog(RepositoryPackage package, _ReleaseInfo releaseInfo) {
182-
print(' Updating CHANGELOG.md...');
183187
final String newHeader = '## ${releaseInfo.newVersion}';
184188
final List<String> newEntries = releaseInfo.changelogs;
185189

@@ -197,7 +201,6 @@ class BranchForBatchReleaseCommand extends PackageCommand {
197201

198202
Future<void> _removePendingChangelogs(
199203
GitDir git, List<File> pendingChangelogFiles) async {
200-
print(' Removing pending changelog files...');
201204
for (final File file in pendingChangelogFiles) {
202205
final io.ProcessResult rmResult =
203206
await git.runCommand(<String>['rm', file.path]);
@@ -210,19 +213,17 @@ class BranchForBatchReleaseCommand extends PackageCommand {
210213

211214
Future<void> _stageAndCommitChanges(
212215
GitDir git, RepositoryPackage package) async {
213-
print(' Staging changes...');
214216
final io.ProcessResult addResult = await git.runCommand(
215217
<String>['add', package.pubspecFile.path, package.changelogFile.path]);
216218
if (addResult.exitCode != 0) {
217219
printError('Failed to git add: ${addResult.stderr}');
218220
throw ToolExit(_kGitFailedToPush);
219221
}
220222

221-
print(' Committing changes...');
222223
final io.ProcessResult commitResult = await git.runCommand(<String>[
223224
'commit',
224225
'-m',
225-
'${package.displayName}: Prepare for release'
226+
'[${package.displayName}] Prepares for batch release'
226227
]);
227228
if (commitResult.exitCode != 0) {
228229
printError('Failed to commit: ${commitResult.stderr}');
@@ -232,7 +233,7 @@ class BranchForBatchReleaseCommand extends PackageCommand {
232233

233234
Future<void> _pushBranch(
234235
GitDir git, String remoteName, String branchName) async {
235-
print(' Pushing to remote...');
236+
print(' Pushing branch ${branchName} to remote ${remoteName}...');
236237
final io.ProcessResult pushResult =
237238
await git.runCommand(<String>['push', remoteName, branchName]);
238239
if (pushResult.exitCode != 0) {

script/tool/test/branch_for_batch_release_command_test.dart

Lines changed: 17 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,13 @@ version: 1.0.0
6262
package.directory.deleteSync(recursive: true);
6363
});
6464

65+
Future<List<String>> runBatchCommand() => runCapturingPrint(runner, <String>[
66+
'branch-for-batch-release',
67+
'--packages=a_package',
68+
'--branch=release-branch',
69+
'--remote=origin'
70+
]);
71+
6572
Future<void> testReleaseBranch({
6673
required Map<String, String> changelogs,
6774
required List<String> expectedOutput,
@@ -73,11 +80,7 @@ version: 1.0.0
7380
createChangelogFile(entry.key, entry.value);
7481
}
7582

76-
final List<String> output = await runCapturingPrint(runner, <String>[
77-
'branch-for-batch-release',
78-
'--packages=a_package',
79-
'--branch=release-branch',
80-
]);
83+
final List<String> output = await runBatchCommand();
8184

8285
expect(output, containsAllInOrder(expectedOutput));
8386

@@ -106,10 +109,8 @@ version: minor
106109
expectedChangelogSnippets: <String>['A new feature'],
107110
expectedOutput: <String>[
108111
'Parsing package "a_package"...',
109-
'Creating and pushing release branch...',
110112
' Creating new branch "release-branch"...',
111-
' Updating pubspec.yaml to version 1.1.0...',
112-
' Updating CHANGELOG.md...',
113+
' Pushing branch release-branch to remote origin...',
113114
],
114115
expectedGitCommands: <ProcessCall>[
115116
const ProcessCall(
@@ -124,7 +125,7 @@ version: minor
124125
],
125126
null),
126127
const ProcessCall('git-commit',
127-
<String>['-m', 'a_package: Prepare for release'], null),
128+
<String>['-m', '[a_package] Prepares for batch release'], null),
128129
const ProcessCall(
129130
'git-push', <String>['origin', 'release-branch'], null),
130131
],
@@ -143,10 +144,8 @@ version: major
143144
expectedChangelogSnippets: <String>['A new feature'],
144145
expectedOutput: <String>[
145146
'Parsing package "a_package"...',
146-
'Creating and pushing release branch...',
147147
' Creating new branch "release-branch"...',
148-
' Updating pubspec.yaml to version 2.0.0...',
149-
' Updating CHANGELOG.md...',
148+
' Pushing branch release-branch to remote origin...',
150149
],
151150
expectedGitCommands: <ProcessCall>[
152151
const ProcessCall(
@@ -161,7 +160,7 @@ version: major
161160
],
162161
null),
163162
const ProcessCall('git-commit',
164-
<String>['-m', 'a_package: Prepare for release'], null),
163+
<String>['-m', '[a_package] Prepares for batch release'], null),
165164
const ProcessCall(
166165
'git-push', <String>['origin', 'release-branch'], null),
167166
],
@@ -180,10 +179,8 @@ version: patch
180179
expectedChangelogSnippets: <String>['A new feature'],
181180
expectedOutput: <String>[
182181
'Parsing package "a_package"...',
183-
'Creating and pushing release branch...',
184182
' Creating new branch "release-branch"...',
185-
' Updating pubspec.yaml to version 1.0.1...',
186-
' Updating CHANGELOG.md...',
183+
' Pushing branch release-branch to remote origin...',
187184
],
188185
expectedGitCommands: <ProcessCall>[
189186
const ProcessCall(
@@ -198,7 +195,7 @@ version: patch
198195
],
199196
null),
200197
const ProcessCall('git-commit',
201-
<String>['-m', 'a_package: Prepare for release'], null),
198+
<String>['-m', '[a_package] Prepares for batch release'], null),
202199
const ProcessCall(
203200
'git-push', <String>['origin', 'release-branch'], null),
204201
],
@@ -224,10 +221,8 @@ version: major
224221
],
225222
expectedOutput: <String>[
226223
'Parsing package "a_package"...',
227-
'Creating and pushing release branch...',
228224
' Creating new branch "release-branch"...',
229-
' Updating pubspec.yaml to version 2.0.0...',
230-
' Updating CHANGELOG.md...',
225+
' Pushing branch release-branch to remote origin...',
231226
],
232227
expectedGitCommands: <ProcessCall>[
233228
const ProcessCall(
@@ -244,7 +239,7 @@ version: major
244239
],
245240
null),
246241
const ProcessCall('git-commit',
247-
<String>['-m', 'a_package: Prepare for release'], null),
242+
<String>['-m', '[a_package] Prepares for batch release'], null),
248243
const ProcessCall(
249244
'git-push', <String>['origin', 'release-branch'], null),
250245
],
@@ -295,11 +290,7 @@ version: major
295290
];
296291
Object? error;
297292
try {
298-
await runCapturingPrint(runner, <String>[
299-
'branch-for-batch-release',
300-
'--packages=a_package',
301-
'--branch=release-branch',
302-
]);
293+
await runBatchCommand();
303294
} catch (e) {
304295
error = e;
305296
}

0 commit comments

Comments
 (0)