|
| 1 | +// Copyright 2014 The Flutter Authors. All rights reserved. |
| 2 | +// Use of this source code is governed by a BSD-style license that can be |
| 3 | +// found in the LICENSE file. |
| 4 | + |
| 5 | +import 'dart:io' as io; |
| 6 | + |
| 7 | +import 'package:path/path.dart' as p; |
| 8 | + |
| 9 | +/// To run this script, either: |
| 10 | +/// |
| 11 | +/// ```sh |
| 12 | +/// cd dev/customer_testing |
| 13 | +/// dart ci.dart [sha] |
| 14 | +/// ``` |
| 15 | +/// |
| 16 | +/// Or: |
| 17 | +/// |
| 18 | +/// ```sh |
| 19 | +/// ./dev/customer_testing/ci.sh |
| 20 | +/// ./dev/customer_testing/ci.bat |
| 21 | +/// ``` |
| 22 | +void main(List<String> args) async { |
| 23 | + final String sha; |
| 24 | + if (args.isEmpty) { |
| 25 | + sha = io.File('tests.version').readAsStringSync().trim(); |
| 26 | + } else if (args.length == 1) { |
| 27 | + sha = args.first; |
| 28 | + } else { |
| 29 | + io.stderr.writeln('Usage: dart ci.dart [sha]'); |
| 30 | + io.exitCode = 1; |
| 31 | + return; |
| 32 | + } |
| 33 | + |
| 34 | + final String flutterRootPath = p.canonicalize('../../'); |
| 35 | + final io.Directory testsCacheDir = io.Directory( |
| 36 | + p.join(flutterRootPath, 'bin', 'cache', 'pkg', 'tests'), |
| 37 | + ); |
| 38 | + |
| 39 | + if (testsCacheDir.existsSync()) { |
| 40 | + io.stderr.writeln('Cleaning up existing repo: ${testsCacheDir.path}'); |
| 41 | + testsCacheDir.deleteSync(recursive: true); |
| 42 | + } |
| 43 | + |
| 44 | + io.stderr.writeln('Cloning flutter/tests'); |
| 45 | + final io.Process clone = await io.Process.start('git', <String>[ |
| 46 | + 'clone', |
| 47 | + '--depth', |
| 48 | + '1', |
| 49 | + 'https://github.com/flutter/tests.git', |
| 50 | + testsCacheDir.path, |
| 51 | + ], mode: io.ProcessStartMode.inheritStdio); |
| 52 | + if ((await clone.exitCode) != 0) { |
| 53 | + io.exitCode = 1; |
| 54 | + return; |
| 55 | + } |
| 56 | + |
| 57 | + io.stderr.writeln('Fetching/checking out $sha'); |
| 58 | + final io.Process fetch = await io.Process.start( |
| 59 | + 'git', |
| 60 | + <String>['fetch', 'origin', sha], |
| 61 | + mode: io.ProcessStartMode.inheritStdio, |
| 62 | + workingDirectory: testsCacheDir.path, |
| 63 | + ); |
| 64 | + if ((await fetch.exitCode) != 0) { |
| 65 | + io.exitCode = 1; |
| 66 | + return; |
| 67 | + } |
| 68 | + final io.Process checkout = await io.Process.start( |
| 69 | + 'git', |
| 70 | + <String>['checkout', sha], |
| 71 | + mode: io.ProcessStartMode.inheritStdio, |
| 72 | + workingDirectory: testsCacheDir.path, |
| 73 | + ); |
| 74 | + if ((await checkout.exitCode) != 0) { |
| 75 | + io.exitCode = 1; |
| 76 | + return; |
| 77 | + } |
| 78 | + |
| 79 | + io.stderr.writeln('Running tests...'); |
| 80 | + final io.Process test = await io.Process.start('dart', <String>[ |
| 81 | + '--enable-asserts', |
| 82 | + 'run_tests.dart', |
| 83 | + '--skip-on-fetch-failure', |
| 84 | + '--skip-template', |
| 85 | + p.posix.joinAll(<String>[...p.split(testsCacheDir.path), 'registry', '*.test']), |
| 86 | + ], mode: io.ProcessStartMode.inheritStdio); |
| 87 | + if ((await test.exitCode) != 0) { |
| 88 | + io.exitCode = 1; |
| 89 | + return; |
| 90 | + } |
| 91 | +} |
0 commit comments