Skip to content

Commit 102de85

Browse files
committed
resolve some comments
new api lint lint update tests 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 039a026 commit 102de85

File tree

6 files changed

+307
-7
lines changed

6 files changed

+307
-7
lines changed

.github/workflows/release.yml

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,18 @@
1-
name: release
1+
name: Reusable Release
22
on:
3-
push:
4-
branches:
5-
- main
6-
3+
workflow_call:
4+
inputs:
5+
publish-args:
6+
required: true
7+
type: string
8+
workflow-name:
9+
required: true
10+
type: string
11+
branch-name:
12+
required: true
13+
type: string
714
# Declare default permissions as read only.
815
permissions: read-all
9-
1016
jobs:
1117
release:
1218
if: github.repository_owner == 'flutter'
@@ -21,6 +27,7 @@ jobs:
2127
uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8
2228
with:
2329
fetch-depth: 0 # Fetch all history so the tool can get all the tags to determine version.
30+
ref: ${{ inputs.branch-name }}
2431
- name: "Install Flutter"
2532
uses: ./.github/workflows/internals/install_flutter
2633
- name: Set up tools
@@ -66,5 +73,5 @@ jobs:
6673
run: |
6774
git config --global user.name ${{ secrets.USER_NAME }}
6875
git config --global user.email ${{ secrets.USER_EMAIL }}
69-
dart ./script/tool/lib/src/main.dart publish --all-changed --base-sha=HEAD~ --skip-confirmation --remote=origin
76+
dart ./script/tool/lib/src/main.dart publish ${{ inputs.publish-args }}
7077
env: {PUB_CREDENTIALS: "${{ secrets.PUB_CREDENTIALS }}"}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
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 ${{ github.ref_name }}'
12+
branch-name: '${{ github.ref_name }}'
13+
secrets: inherit
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
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+
branch-name: 'main'
13+
secrets: inherit

script/tool/lib/src/publish_command.dart

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import 'package:platform/platform.dart';
1515
import 'package:pub_semver/pub_semver.dart';
1616
import 'package:yaml/yaml.dart';
1717

