diff --git a/dev/bots/suite_runners/run_flutter_packages_tests.dart b/dev/bots/suite_runners/run_flutter_packages_tests.dart new file mode 100644 index 0000000000..91e7d4cfed --- /dev/null +++ b/dev/bots/suite_runners/run_flutter_packages_tests.dart @@ -0,0 +1,101 @@ +// Copyright 2014 The Flutter Authors. 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' show Directory, File; + +import 'package:file/file.dart' as fs; +import 'package:file/local.dart'; +import 'package:path/path.dart' as path; + +import '../run_command.dart'; +import '../test.dart'; +import '../utils.dart'; + +/// Executes the test suite for the flutter/packages repo. +Future flutterPackagesRunner(String flutterRoot) async { + + Future runAnalyze() async { + printProgress('${green}Running analysis for flutter/packages$reset'); + final Directory checkout = Directory.systemTemp.createTempSync('flutter_packages.'); + await runCommand( + 'git', + const [ + '-c', + 'core.longPaths=true', + 'clone', + 'https://github.com/flutter/packages.git', + '.', + ], + workingDirectory: checkout.path, + ); + final String packagesCommit = await getFlutterPackagesVersion(flutterRoot: flutterRoot); + await runCommand( + 'git', + [ + '-c', + 'core.longPaths=true', + 'checkout', + packagesCommit, + ], + workingDirectory: checkout.path, + ); + // Prep the repository tooling. + // This test does not use tool_runner.sh because in this context the test + // should always run on the entire packages repo, while tool_runner.sh + // is designed for flutter/packages CI and only analyzes changed repository + // files when run for anything but master. + final String toolDir = path.join(checkout.path, 'script', 'tool'); + await runCommand( + 'dart', + const [ + 'pub', + 'get', + ], + workingDirectory: toolDir, + ); + final String toolScript = path.join(toolDir, 'bin', 'flutter_plugin_tools.dart'); + await runCommand( + 'dart', + [ + 'run', + toolScript, + 'analyze', + // Fetch the oldest possible dependencies, rather than the newest, to + // insulate flutter/flutter from out-of-band failures when new versions + // of dependencies are published. This compensates for the fact that + // flutter/packages doesn't use pinned dependencies, and for the + // purposes of this test using old dependencies is fine. See + // https://github.com/flutter/flutter/issues/129633 + '--downgrade', + '--custom-analysis=script/configs/custom_analysis.yaml', + ], + workingDirectory: checkout.path, + ); + } + await selectSubshard({ + 'analyze': runAnalyze, + }); +} + +/// Returns the commit hash of the flutter/packages repository that's rolled in. +/// +/// The flutter/packages repository is a downstream dependency, it is only used +/// by flutter/flutter for testing purposes, to assure stable tests for a given +/// flutter commit the flutter/packages commit hash to test against is coded in +/// the bin/internal/flutter_packages.version file. +/// +/// The `filesystem` parameter specified filesystem to read the packages version file from. +/// The `packagesVersionFile` parameter allows specifying an alternative path for the +/// packages version file, when null [flutterPackagesVersionFile] is used. +Future getFlutterPackagesVersion({ + fs.FileSystem fileSystem = const LocalFileSystem(), + String? packagesVersionFile, + required String flutterRoot, +}) async { + final String flutterPackagesVersionFile = path.join(flutterRoot, 'bin', 'internal', 'flutter_packages.version'); + + final File versionFile = fileSystem.file(packagesVersionFile ?? flutterPackagesVersionFile); + final String versionFileContents = await versionFile.readAsString(); + return versionFileContents.trim(); +} diff --git a/dev/bots/test.dart b/dev/bots/test.dart index da2c179a6b..19f8bfd773 100644 --- a/dev/bots/test.dart +++ b/dev/bots/test.dart @@ -65,6 +65,7 @@ import 'package:process/process.dart'; import 'run_command.dart'; import 'suite_runners/run_add_to_app_life_cycle_tests.dart'; +import 'suite_runners/run_flutter_packages_tests.dart'; import 'suite_runners/run_skp_generator_tests.dart'; import 'suite_runners/run_web_long_running_tests.dart'; import 'tool_subsharding.dart'; @@ -88,7 +89,6 @@ final String dart = path.join(flutterRoot, 'bin', 'cache', 'dart-sdk', 'bin', 'd final String pubCache = path.join(flutterRoot, '.pub-cache'); final String engineVersionFile = path.join(flutterRoot, 'bin', 'internal', 'engine.version'); final String engineRealmFile = path.join(flutterRoot, 'bin', 'internal', 'engine.realm'); -final String flutterPackagesVersionFile = path.join(flutterRoot, 'bin', 'internal', 'flutter_packages.version'); String get platformFolderName { if (Platform.isWindows) { @@ -248,7 +248,7 @@ Future main(List args) async { 'web_skwasm_tests': _runWebSkwasmUnitTests, // All web integration tests 'web_long_running_tests': () => webLongRunningTestsRunner(flutterRoot), - 'flutter_plugins': _runFlutterPackagesTests, + 'flutter_plugins': () => flutterPackagesRunner(flutterRoot), 'skp_generator': skpGeneratorTestsRunner, 'realm_checker': _runRealmCheckerTest, 'customer_testing': _runCustomerTesting, @@ -1196,90 +1196,6 @@ Future _runWebUnitTests(String webRenderer, bool useWasm) async { await selectSubshard(subshards); } -/// Returns the commit hash of the flutter/packages repository that's rolled in. -/// -/// The flutter/packages repository is a downstream dependency, it is only used -/// by flutter/flutter for testing purposes, to assure stable tests for a given -/// flutter commit the flutter/packages commit hash to test against is coded in -/// the bin/internal/flutter_packages.version file. -/// -/// The `filesystem` parameter specified filesystem to read the packages version file from. -/// The `packagesVersionFile` parameter allows specifying an alternative path for the -/// packages version file, when null [flutterPackagesVersionFile] is used. -Future getFlutterPackagesVersion({ - fs.FileSystem fileSystem = const LocalFileSystem(), - String? packagesVersionFile, -}) async { - final File versionFile = fileSystem.file(packagesVersionFile ?? flutterPackagesVersionFile); - final String versionFileContents = await versionFile.readAsString(); - return versionFileContents.trim(); -} - -/// Executes the test suite for the flutter/packages repo. -Future _runFlutterPackagesTests() async { - Future runAnalyze() async { - printProgress('${green}Running analysis for flutter/packages$reset'); - final Directory checkout = Directory.systemTemp.createTempSync('flutter_packages.'); - await runCommand( - 'git', - [ - '-c', - 'core.longPaths=true', - 'clone', - 'https://github.com/flutter/packages.git', - '.', - ], - workingDirectory: checkout.path, - ); - final String packagesCommit = await getFlutterPackagesVersion(); - await runCommand( - 'git', - [ - '-c', - 'core.longPaths=true', - 'checkout', - packagesCommit, - ], - workingDirectory: checkout.path, - ); - // Prep the repository tooling. - // This test does not use tool_runner.sh because in this context the test - // should always run on the entire packages repo, while tool_runner.sh - // is designed for flutter/packages CI and only analyzes changed repository - // files when run for anything but master. - final String toolDir = path.join(checkout.path, 'script', 'tool'); - await runCommand( - 'dart', - [ - 'pub', - 'get', - ], - workingDirectory: toolDir, - ); - final String toolScript = path.join(toolDir, 'bin', 'flutter_plugin_tools.dart'); - await runCommand( - 'dart', - [ - 'run', - toolScript, - 'analyze', - // Fetch the oldest possible dependencies, rather than the newest, to - // insulate flutter/flutter from out-of-band failures when new versions - // of dependencies are published. This compensates for the fact that - // flutter/packages doesn't use pinned dependencies, and for the - // purposes of this test using old dependencies is fine. See - // https://github.com/flutter/flutter/issues/129633 - '--downgrade', - '--custom-analysis=script/configs/custom_analysis.yaml', - ], - workingDirectory: checkout.path, - ); - } - await selectSubshard({ - 'analyze': runAnalyze, - }); -} - // Runs customer_testing. Future _runCustomerTesting() async { printProgress('${green}Running customer testing$reset'); diff --git a/dev/bots/test/test_test.dart b/dev/bots/test/test_test.dart index 9994f66d00..77f16e91b7 100644 --- a/dev/bots/test/test_test.dart +++ b/dev/bots/test/test_test.dart @@ -9,6 +9,7 @@ import 'package:file/memory.dart'; import 'package:path/path.dart' as path; import 'package:process/process.dart'; +import '../suite_runners/run_flutter_packages_tests.dart'; import '../test.dart'; import 'common.dart'; @@ -92,13 +93,13 @@ void main() { test('commit hash', () async { packagesVersionFile.writeAsStringSync(kSampleHash); - final String actualHash = await getFlutterPackagesVersion(fileSystem: memoryFileSystem, packagesVersionFile: packagesVersionFile.path); + final String actualHash = await getFlutterPackagesVersion(flutterRoot: flutterRoot, fileSystem: memoryFileSystem, packagesVersionFile: packagesVersionFile.path); expect(actualHash, kSampleHash); }); test('commit hash with newlines', () async { packagesVersionFile.writeAsStringSync('\n$kSampleHash\n'); - final String actualHash = await getFlutterPackagesVersion(fileSystem: memoryFileSystem, packagesVersionFile: packagesVersionFile.path); + final String actualHash = await getFlutterPackagesVersion(flutterRoot: flutterRoot, fileSystem: memoryFileSystem, packagesVersionFile: packagesVersionFile.path); expect(actualHash, kSampleHash); }); });