diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 835b40c18e3..36505038c53 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 + dart ./script/tool/lib/src/main.dart publish ${{ inputs.publish-args }} env: {PUB_CREDENTIALS: "${{ secrets.PUB_CREDENTIALS }}"} diff --git a/.github/workflows/release_from_batch_release.yml b/.github/workflows/release_from_batch_release.yml new file mode 100644 index 00000000000..4e1dddc9833 --- /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 diff --git a/.github/workflows/release_from_main.yml b/.github/workflows/release_from_main.yml new file mode 100644 index 00000000000..2855f6e629b --- /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 diff --git a/script/tool/lib/src/publish_command.dart b/script/tool/lib/src/publish_command.dart index 8af5eb1a0f2..ada04adc6be 100644 --- a/script/tool/lib/src/publish_command.dart +++ b/script/tool/lib/src/publish_command.dart @@ -78,6 +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( _dryRunFlag, help: @@ -99,6 +102,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 +186,33 @@ 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),