From 1befb990d91bce5a8908bd12ecad2f3d1e310bff Mon Sep 17 00:00:00 2001 From: Simon Binder Date: Tue, 18 Jan 2022 23:28:12 +0100 Subject: [PATCH 1/5] Experiment with running client tests --- .github/workflows/community.yml | 27 +++++ tool/bin/patch_build_dependencies.dart | 17 ++++ tool/lib/patch_build_dependencies.dart | 55 ++++++++++ tool/mono_repo.yaml | 12 +++ tool/pubspec.yaml | 16 +++ tool/test/patch_build_dependencies_test.dart | 102 +++++++++++++++++++ 6 files changed, 229 insertions(+) create mode 100644 .github/workflows/community.yml create mode 100644 tool/bin/patch_build_dependencies.dart create mode 100644 tool/lib/patch_build_dependencies.dart create mode 100644 tool/mono_repo.yaml create mode 100644 tool/pubspec.yaml create mode 100644 tool/test/patch_build_dependencies_test.dart diff --git a/.github/workflows/community.yml b/.github/workflows/community.yml new file mode 100644 index 000000000..bfa9245b3 --- /dev/null +++ b/.github/workflows/community.yml @@ -0,0 +1,27 @@ +name: Community tests +on: + pull_request: +env: + PUB_ENVIRONMENT: bot.github + +jobs: + drift: + # Tests maintained by oss@simonbinder.eu + name: "Tests for pkg:drift" + runs-on: ubuntu-latest + steps: + - uses: dart-lang/setup-dart@v1.3 + - uses: actions/checkout@v2 + - run: dart pub get + working-directory: tool + + - uses: actions/checkout@v2 + with: + repository: simolus3/moor + path: /tmp/drift + - run: |- + dart run tool/bin/patch_build_dependencies.dart /tmp/drift/drift + cd /tmp/drift/drift + git add pubspec.yaml + - run: dart test --preset build_community_tests + name: Drift community tests diff --git a/tool/bin/patch_build_dependencies.dart b/tool/bin/patch_build_dependencies.dart new file mode 100644 index 000000000..0997422e6 --- /dev/null +++ b/tool/bin/patch_build_dependencies.dart @@ -0,0 +1,17 @@ +// Copyright (c) 2021, 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. + +import 'dart:io'; + +import 'package:build_development_tools/patch_build_dependencies.dart'; + +void main(List args) { + if (args.length != 1) { + print( + 'Usage: dart run tool/bin/patch_build_dependencies.dart '); + exit(1); + } + + patchBuildDependencies(args.single); +} diff --git a/tool/lib/patch_build_dependencies.dart b/tool/lib/patch_build_dependencies.dart new file mode 100644 index 000000000..eba0e76be --- /dev/null +++ b/tool/lib/patch_build_dependencies.dart @@ -0,0 +1,55 @@ +// Copyright (c) 2021, 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. + +import 'dart:io'; + +import 'package:path/path.dart' as p; +import 'package:yaml/yaml.dart'; +import 'package:yaml_edit/yaml_edit.dart'; + +const _buildPackages = [ + 'build', + 'build_config', + 'build_daemon', + 'build_modules', + 'build_resolvers', + 'build_runner', + 'build_runner_core', + 'build_test', + 'build_vm_compilers', + 'build_web_compilers', + 'scratch_space', +]; + +/// Adds `dependency_overrides` for to a pubspec.yaml file in [packageDir] +/// build packages, assuming that the current working directory is the root of +/// the `build` repository checkout. +Future patchBuildDependencies(String packageDir) async { + final pubspec = File(p.join(packageDir, 'pubspec.yaml')); + + if (!await pubspec.exists()) { + throw UnsupportedError('No pubspec.yaml in $packageDir'); + } + + final editor = YamlEditor(await pubspec.readAsString()); + + const targetSection = ['dependency_overrides']; + if (editor + .parseAt(targetSection, orElse: () => YamlScalar.wrap(null)) + .value == + null) { + // There are no `dependency_overrides` in this pubspec, so create an empty + // block first. + editor.update(targetSection, {}); + } + + final buildCheckout = Directory.current.path; + + for (final buildPackage in _buildPackages) { + final path = p.join(buildCheckout, buildPackage); + editor.update([...targetSection, buildPackage], {'path': path}); + } + + await pubspec.writeAsString(editor.toString()); +} diff --git a/tool/mono_repo.yaml b/tool/mono_repo.yaml new file mode 100644 index 000000000..ea4613266 --- /dev/null +++ b/tool/mono_repo.yaml @@ -0,0 +1,12 @@ +sdk: +- dev + +stages: +- analyze_and_format: + - group: + - format + - analyze: --fatal-infos . +- unit_test: + - test: --test-randomize-ordering-seed=random + os: + - linux diff --git a/tool/pubspec.yaml b/tool/pubspec.yaml new file mode 100644 index 000000000..8d7b024d9 --- /dev/null +++ b/tool/pubspec.yaml @@ -0,0 +1,16 @@ +publish_to: none +name: build_development_tools +description: Collection of scripts used during development of build packages. + +environment: + sdk: '>=2.15.0 <3.0.0' + +dependencies: + path: ^1.8.0 + yaml_edit: ^2.0.1 + yaml: ^3.1.0 + +dev_dependencies: + lints: ^1.0.0 + test_descriptor: ^2.0.0 + test: ^1.20.1 diff --git a/tool/test/patch_build_dependencies_test.dart b/tool/test/patch_build_dependencies_test.dart new file mode 100644 index 000000000..5076c6223 --- /dev/null +++ b/tool/test/patch_build_dependencies_test.dart @@ -0,0 +1,102 @@ +import 'dart:io'; + +import 'package:build_development_tools/patch_build_dependencies.dart'; +import 'package:path/path.dart' as p; +import 'package:test/test.dart'; +import 'package:test_descriptor/test_descriptor.dart' as d; + +void main() { + test('without previous overrides', () { + return _testTransformation( + ''' +name: test +environment: + sdk: ^2.12.0 + +dependencies: + foo: ^1.0.0 + +dev_dependencies: + bar: ^1.2.3 +''', + ''' +name: test +environment: + sdk: ^2.12.0 + +dependencies: + foo: ^1.0.0 + +dev_dependencies: + bar: ^1.2.3 +dependency_overrides: {build: {path: ${_packagePath('build')}}, build_config: {path: ${_packagePath('build_config')}}, build_daemon: {path: ${_packagePath('build_daemon')}}, build_modules: {path: ${_packagePath('build_modules')}}, build_resolvers: {path: ${_packagePath('build_resolvers')}}, build_runner: {path: ${_packagePath('build_runner')}}, build_runner_core: {path: ${_packagePath('build_runner_core')}}, build_test: {path: ${_packagePath('build_test')}}, build_vm_compilers: {path: ${_packagePath('build_vm_compilers')}}, build_web_compilers: {path: ${_packagePath('build_web_compilers')}}, scratch_space: {path: ${_packagePath('scratch_space')}}} +''', + ); + }); + + test('with existing overrides', () { + return _testTransformation( + ''' +name: test +environment: + sdk: ^2.12.0 + +dependencies: + foo: ^1.0.0 + +dev_dependencies: + bar: ^1.2.3 + +dependency_overrides: + unrelated: ^1.0.0 + build_runner: ^1.2.3 +''', + ''' +name: test +environment: + sdk: ^2.12.0 + +dependencies: + foo: ^1.0.0 + +dev_dependencies: + bar: ^1.2.3 + +dependency_overrides: + unrelated: ^1.0.0 + build_runner: + path: ${_packagePath('build_runner')} + build: + path: ${_packagePath('build')} + build_config: + path: ${_packagePath('build_config')} + build_daemon: + path: ${_packagePath('build_daemon')} + build_modules: + path: ${_packagePath('build_modules')} + build_resolvers: + path: ${_packagePath('build_resolvers')} + build_runner_core: + path: ${_packagePath('build_runner_core')} + build_test: + path: ${_packagePath('build_test')} + build_vm_compilers: + path: ${_packagePath('build_vm_compilers')} + build_web_compilers: + path: ${_packagePath('build_web_compilers')} + scratch_space: + path: ${_packagePath('scratch_space')} +''', + ); + }); +} + +String _packagePath(String package) { + return p.join(Directory.current.path, package); +} + +Future _testTransformation(String old, String updated) async { + await d.dir('package', [d.file('pubspec.yaml', old)]).create(); + await patchBuildDependencies(p.join(d.sandbox, 'package')); + await d.dir('package', [d.file('pubspec.yaml', updated)]).validate(); +} From 51025eead9d37c98bc0591d67b8f53f85f67f9c9 Mon Sep 17 00:00:00 2001 From: Simon Binder Date: Tue, 18 Jan 2022 23:38:21 +0100 Subject: [PATCH 2/5] Clone into workspace, use right working dir --- .github/workflows/community.yml | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/.github/workflows/community.yml b/.github/workflows/community.yml index bfa9245b3..eafd3c5d4 100644 --- a/.github/workflows/community.yml +++ b/.github/workflows/community.yml @@ -18,10 +18,11 @@ jobs: - uses: actions/checkout@v2 with: repository: simolus3/moor - path: /tmp/drift + path: client_tests - run: |- - dart run tool/bin/patch_build_dependencies.dart /tmp/drift/drift - cd /tmp/drift/drift + dart run tool/bin/patch_build_dependencies.dart client_tests/drift + cd client_tests/drift git add pubspec.yaml - run: dart test --preset build_community_tests name: Drift community tests + working-directory: client_tests/drift From 507d79bd82292390cf6c3c32e2255365a9d347ec Mon Sep 17 00:00:00 2001 From: Simon Binder Date: Wed, 19 Jan 2022 00:01:15 +0100 Subject: [PATCH 3/5] Oh right, it's 2022 already Co-authored-by: Jacob MacDonald --- tool/bin/patch_build_dependencies.dart | 2 +- tool/lib/patch_build_dependencies.dart | 2 +- tool/test/patch_build_dependencies_test.dart | 4 ++++ 3 files changed, 6 insertions(+), 2 deletions(-) diff --git a/tool/bin/patch_build_dependencies.dart b/tool/bin/patch_build_dependencies.dart index 0997422e6..e8d6c7610 100644 --- a/tool/bin/patch_build_dependencies.dart +++ b/tool/bin/patch_build_dependencies.dart @@ -1,4 +1,4 @@ -// Copyright (c) 2021, the Dart project authors. Please see the AUTHORS file +// Copyright (c) 2022, 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. diff --git a/tool/lib/patch_build_dependencies.dart b/tool/lib/patch_build_dependencies.dart index eba0e76be..4f9a86771 100644 --- a/tool/lib/patch_build_dependencies.dart +++ b/tool/lib/patch_build_dependencies.dart @@ -1,4 +1,4 @@ -// Copyright (c) 2021, the Dart project authors. Please see the AUTHORS file +// Copyright (c) 2022, 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. diff --git a/tool/test/patch_build_dependencies_test.dart b/tool/test/patch_build_dependencies_test.dart index 5076c6223..047192be0 100644 --- a/tool/test/patch_build_dependencies_test.dart +++ b/tool/test/patch_build_dependencies_test.dart @@ -1,3 +1,7 @@ +// Copyright (c) 2022, 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. + import 'dart:io'; import 'package:build_development_tools/patch_build_dependencies.dart'; From 75bf1c5982467f3135707c134569cd4c3237deda Mon Sep 17 00:00:00 2001 From: Simon Binder Date: Wed, 19 Jan 2022 18:27:40 +0100 Subject: [PATCH 4/5] Don't use development branch for community tests --- .github/workflows/community.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/community.yml b/.github/workflows/community.yml index eafd3c5d4..c247dd4fa 100644 --- a/.github/workflows/community.yml +++ b/.github/workflows/community.yml @@ -18,6 +18,7 @@ jobs: - uses: actions/checkout@v2 with: repository: simolus3/moor + ref: latest-release path: client_tests - run: |- dart run tool/bin/patch_build_dependencies.dart client_tests/drift From 78f7a3249282d9f80e6cb7e99b78156264a4f2c4 Mon Sep 17 00:00:00 2001 From: Simon Binder Date: Wed, 19 Jan 2022 20:07:02 +0100 Subject: [PATCH 5/5] Place client tests in specific subdirectory --- .github/workflows/community.yml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/community.yml b/.github/workflows/community.yml index c247dd4fa..6d0b69a4e 100644 --- a/.github/workflows/community.yml +++ b/.github/workflows/community.yml @@ -19,11 +19,11 @@ jobs: with: repository: simolus3/moor ref: latest-release - path: client_tests + path: client_tests/drift - run: |- - dart run tool/bin/patch_build_dependencies.dart client_tests/drift - cd client_tests/drift + dart run tool/bin/patch_build_dependencies.dart client_tests/drift/drift + cd client_tests/drift/drift git add pubspec.yaml - run: dart test --preset build_community_tests name: Drift community tests - working-directory: client_tests/drift + working-directory: client_tests/drift/drift