Skip to content

Commit 69c4392

Browse files
authored
Restore ordering of jobs to what it was before (#450)
Restore ordering with explicit secondary sort by insertion order
1 parent 19e7336 commit 69c4392

File tree

6 files changed

+37
-22
lines changed

6 files changed

+37
-22
lines changed

.github/workflows/dart.yml

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

mono_repo/CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
## 6.5.6
2+
3+
- Restore the previous ordering behavior for jobs by using a secondary sort
4+
based on the insertion order (this matches the listed configuration order).
5+
16
## 6.5.5
27

38
- Add the pub package topics `tool` and `repository-management`.

mono_repo/lib/src/ci_shared.dart

Lines changed: 27 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -246,28 +246,38 @@ List<String> calculateOrderedStages(
246246
);
247247
}
248248

249-
// Running strongly connected components lets us detect cycles (which aren't
250-
// allowed), and gives us the reverse order of what we ultimately want.
251-
final components = stronglyConnectedComponents(edges.keys, (n) => edges[n]!);
252-
for (var component in components) {
253-
if (component.length > 1) {
254-
final items = component.map((e) => '`$e`').join(', ');
255-
throw UserException(
256-
'Not all packages agree on `stages` ordering, found '
257-
'a cycle between the following stages: $items.',
258-
);
259-
}
249+
final List<String> components;
250+
try {
251+
// Build up a map of the keys to their index in `edges.keys`, which we use
252+
// as a secondary sort. This is an intuitive secondary sort order as it
253+
// follows the order given in configuration files.
254+
final keys = edges.keys.toList();
255+
final edgeIndexes = {
256+
for (var i = 0; i < keys.length; i++) keys[i]: i,
257+
};
258+
259+
// Orders by dependencies first, and detect cycles (which aren't allowed).
260+
// Our edges here are actually reverse edges already, so a topological sort
261+
// gives us the right thing.
262+
components = topologicalSort(
263+
keys,
264+
(n) => edges[n]!,
265+
secondarySort: (a, b) => edgeIndexes[b]!.compareTo(edgeIndexes[a]!),
266+
);
267+
} on CycleException<String> catch (e) {
268+
final items = e.cycle.map((e) => '`$e`').join(', ');
269+
throw UserException(
270+
'Not all packages agree on `stages` ordering, found '
271+
'a cycle between the following stages: $items.',
272+
);
260273
}
261274

262-
final orderedStages =
263-
components.map((c) => c.first).toList().reversed.toList();
264-
265275
if (rootConfig.monoConfig.selfValidateStage != null &&
266-
!orderedStages.contains(rootConfig.monoConfig.selfValidateStage)) {
267-
orderedStages.insert(0, rootConfig.monoConfig.selfValidateStage!);
276+
!components.contains(rootConfig.monoConfig.selfValidateStage)) {
277+
components.insert(0, rootConfig.monoConfig.selfValidateStage!);
268278
}
269279

270-
return orderedStages;
280+
return components;
271281
}
272282

273283
List<Task> _travisTasks(Iterable<PackageConfig> configs) =>

mono_repo/lib/src/version.dart

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

mono_repo/pubspec.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ name: mono_repo
22
description: >-
33
CLI tools to make it easier to manage a single source repository containing
44
multiple Dart packages.
5-
version: 6.5.5
5+
version: 6.5.6
66
repository: https://github.com/google/mono_repo.dart
77
topics:
88
- tool
@@ -15,7 +15,7 @@ dependencies:
1515
args: ^2.0.0
1616
checked_yaml: ^2.0.0
1717
collection: ^1.14.3
18-
graphs: ^2.0.0
18+
graphs: ^2.2.0
1919
io: ^1.0.0
2020
json_annotation: ^4.8.0
2121
meta: ^1.0.0

tool/ci.sh

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)