Skip to content

Commit 5123965

Browse files
committed
Update publish_command_test.dart
Update publish_command_test.dart 2 2 Update publish_command_test.dart lint Update publish_command.dart Update release_from_batch_release.yml Update release.yml clean up code Update publish_command.dart 1
1 parent 4ac035b commit 5123965

File tree

6 files changed

+139
-5
lines changed

6 files changed

+139
-5
lines changed

.github/workflows/release.yml

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,14 @@
1-
name: release
1+
name: Reusable Release
2+
23
on:
3-
push:
4-
branches:
5-
- main
4+
workflow_call:
5+
inputs:
6+
publish-args:
7+
required: true
8+
type: string
9+
workflow-name:
10+
required: true
11+
type: string
612

713
# Declare default permissions as read only.
814
permissions: read-all
@@ -82,5 +88,5 @@ jobs:
8288
run: |
8389
git config --global user.name ${{ secrets.USER_NAME }}
8490
git config --global user.email ${{ secrets.USER_EMAIL }}
85-
dart ./script/tool/lib/src/main.dart publish --all-changed --base-sha=HEAD~ --skip-confirmation --remote=origin
91+
dart ./script/tool/lib/src/main.dart publish ${{ inputs.publish-args }}
8692
env: {PUB_CREDENTIALS: "${{ secrets.PUB_CREDENTIALS }}"}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
name: Batch Release
2+
on:
3+
push:
4+
branches:
5+
- release-go-router
6+
jobs:
7+
release:
8+
uses: ./.github/workflows/release.yml
9+
with:
10+
publish-args: '--all-changed --batch-release --base-sha=HEAD~ --skip-confirmation --remote=origin'
11+
workflow-name: 'Batch Release'
12+
secrets: inherit
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
name: Main Release
2+
on:
3+
push:
4+
branches:
5+
- main
6+
jobs:
7+
release:
8+
uses: ./.github/workflows/release.yml
9+
with:
10+
publish-args: '--all-changed --base-sha=HEAD~ --skip-confirmation --remote=origin'
11+
workflow-name: 'Main Release'
12+
secrets: inherit