18+
import 'common/ci_config.dart';
1819
import 'common/core.dart';
1920
import 'common/file_utils.dart';
2021
import 'common/output_utils.dart';
@@ -83,6 +84,10 @@ class PublishCommand extends PackageLoopingCommand {
8384
'Release all packages that contains pubspec changes at the current commit compares to the base-sha.\n'
8485
'The --packages option is ignored if this is on.',
8586
);
87+
argParser.addFlag(
88+
_batchReleaseFlag,
89+
help: 'only release the packages that opt-in for batch release option.',
90+
);
8691
argParser.addFlag(
8792
_dryRunFlag,
8893
help:
@@ -109,6 +114,7 @@ class PublishCommand extends PackageLoopingCommand {
109114
static const String _pubFlagsOption = 'pub-publish-flags';
110115
static const String _remoteOption = 'remote';
111116
static const String _allChangedFlag = 'all-changed';
117+
static const String _batchReleaseFlag = 'batch-release';
112118
static const String _dryRunFlag = 'dry-run';
113119
static const String _skipConfirmationFlag = 'skip-confirmation';
114120
static const String _tagForAutoPublishFlag = 'tag-for-auto-publish';
@@ -196,6 +202,31 @@ class PublishCommand extends PackageLoopingCommand {
196202
.toList();
197203

198204
for (final pubspecPath in changedPubspecs) {
205+
// Read the ci_config.yaml file if it exists
206+
207+
final String packageName = p.basename(p.dirname(pubspecPath));
208+
bool isBatchReleasePackage;
209+
try {
210+
final File ciConfigFile = packagesDir.fileSystem
211+
.file(pubspecPath)
212+
.parent
213+
.childFile('ci_config.yaml');
214+
if (!ciConfigFile.existsSync()) {
215+
isBatchReleasePackage = false;
216+
} else {
217+
final CIConfig ciConfig =
218+
CIConfig.parse(ciConfigFile.readAsStringSync());
219+
isBatchReleasePackage = ciConfig.isBatchRelease;
220+
}
221+
} catch (e) {
222+
printError('Could not parse ci_config.yaml for $packageName: $e');
223+
continue;
224+
}
225+
// Skip the package if batch release flag is not set to match the ci_config.yaml
226+
if (getBoolArg(_batchReleaseFlag) != isBatchReleasePackage) {
227+
continue;
228+
}
229+
199230
// git outputs a relativa, Posix-style path.
200231
final File pubspecFile = childFileWithSubcomponents(
201232
packagesDir.fileSystem.directory((await gitDir).path),

script/tool/test/publish_command_test.dart

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

1287+
group('--batch-release flag', () {
1288+
test(
1289+
'filters packages based on the existence of ci_config.yaml',
1290+
() async {
1291+
// Mock pub.dev responses.
1292+
mockHttpResponses['plugin1'] = <String, dynamic>{
1293+
'name': 'plugin1',
1294+
'versions': <String>['0.0.1'],
1295+
};
1296+
mockHttpResponses['plugin2'] = <String, dynamic>{
1297+
'name': 'plugin2',
1298+
'versions': <String>['0.0.1'],
1299+
};
1300+
1301+
// Mock packages.
1302+
final RepositoryPackage plugin1 = createFakePlugin(
1303+
'plugin1',
1304+
packagesDir,
1305+
version: '0.0.2',
1306+
batchRelease: true,
1307+
);
1308+
1309+
final RepositoryPackage plugin2 = createFakePlugin(
1310+
'plugin2',
1311+
packagesDir,
1312+
version: '0.0.2',
1313+
);
1314+
1315+
expect(plugin1.ciConfigFile.existsSync(), true);
1316+
expect(plugin2.ciConfigFile.existsSync(), false);
1317+
1318+
// Mock git diff to show both packages have changed.
1319+
processRunner
1320+
.mockProcessesForExecutable['git-diff'] = <FakeProcessInfo>[
1321+
FakeProcessInfo(
1322+
MockProcess(
1323+
stdout:
1324+
'${plugin1.pubspecFile.path}\n${plugin2.pubspecFile.path}',
1325+
),
1326+
),
1327+
];
1328+
1329+
mockStdin.readLineOutput = 'y';
1330+
1331+
final List<String> output = await runCapturingPrint(
1332+
commandRunner,
1333+
<String>[
1334+
'publish',
1335+
'--all-changed',
1336+
'--base-sha=HEAD~',
1337+
'--batch-release',
1338+
],
1339+
);
1340+
// Package1 is published in batch realease, pacakge2 is not.
1341+
expect(
1342+
output,
1343+
containsAllInOrder(<Matcher>[
1344+
contains('Running `pub publish ` in ${plugin1.path}...'),
1345+
contains('Published plugin1 successfully!'),
1346+
]),
1347+
);
1348+
1349+
expect(
1350+
output,
1351+
isNot(
1352+
contains(
1353+
contains('Running `pub publish ` in ${plugin2.path}...!'),
1354+
),
1355+
),
1356+
);
1357+
expect(
1358+
output,
1359+
isNot(contains(contains('Published plugin2 successfully!'))),
1360+
);
1361+
},
1362+
);
1363+
1364+
test(
1365+
'filters packages based on the batch release flag value in ci_config.yaml',
1366+
() async {
1367+
// Mock pub.dev responses.
1368+
mockHttpResponses['plugin1'] = <String, dynamic>{
1369+
'name': 'plugin1',
1370+
'versions': <String>['0.0.1'],
1371+
};
1372+
mockHttpResponses['plugin2'] = <String, dynamic>{
1373+
'name': 'plugin2',
1374+
'versions': <String>['0.0.1'],
1375+
};
1376+
1377+
// Mock packages.
1378+
final RepositoryPackage plugin1 = createFakePlugin(
1379+
'plugin1',
1380+
packagesDir,
1381+
version: '0.0.2',
1382+
batchRelease: true,
1383+
);
1384+
1385+
final RepositoryPackage plugin2 = createFakePlugin(
1386+
'plugin2',
1387+
packagesDir,
1388+
version: '0.0.2',
1389+
batchRelease: false,
1390+
);
1391+
1392+
// Mock git diff to show both packages have changed.
1393+
processRunner
1394+
.mockProcessesForExecutable['git-diff'] = <FakeProcessInfo>[
1395+
FakeProcessInfo(
1396+
MockProcess(
1397+
stdout:
1398+
'${plugin1.pubspecFile.path}\n${plugin2.pubspecFile.path}',
1399+
),
1400+
),
1401+
];
1402+
1403+
mockStdin.readLineOutput = 'y';
1404+
1405+
final List<String> output = await runCapturingPrint(
1406+
commandRunner,
1407+
<String>[
1408+
'publish',
1409+
'--all-changed',
1410+
'--base-sha=HEAD~',
1411+
'--batch-release',
1412+
],
1413+
);
1414+
// Package1 is published in batch realease, pacakge2 is not.
1415+
expect(
1416+
output,
1417+
containsAllInOrder(<Matcher>[
1418+
contains('Running `pub publish ` in ${plugin1.path}...'),
1419+
contains('Published plugin1 successfully!'),
1420+
]),
1421+
);
1422+
1423+
expect(
1424+
output,
1425+
isNot(
1426+
contains(
1427+
contains('Running `pub publish ` in ${plugin2.path}...!'),
1428+
),
1429+
),
1430+
);
1431+
expect(
1432+
output,
1433+
isNot(contains(contains('Published plugin2 successfully!'))),
1434+
);
1435+
},
1436+
);
1437+
1438+
test(
1439+
'when --batch-release flag value is false, batch release packages are filtered out',
1440+
() async {
1441+
// Mock pub.dev responses.
1442+
mockHttpResponses['plugin1'] = <String, dynamic>{
1443+
'name': 'plugin1',
1444+
'versions': <String>['0.0.1'],
1445+
};
1446+
mockHttpResponses['plugin2'] = <String, dynamic>{
1447+
'name': 'plugin2',
1448+
'versions': <String>['0.0.1'],
1449+
};
1450+
1451+
// Mock packages.
1452+
final RepositoryPackage plugin1 = createFakePlugin(
1453+
'plugin1',
1454+
packagesDir,
1455+
version: '0.0.2',
1456+
);
1457+
1458+
final RepositoryPackage plugin2 = createFakePlugin(
1459+
'plugin2',
1460+
packagesDir,
1461+
version: '0.0.2',
1462+
batchRelease: true,
1463+
);
1464+
1465+
// Mock git diff to show both packages have changed.
1466+
processRunner
1467+
.mockProcessesForExecutable['git-diff'] = <FakeProcessInfo>[
1468+
FakeProcessInfo(
1469+
MockProcess(
1470+
stdout:
1471+
'${plugin1.pubspecFile.path}\n${plugin2.pubspecFile.path}',
1472+
),
1473+
),
1474+
];
1475+
1476+
mockStdin.readLineOutput = 'y';
1477+
1478+
final List<String> output = await runCapturingPrint(
1479+
commandRunner,
1480+
<String>['publish', '--all-changed', '--base-sha=HEAD~'],
1481+
);
1482+
// Package1 is published in batch realease, pacakge2 is not.
1483+
expect(
1484+
output,
1485+
containsAllInOrder(<Matcher>[
1486+
contains('Running `pub publish ` in ${plugin1.path}...'),
1487+
contains('Published plugin1 successfully!'),
1488+
]),
1489+
);
1490+
1491+
expect(
1492+
output,
1493+
isNot(
1494+
contains(
1495+
contains('Running `pub publish ` in ${plugin2.path}...!'),
1496+
),
1497+
),
1498+
);
1499+
expect(
1500+
output,
1501+
isNot(contains(contains('Published plugin2 successfully!'))),
1502+
);
1503+
},
1504+
);
1505+
});
1506+
12871507
test('Do not release flutter_plugin_tools', () async {
12881508
mockHttpResponses['plugin1'] = <String, dynamic>{
12891509
'name': 'flutter_plugin_tools',

script/tool/test/util.dart

Lines changed: 16 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,18 @@ $pluginSection
287291
package.pubspecFile.writeAsStringSync(yaml);
288292
}
289293

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

0 commit comments

Comments
 (0)