From 83db67a947ee50b36a1243c9cf5f0026136d7855 Mon Sep 17 00:00:00 2001 From: Jake Macdonald Date: Mon, 15 May 2023 16:52:23 +0000 Subject: [PATCH 1/4] restore ordering with explicit secondary sort by insertion order --- mono_repo/lib/src/ci_shared.dart | 36 ++++++++++++++++++++------------ 1 file changed, 23 insertions(+), 13 deletions(-) diff --git a/mono_repo/lib/src/ci_shared.dart b/mono_repo/lib/src/ci_shared.dart index 6366368d..a805338f 100644 --- a/mono_repo/lib/src/ci_shared.dart +++ b/mono_repo/lib/src/ci_shared.dart @@ -246,21 +246,31 @@ List 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 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 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)) { From d73c66c66cfdc4438973fc0f2f395a6060e7d29a Mon Sep 17 00:00:00 2001 From: Jake Macdonald Date: Mon, 15 May 2023 16:54:30 +0000 Subject: [PATCH 2/4] version/release --- mono_repo/CHANGELOG.md | 5 +++++ mono_repo/pubspec.yaml | 4 ++-- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/mono_repo/CHANGELOG.md b/mono_repo/CHANGELOG.md index da5e3c4f..cb254769 100644 --- a/mono_repo/CHANGELOG.md +++ b/mono_repo/CHANGELOG.md @@ -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`. diff --git a/mono_repo/pubspec.yaml b/mono_repo/pubspec.yaml index 77064e7e..b658a3ba 100644 --- a/mono_repo/pubspec.yaml +++ b/mono_repo/pubspec.yaml @@ -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 @@ -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 From 1910619030b54e3c435f9ff805455fed13168553 Mon Sep 17 00:00:00 2001 From: Jake Macdonald Date: Mon, 15 May 2023 17:00:42 +0000 Subject: [PATCH 3/4] clarify comment, remove unnecessary variable --- mono_repo/lib/src/ci_shared.dart | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/mono_repo/lib/src/ci_shared.dart b/mono_repo/lib/src/ci_shared.dart index a805338f..968d70c6 100644 --- a/mono_repo/lib/src/ci_shared.dart +++ b/mono_repo/lib/src/ci_shared.dart @@ -257,6 +257,8 @@ List calculateOrderedStages( }; // Orders by dependencies first, and detect cycles (which aren't allowed). + // Our edges here are actually reverse edges already, so a topological sort + // gives us the right thing. components = topologicalSort( keys, (n) => edges[n]!, @@ -270,14 +272,12 @@ List calculateOrderedStages( ); } - final orderedStages = components; - if (rootConfig.monoConfig.selfValidateStage != null && - !orderedStages.contains(rootConfig.monoConfig.selfValidateStage)) { - orderedStages.insert(0, rootConfig.monoConfig.selfValidateStage!); + !components.contains(rootConfig.monoConfig.selfValidateStage)) { + components.insert(0, rootConfig.monoConfig.selfValidateStage!); } - return orderedStages; + return components; } List _travisTasks(Iterable configs) => From f571948d5bdf06a4802748570d836438602bc070 Mon Sep 17 00:00:00 2001 From: Jake Macdonald Date: Mon, 15 May 2023 17:02:20 +0000 Subject: [PATCH 4/4] regen code, rerun generate --- .github/workflows/dart.yml | 2 +- mono_repo/lib/src/version.dart | 2 +- tool/ci.sh | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/dart.yml b/.github/workflows/dart.yml index c5f512fb..5d3681b1 100644 --- a/.github/workflows/dart.yml +++ b/.github/workflows/dart.yml @@ -1,4 +1,4 @@ -# Created with package:mono_repo v6.5.5 +# Created with package:mono_repo v6.5.6 name: Dart CI on: push: diff --git a/mono_repo/lib/src/version.dart b/mono_repo/lib/src/version.dart index 7033cdb3..9050f6d6 100644 --- a/mono_repo/lib/src/version.dart +++ b/mono_repo/lib/src/version.dart @@ -1,2 +1,2 @@ // Generated code. Do not modify. -const packageVersion = '6.5.5'; +const packageVersion = '6.5.6'; diff --git a/tool/ci.sh b/tool/ci.sh index 29b9e436..0c226d03 100755 --- a/tool/ci.sh +++ b/tool/ci.sh @@ -1,5 +1,5 @@ #!/bin/bash -# Created with package:mono_repo v6.5.5 +# Created with package:mono_repo v6.5.6 # Support built in commands on windows out of the box. # When it is a flutter repo (check the pubspec.yaml for "sdk: flutter")