From 4171189c0dd0f5e02426fcded7d1fa2d09be6133 Mon Sep 17 00:00:00 2001 From: Jacob MacDonald Date: Tue, 2 Jul 2024 11:54:47 -0700 Subject: [PATCH] support nested packages in firehose (#277) Fixes https://github.com/dart-lang/ecosystem/issues/276 Adds support for published packages nested under unpublished packages. In particular, this adds support for workspace packages to firehose. --- pkgs/firehose/CHANGELOG.md | 4 ++ pkgs/firehose/lib/src/repo.dart | 18 ++++--- pkgs/firehose/pubspec.yaml | 2 +- pkgs/firehose/test/repo_test.dart | 51 +++++++++++++++++-- .../root_unpublished_pkg/pkg_1/pubspec.yaml | 1 + .../root_unpublished_pkg/pkg_2/pubspec.yaml | 1 + .../root_unpublished_pkg/pubspec.yaml | 2 + .../workspace_repo/pkg_1/pubspec.yaml | 2 + .../workspace_repo/pkg_2/pubspec.yaml | 2 + .../test_data/workspace_repo/pubspec.yaml | 4 ++ 10 files changed, 73 insertions(+), 14 deletions(-) create mode 100644 pkgs/firehose/test_data/root_unpublished_pkg/pkg_1/pubspec.yaml create mode 100644 pkgs/firehose/test_data/root_unpublished_pkg/pkg_2/pubspec.yaml create mode 100644 pkgs/firehose/test_data/root_unpublished_pkg/pubspec.yaml create mode 100644 pkgs/firehose/test_data/workspace_repo/pkg_1/pubspec.yaml create mode 100644 pkgs/firehose/test_data/workspace_repo/pkg_2/pubspec.yaml create mode 100644 pkgs/firehose/test_data/workspace_repo/pubspec.yaml diff --git a/pkgs/firehose/CHANGELOG.md b/pkgs/firehose/CHANGELOG.md index 2e49ae33..d409f866 100644 --- a/pkgs/firehose/CHANGELOG.md +++ b/pkgs/firehose/CHANGELOG.md @@ -1,3 +1,7 @@ +## 0.9.1 + +- Support packages nested under a 'workspace' root package. + ## 0.9.0 - Add `leaking` check to the health workflow. diff --git a/pkgs/firehose/lib/src/repo.dart b/pkgs/firehose/lib/src/repo.dart index 1cdd1df6..1d5fea11 100644 --- a/pkgs/firehose/lib/src/repo.dart +++ b/pkgs/firehose/lib/src/repo.dart @@ -55,16 +55,18 @@ class Repository { if (pubspecFile.existsSync()) { var pubspec = yaml.loadYaml(pubspecFile.readAsStringSync()) as Map; var publishTo = pubspec['publish_to'] as String?; - if (publishTo != 'none') { + if (publishTo != 'none' && !pubspec.containsKey('workspace')) { packages.add(Package(directory, this)); + // There is an assumption here that published, non-workspace packages do + // not contain nested published packages. + return; } - } else { - if (directory.existsSync()) { - for (var child in directory.listSync().whereType()) { - var name = path.basename(child.path); - if (!name.startsWith('.')) { - _recurseAndGather(child, packages); - } + } + if (directory.existsSync()) { + for (var child in directory.listSync().whereType()) { + var name = path.basename(child.path); + if (!name.startsWith('.')) { + _recurseAndGather(child, packages); } } } diff --git a/pkgs/firehose/pubspec.yaml b/pkgs/firehose/pubspec.yaml index f6a6b6ef..d9a079a2 100644 --- a/pkgs/firehose/pubspec.yaml +++ b/pkgs/firehose/pubspec.yaml @@ -1,6 +1,6 @@ name: firehose description: A tool to automate publishing of Pub packages from GitHub actions. -version: 0.9.0 +version: 0.9.1 repository: https://github.com/dart-lang/ecosystem/tree/main/pkgs/firehose environment: diff --git a/pkgs/firehose/test/repo_test.dart b/pkgs/firehose/test/repo_test.dart index d148423c..27a774d2 100644 --- a/pkgs/firehose/test/repo_test.dart +++ b/pkgs/firehose/test/repo_test.dart @@ -6,6 +6,7 @@ library; import 'dart:io'; +import 'dart:isolate'; import 'package:firehose/src/github.dart'; import 'package:firehose/src/repo.dart'; @@ -13,13 +14,19 @@ import 'package:github/github.dart' show RepositorySlug; import 'package:test/test.dart'; void main() { - group('repo', () { - late Repository packages; + late Repository packages; + late Uri packageRoot; + + setUpAll(() async { + packageRoot = (await Isolate.resolvePackageUri( + Uri.parse('package:firehose/test.dart')))! + .resolve('../'); + }); + group('repo', () { setUp(() { - // Tests are run in the package directory; look up two levels to get the - // repo directory. - packages = Repository(Directory.current.parent.parent); + // Look up two levels from the package directory to get the repo dir. + packages = Repository(Directory.fromUri(packageRoot.resolve('../../'))); }); test('isSinglePackageRepo', () { @@ -59,4 +66,38 @@ void main() { expect(queryParams['body'], package.changelog.describeLatestChanges); }); }); + + group('pub workspace repo', () { + setUp(() { + packages = Repository( + Directory.fromUri(packageRoot.resolve('test_data/workspace_repo'))); + }); + + test('locatePackages', () { + var result = packages.locatePackages(); + expect( + result, + equals([ + isA().having((p) => p.name, 'name', 'pkg_1'), + isA().having((p) => p.name, 'name', 'pkg_2'), + ])); + }); + }); + + group('repo with an unpublished root package', () { + setUp(() { + packages = Repository(Directory.fromUri( + packageRoot.resolve('test_data/root_unpublished_pkg'))); + }); + + test('locatePackages', () { + var result = packages.locatePackages(); + expect( + result, + equals([ + isA().having((p) => p.name, 'name', 'pkg_1'), + isA().having((p) => p.name, 'name', 'pkg_2'), + ])); + }); + }); } diff --git a/pkgs/firehose/test_data/root_unpublished_pkg/pkg_1/pubspec.yaml b/pkgs/firehose/test_data/root_unpublished_pkg/pkg_1/pubspec.yaml new file mode 100644 index 00000000..935037ed --- /dev/null +++ b/pkgs/firehose/test_data/root_unpublished_pkg/pkg_1/pubspec.yaml @@ -0,0 +1 @@ +name: pkg_1 diff --git a/pkgs/firehose/test_data/root_unpublished_pkg/pkg_2/pubspec.yaml b/pkgs/firehose/test_data/root_unpublished_pkg/pkg_2/pubspec.yaml new file mode 100644 index 00000000..a4598d05 --- /dev/null +++ b/pkgs/firehose/test_data/root_unpublished_pkg/pkg_2/pubspec.yaml @@ -0,0 +1 @@ +name: pkg_2 diff --git a/pkgs/firehose/test_data/root_unpublished_pkg/pubspec.yaml b/pkgs/firehose/test_data/root_unpublished_pkg/pubspec.yaml new file mode 100644 index 00000000..a72f8946 --- /dev/null +++ b/pkgs/firehose/test_data/root_unpublished_pkg/pubspec.yaml @@ -0,0 +1,2 @@ +name: root +publish_to: none diff --git a/pkgs/firehose/test_data/workspace_repo/pkg_1/pubspec.yaml b/pkgs/firehose/test_data/workspace_repo/pkg_1/pubspec.yaml new file mode 100644 index 00000000..eecba700 --- /dev/null +++ b/pkgs/firehose/test_data/workspace_repo/pkg_1/pubspec.yaml @@ -0,0 +1,2 @@ +name: pkg_1 +resolution: workspace diff --git a/pkgs/firehose/test_data/workspace_repo/pkg_2/pubspec.yaml b/pkgs/firehose/test_data/workspace_repo/pkg_2/pubspec.yaml new file mode 100644 index 00000000..dac8e070 --- /dev/null +++ b/pkgs/firehose/test_data/workspace_repo/pkg_2/pubspec.yaml @@ -0,0 +1,2 @@ +name: pkg_2 +resolution: workspace diff --git a/pkgs/firehose/test_data/workspace_repo/pubspec.yaml b/pkgs/firehose/test_data/workspace_repo/pubspec.yaml new file mode 100644 index 00000000..c4fd0765 --- /dev/null +++ b/pkgs/firehose/test_data/workspace_repo/pubspec.yaml @@ -0,0 +1,4 @@ +name: workspace +workspace: + - pkg_1 + - pkg_2