|
| 1 | +// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. |
| 2 | +// SPDX-License-Identifier: Apache-2.0 |
| 3 | + |
| 4 | +import 'package:aft/aft.dart'; |
| 5 | + |
| 6 | +/// A function that publishes a single package (e.g. pre-publish checks + |
| 7 | +/// actual publish). |
| 8 | +typedef PublishPackageFn = Future<void> Function(PackageInfo package); |
| 9 | + |
| 10 | +/// Schedules and executes the publishing of a list of packages in order. |
| 11 | +/// |
| 12 | +/// Packages are published sequentially. After each package is published the |
| 13 | +/// scheduler polls for a pending analysis on pub.dev and waits until the |
| 14 | +/// analysis is complete before proceeding to the next package. |
| 15 | +class PublishScheduler { |
| 16 | + PublishScheduler({ |
| 17 | + required List<PackageInfo> packages, |
| 18 | + required PublishPackageFn publishPackage, |
| 19 | + required AmplifyCommand command, |
| 20 | + }) : _packages = packages, |
| 21 | + _publishPackage = publishPackage, |
| 22 | + _command = command; |
| 23 | + |
| 24 | + final List<PackageInfo> _packages; |
| 25 | + final PublishPackageFn _publishPackage; |
| 26 | + final AmplifyCommand _command; |
| 27 | + |
| 28 | + /// Publishes all packages sequentially, awaiting pending analysis between |
| 29 | + /// each one. |
| 30 | + Future<void> run() async { |
| 31 | + for (final package in _packages) { |
| 32 | + await _publishPackage(package); |
| 33 | + await _command.awaitPendingAnalysis(package.name); |
| 34 | + } |
| 35 | + } |
| 36 | +} |
0 commit comments