script/tool/lib/src/publish_command.dart

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,9 @@ class PublishCommand extends PackageLoopingCommand {
8383
'Release all packages that contains pubspec changes at the current commit compares to the base-sha.\n'
8484
'The --packages option is ignored if this is on.',
8585
);
86+
argParser.addFlag(_batchReleaseFlag,
87+
help:
88+
'only release the packages that opt-in for batch release option.');
8689
argParser.addFlag(
8790
_dryRunFlag,
8891
help:
@@ -109,6 +112,7 @@ class PublishCommand extends PackageLoopingCommand {
109112
static const String _pubFlagsOption = 'pub-publish-flags';
110113
static const String _remoteOption = 'remote';
111114
static const String _allChangedFlag = 'all-changed';
115+
static const String _batchReleaseFlag = 'batch-release';
112116
static const String _dryRunFlag = 'dry-run';
113117
static const String _skipConfirmationFlag = 'skip-confirmation';
114118
static const String _tagForAutoPublishFlag = 'tag-for-auto-publish';
@@ -196,6 +200,37 @@ class PublishCommand extends PackageLoopingCommand {
196200
.toList();
197201

198202
for (final pubspecPath in changedPubspecs) {
203+
// Read the ci_config.yaml file if it exists
204+
205+
final String packageName = p.basename(p.dirname(pubspecPath));
206+
bool isBatchReleasePackage;
207+
try {
208+
final File ciConfigFile = packagesDir.fileSystem
209+
.file(pubspecPath)
210+
.parent
211+
.childFile('ci_config.yaml');
212+
if (!ciConfigFile.existsSync()) {
213+
isBatchReleasePackage = false;
214+
} else {
215+
final YamlMap? ciConfig =
216+
loadYaml(ciConfigFile.readAsStringSync()) as YamlMap?;
217+
final dynamic batchValue = ciConfig?['release']?['batch'];
218+
if (batchValue is! bool) {
219+
printError(
220+
'`release.batch` key is missing or not a boolean in ci_config.yaml for $packageName.');
221+
continue;
222+
}
223+
isBatchReleasePackage = batchValue;
224+
}
225+
} catch (e) {
226+
printError('Could not parse ci_config.yaml for $packageName: $e');
227+
continue;
228+
}
229+
// Skip the package if batch release flag is not set to match the ci_config.yaml
230+
if (getBoolArg(_batchReleaseFlag) != isBatchReleasePackage) {
231+
continue;
232+
}
233+
199234
// git outputs a relativa, Posix-style path.
200235
final File pubspecFile = childFileWithSubcomponents(
201236
packagesDir.fileSystem.directory((await gitDir).path),

script/tool/test/publish_command_test.dart

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1284,6 +1284,56 @@ void main() {
12841284
);
12851285
});
12861286

1287+
group('--batch-release flag', () {
1288+
test('filters packages based on ci_config.yaml', () async {
1289+
// Mock packages.
1290+
final RepositoryPackage plugin1 = createFakePlugin(
1291+
'plugin1',
1292+
packagesDir,
1293+
version: '1.0.0',
1294+
batchRelease: true,
1295+
);
1296+
1297+
final RepositoryPackage plugin2 = createFakePlugin(
1298+
'plugin2',
1299+
packagesDir,
1300+
version: '1.0.0',
1301+
batchRelease: false,
1302+
);
1303+
1304+
// Mock git diff to show both packages have changed.
1305+
processRunner.mockProcessesForExecutable['git-diff'] = <FakeProcessInfo>[
1306+
FakeProcessInfo(MockProcess(
1307+
stdout:
1308+
'${plugin1.pubspecFile.path}\n${plugin2.pubspecFile.path}'))
1309+
];
1310+
1311+
// Mock pub.dev responses.
1312+
mockHttpResponses['plugin1'] = <String, dynamic>{
1313+
'name': 'plugin1',
1314+
'versions': <String>['0.0.1'],
1315+
};
1316+
mockHttpResponses['plugin2'] = <String, dynamic>{
1317+
'name': 'plugin2',
1318+
'versions': <String>['0.0.1'],
1319+
};
1320+
1321+
final List<String> output = await runCapturingPrint(
1322+
commandRunner, <String>[
1323+
'publish',
1324+
'--all-changed',
1325+
'--base-sha=HEAD~',
1326+
'--batch-release',
1327+
'--skip-confirmation'
1328+
]);
1329+
1330+
expect(output, contains('Publishing plugin1 version 1.0.0'));
1331+
expect(output, isNot(contains('Publishing plugin2 version 1.0.0')));
1332+
});
1333+
1334+
1335+
});
1336+
12871337
test('Do not release flutter_plugin_tools', () async {
12881338
mockHttpResponses['plugin1'] = <String, dynamic>{
12891339
'name': 'flutter_plugin_tools',

script/tool/test/util.dart

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@ RepositoryPackage createFakePlugin(
9696
String? version = '0.0.1',
9797
String flutterConstraint = _defaultFlutterConstraint,
9898
String dartConstraint = _defaultDartConstraint,
99+
bool? batchRelease,
99100
}) {
100101
final RepositoryPackage package = createFakePackage(
101102
name,
@@ -117,6 +118,9 @@ RepositoryPackage createFakePlugin(
117118
flutterConstraint: flutterConstraint,
118119
dartConstraint: dartConstraint,
119120
);
121+
if(batchRelease != null){
122+
createFakeCiConfig(batchRelease, package);
123+
}
120124

121125
return package;
122126
}
@@ -287,6 +291,21 @@ $pluginSection
287291
package.pubspecFile.writeAsStringSync(yaml);
288292
}
289293

294+
/// Creates a `ci_config.yaml` file for [package].
295+
void createFakeCiConfig(
296+
bool batchRelease,
297+
RepositoryPackage package,
298+
){
299+
final String yaml = '''
300+
release:
301+
batch: $batchRelease
302+
''';
303+
304+
package.ciConfigFile.createSync();
305+
package.ciConfigFile.writeAsStringSync(yaml);
306+
307+
}
308+
290309
String _pluginPlatformSection(
291310
String platform,
292311
PlatformDetails support,

0 commit comments

Comments
 (0)