Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

normalize sort order of package listing #205

Merged
merged 2 commits into from
Dec 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.4.1-wip

- Ensure that packages are listed in lexical order.

## 0.4.0

- Switch to using `package:github`.
Expand Down
14 changes: 7 additions & 7 deletions pkgs/firehose/lib/src/repo.dart
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,13 @@ class Repository {
///
/// Once we find a package, we don't look for packages in sub-directories.
List<Package> locatePackages() {
return _recurseAndGather(baseDirectory, []);
final packages = <Package>[];
_recurseAndGather(baseDirectory, packages);
packages.sort((a, b) => a.name.compareTo(b.name));
return packages;
}

List<Package> _recurseAndGather(Directory directory, List<Package> packages) {
void _recurseAndGather(Directory directory, List<Package> packages) {
var pubspecFile = File(path.join(directory.path, 'pubspec.yaml'));

if (pubspecFile.existsSync()) {
Expand All @@ -62,8 +65,6 @@ class Repository {
}
}
}

return packages;
}

String calculateRepoTag(Package package) {
Expand Down Expand Up @@ -103,7 +104,6 @@ class Package {
Version? get version => pubspec.version;

@override
String toString() {
return 'package:${pubspec.name} ${pubspec.version} (dir=${directory.path})';
}
String toString() =>
'package:${pubspec.name} ${pubspec.version} (dir=${directory.path})';
}
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.4.0
version: 0.4.1-wip
repository: https://github.com/dart-lang/ecosystem/tree/main/pkgs/firehose

environment:
Expand Down
1 change: 1 addition & 0 deletions pkgs/firehose/test/changelog_test.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// Copyright (c) 2023, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.

@TestOn('vm')
library;

Expand Down
1 change: 1 addition & 0 deletions pkgs/firehose/test/coverage_test.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// Copyright (c) 2023, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.

@TestOn('vm')
library;

Expand Down
1 change: 1 addition & 0 deletions pkgs/firehose/test/license_test.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// Copyright (c) 2023, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.

@TestOn('vm')
library;

Expand Down
1 change: 1 addition & 0 deletions pkgs/firehose/test/pub_test.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// Copyright (c) 2023, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.

@TestOn('vm')
library;

Expand Down
29 changes: 25 additions & 4 deletions pkgs/firehose/test/repo_test.dart
Original file line number Diff line number Diff line change
@@ -1,36 +1,57 @@
// Copyright (c) 2023, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.

@TestOn('vm')
library;

import 'dart:io';

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;

setUp(() {
packages = Repository();
// Tests are run in the package directory; look up two levels to get the
// repo directory.
packages = Repository(Directory.current.parent.parent);
});

test('isSinglePackageRepo', () {
var result = packages.isSinglePackageRepo;
expect(result, true);
expect(result, false);
});

test('locatePackages', () {
var result = packages.locatePackages();
expect(result, isNotEmpty);
});

test('validate sorted', () {
var result = packages.locatePackages();
var sorted = true;
for (var i = 1; i < result.length; i++) {
final a = result[i - 1];
final b = result[i];

sorted &= a.name.compareTo(b.name) <= 0;
}
expect(sorted, isTrue);
});

test('github release link', () {
final github = GithubApi();
final package = packages.locatePackages().single;
final github = GithubApi(
repoSlug: RepositorySlug.full('dart-lang/ecosystem'),
);
final package = packages.locatePackages().first;
final releaseUri = packages.calculateReleaseUri(package, github);
expect(releaseUri.path, '/${github.repoSlug}/releases/new');

final queryParams = releaseUri.queryParameters;
expect(queryParams['tag'], packages.calculateRepoTag(package));
expect(queryParams['title'],
Expand Down