From aba6520afacbc8d6fe138ab4792e24feab9fceb2 Mon Sep 17 00:00:00 2001 From: hangyu Date: Mon, 17 Nov 2025 15:10:49 -0800 Subject: [PATCH 1/3] Update release_from_batch_release.yml Update release.yml clean up code Update publish_command.dart 1 --- .github/workflows/release.yml | 18 +++++++---- .../workflows/release_from_batch_release.yml | 12 +++++++ .github/workflows/release_from_main.yml | 12 +++++++ script/tool/lib/src/publish_command.dart | 32 +++++++++++++++++++ 4 files changed, 68 insertions(+), 6 deletions(-) create mode 100644 .github/workflows/release_from_batch_release.yml create mode 100644 .github/workflows/release_from_main.yml diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 835b40c18e3..4bb9db848ba 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -1,8 +1,14 @@ -name: release +name: Reusable Release + on: - push: - branches: - - main + workflow_call: + inputs: + publish-args: + required: true + type: string + workflow-name: + required: true + type: string # Declare default permissions as read only. permissions: read-all @@ -82,5 +88,5 @@ jobs: run: | git config --global user.name ${{ secrets.USER_NAME }} git config --global user.email ${{ secrets.USER_EMAIL }} - dart ./script/tool/lib/src/main.dart publish --all-changed --base-sha=HEAD~ --skip-confirmation --remote=origin - env: {PUB_CREDENTIALS: "${{ secrets.PUB_CREDENTIALS }}"} + dart ./script/tool/lib/src/main.dart publish ${{ inputs.publish-args }} + env: {PUB_CREDENTIALS: "${{ secrets.PUB_CREDENTIALS }}"} \ No newline at end of file diff --git a/.github/workflows/release_from_batch_release.yml b/.github/workflows/release_from_batch_release.yml new file mode 100644 index 00000000000..5001730f859 --- /dev/null +++ b/.github/workflows/release_from_batch_release.yml @@ -0,0 +1,12 @@ +name: Batch Release +on: + push: + branches: + - release +jobs: + release: + uses: ./.github/workflows/reusable_release.yml + with: + publish-args: '--all-changed --batch-release --base-sha=HEAD~ --skip-confirmation --remote=origin' + workflow-name: 'Batch Release' + secrets: inherit \ No newline at end of file diff --git a/.github/workflows/release_from_main.yml b/.github/workflows/release_from_main.yml new file mode 100644 index 00000000000..501546d919d --- /dev/null +++ b/.github/workflows/release_from_main.yml @@ -0,0 +1,12 @@ +name: Main Release +on: + push: + branches: + - main +jobs: + release: + uses: ./.github/workflows/reusable_release.yml + with: + publish-args: '--all-changed --base-sha=HEAD~ --skip-confirmation --remote=origin' + workflow-name: 'Main Release' + secrets: inherit \ No newline at end of file diff --git a/script/tool/lib/src/publish_command.dart b/script/tool/lib/src/publish_command.dart index 8af5eb1a0f2..2d28c4988f0 100644 --- a/script/tool/lib/src/publish_command.dart +++ b/script/tool/lib/src/publish_command.dart @@ -78,6 +78,11 @@ class PublishCommand extends PackageLoopingCommand { 'Release all packages that contains pubspec changes at the current commit compares to the base-sha.\n' 'The --packages option is ignored if this is on.', ); + argParser.addFlag( + _batchReleaseFlag, + help: + 'only release the packages that opt-in for batch release option.' + ) argParser.addFlag( _dryRunFlag, help: @@ -99,6 +104,7 @@ class PublishCommand extends PackageLoopingCommand { static const String _pubFlagsOption = 'pub-publish-flags'; static const String _remoteOption = 'remote'; static const String _allChangedFlag = 'all-changed'; + static const String _batchReleaseFlag = 'batch-release'; static const String _dryRunFlag = 'dry-run'; static const String _skipConfirmationFlag = 'skip-confirmation'; static const String _tagForAutoPublishFlag = 'tag-for-auto-publish'; @@ -182,6 +188,32 @@ class PublishCommand extends PackageLoopingCommand { .toList(); for (final String pubspecPath in changedPubspecs) { + // Read the ci_config.yaml file + + final String packageName = p.basename(p.dirname(pubspecPath)); + bool isBatchReleasePackage; + try { + final File ciConfigFile = packagesDir.fileSystem + .file(pubspecPath) + .parent + .childFile('ci_config.yaml'); + final YamlMap? ciConfig = + loadYaml(ciConfigFile.readAsStringSync()) as YamlMap?; + final dynamic batchValue = ciConfig?['release']?['batch']; + if (batchValue is! bool) { + printError( + '`release.batch` key is missing or not a boolean in ci_config.yaml for $packageName.'); + continue; + } + isBatchReleasePackage = batchValue; + } catch (e) { + printError('Could not parse ci_config.yaml for $packageName: $e'); + continue; + } + // Skip the package if batch release flag is not set to match the ci_config.yaml + if (getBoolArg(_batchReleaseFlag) != isBatchReleasePackage) { + continue; + // git outputs a relativa, Posix-style path. final File pubspecFile = childFileWithSubcomponents( packagesDir.fileSystem.directory((await gitDir).path), From dc5dd86a49bf6999087f95ac1c04c460b4e5d2fd Mon Sep 17 00:00:00 2001 From: hangyu Date: Mon, 17 Nov 2025 16:13:19 -0800 Subject: [PATCH 2/3] Update publish_command.dart --- script/tool/lib/src/publish_command.dart | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/script/tool/lib/src/publish_command.dart b/script/tool/lib/src/publish_command.dart index 2d28c4988f0..ada04adc6be 100644 --- a/script/tool/lib/src/publish_command.dart +++ b/script/tool/lib/src/publish_command.dart @@ -78,11 +78,9 @@ class PublishCommand extends PackageLoopingCommand { 'Release all packages that contains pubspec changes at the current commit compares to the base-sha.\n' 'The --packages option is ignored if this is on.', ); - argParser.addFlag( - _batchReleaseFlag, - help: - 'only release the packages that opt-in for batch release option.' - ) + argParser.addFlag(_batchReleaseFlag, + help: + 'only release the packages that opt-in for batch release option.'); argParser.addFlag( _dryRunFlag, help: @@ -213,7 +211,8 @@ class PublishCommand extends PackageLoopingCommand { // Skip the package if batch release flag is not set to match the ci_config.yaml if (getBoolArg(_batchReleaseFlag) != isBatchReleasePackage) { continue; - + } + // git outputs a relativa, Posix-style path. final File pubspecFile = childFileWithSubcomponents( packagesDir.fileSystem.directory((await gitDir).path), From 0b6b65ade20057aa133a0af264755ff62dbd3223 Mon Sep 17 00:00:00 2001 From: hangyu Date: Mon, 17 Nov 2025 16:14:57 -0800 Subject: [PATCH 3/3] lint --- .github/workflows/release.yml | 2 +- .github/workflows/release_from_batch_release.yml | 2 +- .github/workflows/release_from_main.yml | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 4bb9db848ba..36505038c53 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -89,4 +89,4 @@ jobs: git config --global user.name ${{ secrets.USER_NAME }} git config --global user.email ${{ secrets.USER_EMAIL }} dart ./script/tool/lib/src/main.dart publish ${{ inputs.publish-args }} - env: {PUB_CREDENTIALS: "${{ secrets.PUB_CREDENTIALS }}"} \ No newline at end of file + env: {PUB_CREDENTIALS: "${{ secrets.PUB_CREDENTIALS }}"} diff --git a/.github/workflows/release_from_batch_release.yml b/.github/workflows/release_from_batch_release.yml index 5001730f859..4e1dddc9833 100644 --- a/.github/workflows/release_from_batch_release.yml +++ b/.github/workflows/release_from_batch_release.yml @@ -9,4 +9,4 @@ jobs: with: publish-args: '--all-changed --batch-release --base-sha=HEAD~ --skip-confirmation --remote=origin' workflow-name: 'Batch Release' - secrets: inherit \ No newline at end of file + secrets: inherit diff --git a/.github/workflows/release_from_main.yml b/.github/workflows/release_from_main.yml index 501546d919d..2855f6e629b 100644 --- a/.github/workflows/release_from_main.yml +++ b/.github/workflows/release_from_main.yml @@ -9,4 +9,4 @@ jobs: with: publish-args: '--all-changed --base-sha=HEAD~ --skip-confirmation --remote=origin' workflow-name: 'Main Release' - secrets: inherit \ No newline at end of file + secrets: inherit