Skip to content

Restore ordering of jobs to what it was before #450

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

Merged
merged 4 commits into from
May 15, 2023
Merged
Show file tree
Hide file tree
Changes from 2 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
5 changes: 5 additions & 0 deletions mono_repo/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
## 6.5.6

- Restore the previous ordering behavior for jobs by using a secondary sort
based on the insertion order (this matches the listed configuration order).

## 6.5.5

- Add the pub package topics `tool` and `repository-management`.
Expand Down
36 changes: 23 additions & 13 deletions mono_repo/lib/src/ci_shared.dart
Original file line number Diff line number Diff line change
Expand Up @@ -246,21 +246,31 @@ List<String> calculateOrderedStages(
);
}

// Running strongly connected components lets us detect cycles (which aren't
// allowed), and gives us the reverse order of what we ultimately want.
final components = stronglyConnectedComponents(edges.keys, (n) => edges[n]!);
for (var component in components) {
if (component.length > 1) {
final items = component.map((e) => '`$e`').join(', ');
throw UserException(
'Not all packages agree on `stages` ordering, found '
'a cycle between the following stages: $items.',
);
}
final List<String> components;
try {
// Build up a map of the keys to their index in `edges.keys`, which we use
// as a secondary sort. This is an intuitive secondary sort order as it
// follows the order given in configuration files.
final keys = edges.keys.toList();
final edgeIndexes = {
for (var i = 0; i < keys.length; i++) keys[i]: i,
};

// Orders by dependencies first, and detect cycles (which aren't allowed).
components = topologicalSort(
keys,
(n) => edges[n]!,
secondarySort: (a, b) => edgeIndexes[b]!.compareTo(edgeIndexes[a]!),
);
} on CycleException<String> catch (e) {
final items = e.cycle.map((e) => '`$e`').join(', ');
throw UserException(
'Not all packages agree on `stages` ordering, found '
'a cycle between the following stages: $items.',
);
}

final orderedStages =
components.map((c) => c.first).toList().reversed.toList();
final orderedStages = components;

if (rootConfig.monoConfig.selfValidateStage != null &&
!orderedStages.contains(rootConfig.monoConfig.selfValidateStage)) {
Expand Down
4 changes: 2 additions & 2 deletions mono_repo/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: mono_repo
description: >-
CLI tools to make it easier to manage a single source repository containing
multiple Dart packages.
version: 6.5.5
version: 6.5.6
repository: https://github.com/google/mono_repo.dart
topics:
- tool
Expand All @@ -15,7 +15,7 @@ dependencies:
args: ^2.0.0
checked_yaml: ^2.0.0
collection: ^1.14.3
graphs: ^2.0.0
graphs: ^2.2.0
io: ^1.0.0
json_annotation: ^4.8.0
meta: ^1.0.0
Expand Down