Skip to content

Commit aba6520

Browse files
committed
Update release_from_batch_release.yml
Update release.yml clean up code Update publish_command.dart 1
1 parent 7d57d12 commit aba6520

File tree

4 files changed

+68
-6
lines changed

4 files changed

+68
-6
lines changed

.github/workflows/release.yml

Lines changed: 12 additions & 6 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
86-
env: {PUB_CREDENTIALS: "${{ secrets.PUB_CREDENTIALS }}"}
91+
dart ./script/tool/lib/src/main.dart publish ${{ inputs.publish-args }}
92+
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
6+
jobs:
7+
release:
8+
uses: ./.github/workflows/reusable_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/reusable_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: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,11 @@ class PublishCommand extends PackageLoopingCommand {
7878
'Release all packages that contains pubspec changes at the current commit compares to the base-sha.\n'
7979
'The --packages option is ignored if this is on.',
8080
);
81+
argParser.addFlag(
82+
_batchReleaseFlag,
83+
help:
84+
'only release the packages that opt-in for batch release option.'
85+
)
8186
argParser.addFlag(
8287
_dryRunFlag,
8388
help:
@@ -99,6 +104,7 @@ class PublishCommand extends PackageLoopingCommand {
99104
static const String _pubFlagsOption = 'pub-publish-flags';
100105
static const String _remoteOption = 'remote';
101106
static const String _allChangedFlag = 'all-changed';
107+
static const String _batchReleaseFlag = 'batch-release';
102108
static const String _dryRunFlag = 'dry-run';
103109
static const String _skipConfirmationFlag = 'skip-confirmation';
104110
static const String _tagForAutoPublishFlag = 'tag-for-auto-publish';
@@ -182,6 +188,32 @@ class PublishCommand extends PackageLoopingCommand {
182188
.toList();
183189

184190
for (final String pubspecPath in changedPubspecs) {
191+
// Read the ci_config.yaml file
192+
193+
final String packageName = p.basename(p.dirname(pubspecPath));
194+
bool isBatchReleasePackage;
195+
try {
196+
final File ciConfigFile = packagesDir.fileSystem
197+
.file(pubspecPath)
198+
.parent
199+
.childFile('ci_config.yaml');
200+
final YamlMap? ciConfig =
201+
loadYaml(ciConfigFile.readAsStringSync()) as YamlMap?;
202+
final dynamic batchValue = ciConfig?['release']?['batch'];
203+
if (batchValue is! bool) {
204+
printError(
205+
'`release.batch` key is missing or not a boolean in ci_config.yaml for $packageName.');
206+
continue;
207+
}
208+
isBatchReleasePackage = batchValue;
209+
} catch (e) {
210+
printError('Could not parse ci_config.yaml for $packageName: $e');
211+
continue;
212+
}
213+
// Skip the package if batch release flag is not set to match the ci_config.yaml
214+
if (getBoolArg(_batchReleaseFlag) != isBatchReleasePackage) {
215+
continue;
216+
185217
// git outputs a relativa, Posix-style path.
186218
final File pubspecFile = childFileWithSubcomponents(
187219
packagesDir.fileSystem.directory((await gitDir).path),

0 commit comments

Comments
 (0)