-
Notifications
You must be signed in to change notification settings - Fork 247
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* ci: Fix db_common tests on Windows * Use powershell * feat: Add `pub_server` package Adds a minimal package for running a local, embedded pub server. * chore: Improve license script Running license script without `addlicense` installed should not leave a bunch of files around and should be runnable without sudo * feat(pub_server): Add launcher Adds a mechanism for seeding the local pub server with either the packages of a local directory or of a remote git repo. * feat(aft): Add `serve` command Adds a command for serving the repo's packages on a local pub server. * chore(pub_server): Clean up * ci: Add `pub_server` workflow * chore(pub_server): Add more doc comments * test(pub_server): Add e2e tests
- Loading branch information
Showing
26 changed files
with
2,366 additions
and
57 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
# Generated with aft. To update, run: `aft generate workflows` | ||
name: pub_server | ||
on: | ||
push: | ||
branches: | ||
- main | ||
- stable | ||
pull_request: | ||
paths: | ||
- '.github/workflows/dart_native.yaml' | ||
- '.github/workflows/dart_vm.yaml' | ||
- '.github/workflows/pub_server.yaml' | ||
- 'packages/amplify_lints/lib/**/*.yaml' | ||
- 'packages/amplify_lints/pubspec.yaml' | ||
- 'packages/aws_common/lib/**/*.dart' | ||
- 'packages/aws_common/pubspec.yaml' | ||
- 'packages/test/pub_server/**/*.dart' | ||
- 'packages/test/pub_server/**/*.yaml' | ||
- 'packages/test/pub_server/lib/**/*' | ||
- 'packages/test/pub_server/test/**/*' | ||
schedule: | ||
- cron: "0 0 * * 0" # Every Sunday at 00:00 | ||
defaults: | ||
run: | ||
shell: bash | ||
permissions: read-all | ||
|
||
jobs: | ||
test: | ||
uses: ./.github/workflows/dart_vm.yaml | ||
with: | ||
package-name: pub_server | ||
working-directory: packages/test/pub_server | ||
native_test: | ||
needs: test | ||
uses: ./.github/workflows/dart_native.yaml | ||
with: | ||
package-name: pub_server | ||
working-directory: packages/test/pub_server |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,108 @@ | ||
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
import 'dart:io'; | ||
|
||
import 'package:aft/aft.dart'; | ||
import 'package:aft/src/options/glob_options.dart'; | ||
import 'package:async/async.dart'; | ||
import 'package:pub_server/pub_server.dart'; | ||
import 'package:shelf/shelf_io.dart' as io; | ||
|
||
/// A command for serving all packages in the Amplify Flutter repo on a local | ||
/// pub server. | ||
class ServeCommand extends AmplifyCommand with GlobOptions, PublishHelpers { | ||
ServeCommand() { | ||
argParser.addOption( | ||
'port', | ||
abbr: 'p', | ||
defaultsTo: '0', | ||
help: 'The port to serve on.', | ||
); | ||
} | ||
|
||
/// The port to serve on. | ||
late final int port = int.parse(argResults!['port'] as String); | ||
|
||
@override | ||
bool get force => true; | ||
|
||
@override | ||
bool get dryRun => false; | ||
|
||
@override | ||
String get description => 'Serves all packages in the Amplify Flutter repo ' | ||
'on a local pub server.'; | ||
|
||
@override | ||
String get name => 'serve'; | ||
|
||
@override | ||
Future<PackageInfo?> checkPublishable(PackageInfo package) async { | ||
final publishTo = package.pubspecInfo.pubspec.publishTo; | ||
if (publishTo == 'none') { | ||
return null; | ||
} | ||
return package; | ||
} | ||
|
||
@override | ||
Future<void> run() async { | ||
await super.run(); | ||
await linkPackages(); | ||
|
||
final pubServer = await io.serve( | ||
PubServer.prod().handler, | ||
InternetAddress.anyIPv4, | ||
port, | ||
); | ||
final pubServerUri = Uri.parse('http://localhost:${pubServer.port}'); | ||
|
||
// Gather packages which can be published. | ||
final publishablePackages = repo.publishablePackages(commandPackages); | ||
|
||
// Publish packages to local pub server. | ||
final packagesNeedingPublish = | ||
await unpublishedPackages(publishablePackages); | ||
final launcherPackages = packagesNeedingPublish | ||
.map( | ||
(pkg) => LocalPackage( | ||
name: pkg.name, | ||
path: pkg.path, | ||
pubspec: pkg.pubspecInfo.pubspec, | ||
), | ||
) | ||
.toList(); | ||
final launcher = AmplifyPubLauncher( | ||
pubServerUri, | ||
launcherPackages, | ||
prePublish: (LocalPackage pkg) { | ||
final package = repo.allPackages[pkg.name]!; | ||
return prePublish(package); | ||
}, | ||
); | ||
await launcher.run(); | ||
|
||
logger.info('Serving packages on $pubServerUri. Press Ctrl+C to exit.'); | ||
|
||
await StreamGroup.merge([ | ||
ProcessSignal.sigint.watch(), | ||
ProcessSignal.sigterm.watch(), | ||
]).first; | ||
|
||
await pubServer.close(force: true); | ||
} | ||
} | ||
|
||
class AmplifyPubLauncher extends PubLauncher { | ||
AmplifyPubLauncher( | ||
super.pubServerUri, | ||
super.packages, { | ||
required Future<void> Function(LocalPackage) prePublish, | ||
}) : _prePublish = prePublish; | ||
|
||
final Future<void> Function(LocalPackage) _prePublish; | ||
|
||
@override | ||
Future<void> prePublish(LocalPackage package) => _prePublish(package); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.