Skip to content

Commit

Permalink
support nested packages in firehose (#277)
Browse files Browse the repository at this point in the history
Fixes #276

Adds support for published packages nested under unpublished packages. In particular, this adds support for workspace packages to firehose.
  • Loading branch information
jakemac53 authored Jul 2, 2024
1 parent 459041b commit 4171189
Show file tree
Hide file tree
Showing 10 changed files with 73 additions and 14 deletions.
4 changes: 4 additions & 0 deletions pkgs/firehose/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
18 changes: 10 additions & 8 deletions pkgs/firehose/lib/src/repo.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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<Directory>()) {
var name = path.basename(child.path);
if (!name.startsWith('.')) {
_recurseAndGather(child, packages);
}
}
if (directory.existsSync()) {
for (var child in directory.listSync().whereType<Directory>()) {
var name = path.basename(child.path);
if (!name.startsWith('.')) {
_recurseAndGather(child, packages);
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion pkgs/firehose/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -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:
Expand Down
51 changes: 46 additions & 5 deletions pkgs/firehose/test/repo_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,27 @@
library;

import 'dart:io';
import 'dart:isolate';

import 'package:firehose/src/github.dart';
import 'package:firehose/src/repo.dart';
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', () {
Expand Down Expand Up @@ -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<Package>().having((p) => p.name, 'name', 'pkg_1'),
isA<Package>().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<Package>().having((p) => p.name, 'name', 'pkg_1'),
isA<Package>().having((p) => p.name, 'name', 'pkg_2'),
]));
});
});
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
name: pkg_1
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
name: pkg_2
2 changes: 2 additions & 0 deletions pkgs/firehose/test_data/root_unpublished_pkg/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
name: root
publish_to: none
2 changes: 2 additions & 0 deletions pkgs/firehose/test_data/workspace_repo/pkg_1/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
name: pkg_1
resolution: workspace
2 changes: 2 additions & 0 deletions pkgs/firehose/test_data/workspace_repo/pkg_2/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
name: pkg_2
resolution: workspace
4 changes: 4 additions & 0 deletions pkgs/firehose/test_data/workspace_repo/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
name: workspace
workspace:
- pkg_1
- pkg_2

0 comments on commit 4171189

Please sign in to comment.