From e1ee6cbce511a321b2f6b570f98020c6d083f816 Mon Sep 17 00:00:00 2001 From: Jake Macdonald Date: Mon, 1 Jul 2024 21:48:19 +0000 Subject: [PATCH 1/5] support nested packages --- pkgs/firehose/CHANGELOG.md | 5 +++++ pkgs/firehose/lib/src/repo.dart | 16 +++++++++------- pkgs/firehose/pubspec.yaml | 2 +- 3 files changed, 15 insertions(+), 8 deletions(-) diff --git a/pkgs/firehose/CHANGELOG.md b/pkgs/firehose/CHANGELOG.md index 2e49ae33..1fad9772 100644 --- a/pkgs/firehose/CHANGELOG.md +++ b/pkgs/firehose/CHANGELOG.md @@ -1,3 +1,8 @@ +## 0.9.1 + +- Support packages nested under other packages, as long as the outer package + is not publishable. + ## 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..832aa796 100644 --- a/pkgs/firehose/lib/src/repo.dart +++ b/pkgs/firehose/lib/src/repo.dart @@ -57,14 +57,16 @@ class Repository { var publishTo = pubspec['publish_to'] as String?; if (publishTo != 'none') { packages.add(Package(directory, this)); + // There is an assumption here that published 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: From d0be04c95c800683b80fe3e8d0f775a88dc9d59c Mon Sep 17 00:00:00 2001 From: Jake Macdonald Date: Tue, 2 Jul 2024 16:38:38 +0000 Subject: [PATCH 2/5] add tests --- pkgs/firehose/lib/src/repo.dart | 6 +-- 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 ++ 8 files changed, 61 insertions(+), 8 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/lib/src/repo.dart b/pkgs/firehose/lib/src/repo.dart index 832aa796..1d5fea11 100644 --- a/pkgs/firehose/lib/src/repo.dart +++ b/pkgs/firehose/lib/src/repo.dart @@ -55,10 +55,10 @@ 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 packages do not contain - // nested published packages. + // There is an assumption here that published, non-workspace packages do + // not contain nested published packages. return; } } diff --git a/pkgs/firehose/test/repo_test.dart b/pkgs/firehose/test/repo_test.dart index d148423c..15d063f5 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 directory. + 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 From 6dc0a1c31b62b51289b813e5f14d7245c2d11d36 Mon Sep 17 00:00:00 2001 From: Jake Macdonald Date: Tue, 2 Jul 2024 16:39:40 +0000 Subject: [PATCH 3/5] update changelog --- pkgs/firehose/CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkgs/firehose/CHANGELOG.md b/pkgs/firehose/CHANGELOG.md index 1fad9772..85e87a75 100644 --- a/pkgs/firehose/CHANGELOG.md +++ b/pkgs/firehose/CHANGELOG.md @@ -1,7 +1,7 @@ ## 0.9.1 - Support packages nested under other packages, as long as the outer package - is not publishable. + is not publishable or a pub workspace root package. ## 0.9.0 From 5fe731b0aab48ad4f703364acda57716f2288795 Mon Sep 17 00:00:00 2001 From: Jake Macdonald Date: Tue, 2 Jul 2024 16:41:07 +0000 Subject: [PATCH 4/5] line length --- pkgs/firehose/test/repo_test.dart | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkgs/firehose/test/repo_test.dart b/pkgs/firehose/test/repo_test.dart index 15d063f5..27a774d2 100644 --- a/pkgs/firehose/test/repo_test.dart +++ b/pkgs/firehose/test/repo_test.dart @@ -25,7 +25,7 @@ void main() { group('repo', () { setUp(() { - // Look up two levels from the package directory to get the repo directory. + // Look up two levels from the package directory to get the repo dir. packages = Repository(Directory.fromUri(packageRoot.resolve('../../'))); }); From 89b11da12cde31a56ba95cee0f0d57ec32991b62 Mon Sep 17 00:00:00 2001 From: Jacob MacDonald Date: Tue, 2 Jul 2024 11:45:52 -0700 Subject: [PATCH 5/5] Apply suggestions from code review Co-authored-by: Devon Carew --- pkgs/firehose/CHANGELOG.md | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/pkgs/firehose/CHANGELOG.md b/pkgs/firehose/CHANGELOG.md index 85e87a75..d409f866 100644 --- a/pkgs/firehose/CHANGELOG.md +++ b/pkgs/firehose/CHANGELOG.md @@ -1,7 +1,6 @@ ## 0.9.1 -- Support packages nested under other packages, as long as the outer package - is not publishable or a pub workspace root package. +- Support packages nested under a 'workspace' root package. ## 0.9.0