[flutter_conductor] Add "start", "status", "clean" commands to conductor release tool (#80528)
This commit is contained in:
committed by
GitHub
parent
dc40e23893
commit
4a7f280687
97
dev/tools/test/clean_test.dart
Normal file
97
dev/tools/test/clean_test.dart
Normal file
@@ -0,0 +1,97 @@
|
||||
// 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 'package:args/command_runner.dart';
|
||||
import 'package:dev_tools/clean.dart';
|
||||
import 'package:dev_tools/repository.dart';
|
||||
import 'package:file/file.dart';
|
||||
import 'package:file/memory.dart';
|
||||
import 'package:platform/platform.dart';
|
||||
|
||||
import '../../../packages/flutter_tools/test/src/fake_process_manager.dart';
|
||||
import './common.dart';
|
||||
|
||||
void main() {
|
||||
group('clean command', () {
|
||||
const String flutterRoot = '/flutter';
|
||||
const String checkoutsParentDirectory = '$flutterRoot/dev/tools/';
|
||||
|
||||
MemoryFileSystem fileSystem;
|
||||
FakePlatform platform;
|
||||
TestStdio stdio;
|
||||
FakeProcessManager processManager;
|
||||
|
||||
setUp(() {
|
||||
stdio = TestStdio();
|
||||
fileSystem = MemoryFileSystem.test();
|
||||
});
|
||||
|
||||
tearDown(() {
|
||||
// Ensure these don't get re-used between tests
|
||||
stdio = null;
|
||||
fileSystem = null;
|
||||
processManager = null;
|
||||
platform = null;
|
||||
});
|
||||
|
||||
CommandRunner<void> createRunner({
|
||||
List<FakeCommand> commands,
|
||||
String operatingSystem,
|
||||
}) {
|
||||
operatingSystem ??= const LocalPlatform().operatingSystem;
|
||||
final String pathSeparator = operatingSystem == 'windows' ? r'\' : '/';
|
||||
|
||||
processManager = FakeProcessManager.list(commands ?? <FakeCommand>[]);
|
||||
platform = FakePlatform(
|
||||
environment: <String, String>{'HOME': '/path/to/user/home'},
|
||||
pathSeparator: pathSeparator,
|
||||
);
|
||||
final Checkouts checkouts = Checkouts(
|
||||
fileSystem: fileSystem,
|
||||
parentDirectory: fileSystem.directory(checkoutsParentDirectory),
|
||||
platform: platform,
|
||||
processManager: processManager,
|
||||
stdio: stdio,
|
||||
);
|
||||
final CleanCommand command = CleanCommand(
|
||||
checkouts: checkouts,
|
||||
);
|
||||
return CommandRunner<void>('clean-test', '')..addCommand(command);
|
||||
}
|
||||
|
||||
test('throws if no state file found', () async {
|
||||
final CommandRunner<void> runner = createRunner();
|
||||
const String stateFile = '/state-file.json';
|
||||
|
||||
await expectLater(
|
||||
() async => runner.run(<String>[
|
||||
'clean',
|
||||
'--$kStateOption',
|
||||
stateFile,
|
||||
'--$kYesFlag',
|
||||
]),
|
||||
throwsExceptionWith(
|
||||
'No persistent state file found at $stateFile',
|
||||
),
|
||||
);
|
||||
});
|
||||
|
||||
test('deletes state file', () async {
|
||||
final CommandRunner<void> runner = createRunner();
|
||||
final File stateFile = fileSystem.file('/state-file.json');
|
||||
stateFile.writeAsStringSync('{}');
|
||||
|
||||
await runner.run(<String>[
|
||||
'clean',
|
||||
'--$kStateOption',
|
||||
stateFile.path,
|
||||
'--$kYesFlag',
|
||||
]);
|
||||
|
||||
expect(stateFile.existsSync(), false);
|
||||
});
|
||||
}, onPlatform: <String, dynamic>{
|
||||
'windows': const Skip('Flutter Conductor only supported on macos/linux'),
|
||||
});
|
||||
}
|
||||
@@ -21,11 +21,14 @@ void main() {
|
||||
() async {
|
||||
const Platform platform = LocalPlatform();
|
||||
const FileSystem fileSystem = LocalFileSystem();
|
||||
final Directory tempDir = fileSystem.systemTempDirectory.createTempSync(
|
||||
'conductor_integration_test',
|
||||
);
|
||||
const ProcessManager processManager = LocalProcessManager();
|
||||
final TestStdio stdio = TestStdio(verbose: true);
|
||||
final Checkouts checkouts = Checkouts(
|
||||
fileSystem: fileSystem,
|
||||
parentDirectory: localFlutterRoot.parent,
|
||||
parentDirectory: tempDir,
|
||||
platform: platform,
|
||||
processManager: processManager,
|
||||
stdio: stdio,
|
||||
|
||||
@@ -109,6 +109,8 @@ void main() {
|
||||
const FakeCommand(command: <String>[
|
||||
'git',
|
||||
'clone',
|
||||
'--origin',
|
||||
'upstream',
|
||||
'--',
|
||||
'file://$flutterRoot/',
|
||||
'${checkoutsParentDirectory}flutter_conductor_checkouts/framework',
|
||||
@@ -194,6 +196,8 @@ void main() {
|
||||
const FakeCommand(command: <String>[
|
||||
'git',
|
||||
'clone',
|
||||
'--origin',
|
||||
'upstream',
|
||||
'--',
|
||||
'file://$flutterRoot/',
|
||||
'${checkoutsParentDirectory}flutter_conductor_checkouts/framework',
|
||||
@@ -279,6 +283,8 @@ void main() {
|
||||
const FakeCommand(command: <String>[
|
||||
'git',
|
||||
'clone',
|
||||
'--origin',
|
||||
'upstream',
|
||||
'--',
|
||||
'file://$flutterRoot/',
|
||||
'${checkoutsParentDirectory}flutter_conductor_checkouts/framework',
|
||||
@@ -336,6 +342,8 @@ void main() {
|
||||
const FakeCommand(command: <String>[
|
||||
'git',
|
||||
'clone',
|
||||
'--origin',
|
||||
'upstream',
|
||||
'--',
|
||||
'file://$flutterRoot/',
|
||||
'${checkoutsParentDirectory}flutter_conductor_checkouts/framework',
|
||||
|
||||
@@ -35,7 +35,7 @@ Matcher throwsExceptionWith(String messageSubString) {
|
||||
);
|
||||
}
|
||||
|
||||
class TestStdio implements Stdio {
|
||||
class TestStdio extends Stdio {
|
||||
TestStdio({
|
||||
this.verbose = false,
|
||||
List<String> stdin,
|
||||
@@ -43,36 +43,15 @@ class TestStdio implements Stdio {
|
||||
_stdin = stdin ?? <String>[];
|
||||
}
|
||||
|
||||
final StringBuffer _error = StringBuffer();
|
||||
String get error => _error.toString();
|
||||
String get error => logs.where((String log) => log.startsWith(r'[error] ')).join('\n');
|
||||
|
||||
String get stdout => logs.where((String log) {
|
||||
return log.startsWith(r'[status] ') || log.startsWith(r'[trace] ');
|
||||
}).join('\n');
|
||||
|
||||
final StringBuffer _stdout = StringBuffer();
|
||||
String get stdout => _stdout.toString();
|
||||
final bool verbose;
|
||||
List<String> _stdin;
|
||||
|
||||
@override
|
||||
void printError(String message) {
|
||||
_error.writeln(message);
|
||||
}
|
||||
|
||||
@override
|
||||
void printStatus(String message) {
|
||||
_stdout.writeln(message);
|
||||
}
|
||||
|
||||
@override
|
||||
void printTrace(String message) {
|
||||
if (verbose) {
|
||||
_stdout.writeln(message);
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
void write(String message) {
|
||||
_stdout.write(message);
|
||||
}
|
||||
|
||||
@override
|
||||
String readLineSync() {
|
||||
if (_stdin.isEmpty) {
|
||||
|
||||
@@ -7,7 +7,6 @@ import 'package:file/local.dart';
|
||||
import 'package:platform/platform.dart';
|
||||
import 'package:process/process.dart';
|
||||
|
||||
import 'package:dev_tools/globals.dart';
|
||||
import 'package:dev_tools/roll_dev.dart' show rollDev;
|
||||
import 'package:dev_tools/repository.dart';
|
||||
import 'package:dev_tools/version.dart';
|
||||
@@ -25,15 +24,17 @@ void main() {
|
||||
Checkouts checkouts;
|
||||
FrameworkRepository frameworkUpstream;
|
||||
FrameworkRepository framework;
|
||||
Directory tempDir;
|
||||
|
||||
setUp(() {
|
||||
platform = const LocalPlatform();
|
||||
fileSystem = const LocalFileSystem();
|
||||
processManager = const LocalProcessManager();
|
||||
stdio = TestStdio(verbose: true);
|
||||
tempDir = fileSystem.systemTempDirectory.createTempSync('flutter_conductor_checkouts');
|
||||
checkouts = Checkouts(
|
||||
fileSystem: fileSystem,
|
||||
parentDirectory: localFlutterRoot.parent,
|
||||
parentDirectory: tempDir,
|
||||
platform: platform,
|
||||
processManager: processManager,
|
||||
stdio: stdio,
|
||||
@@ -45,7 +46,7 @@ void main() {
|
||||
framework = FrameworkRepository(
|
||||
checkouts,
|
||||
name: 'test-framework',
|
||||
upstream: 'file://${frameworkUpstream.checkoutDirectory.path}/',
|
||||
fetchRemote: Remote(name: RemoteName.upstream, url: 'file://${frameworkUpstream.checkoutDirectory.path}/'),
|
||||
);
|
||||
});
|
||||
|
||||
@@ -59,7 +60,7 @@ void main() {
|
||||
commit: latestCommit,
|
||||
// Ensure this test passes after a dev release with hotfixes
|
||||
force: true,
|
||||
remote: 'origin',
|
||||
remote: 'upstream',
|
||||
);
|
||||
|
||||
expect(
|
||||
@@ -96,7 +97,7 @@ void main() {
|
||||
commit: latestCommit,
|
||||
// Ensure this test passes after a dev release with hotfixes
|
||||
force: true,
|
||||
remote: 'origin',
|
||||
remote: 'upstream',
|
||||
);
|
||||
|
||||
expect(
|
||||
@@ -124,7 +125,7 @@ void main() {
|
||||
expect(finalVersion.m, 0);
|
||||
expect(finalVersion.n, 0);
|
||||
expect(finalVersion.commits, null);
|
||||
}, skip: 'TODO(fujino): https://github.com/flutter/flutter/issues/80463');
|
||||
});
|
||||
}, onPlatform: <String, dynamic>{
|
||||
'windows': const Skip('Flutter Conductor only supported on macos/linux'),
|
||||
});
|
||||
|
||||
@@ -83,6 +83,8 @@ void main() {
|
||||
const FakeCommand(command: <String>[
|
||||
'git',
|
||||
'clone',
|
||||
'--origin',
|
||||
'upstream',
|
||||
'--',
|
||||
kUpstreamRemote,
|
||||
'${checkoutsParentDirectory}flutter_conductor_checkouts/framework',
|
||||
@@ -131,6 +133,8 @@ void main() {
|
||||
const FakeCommand(command: <String>[
|
||||
'git',
|
||||
'clone',
|
||||
'--origin',
|
||||
'upstream',
|
||||
'--',
|
||||
kUpstreamRemote,
|
||||
'${checkoutsParentDirectory}flutter_conductor_checkouts/framework',
|
||||
@@ -193,16 +197,16 @@ void main() {
|
||||
),
|
||||
false,
|
||||
);
|
||||
expect(stdio.stdout.contains(nextVersion), true);
|
||||
expect(stdio.logs.join('').contains(nextVersion), true);
|
||||
});
|
||||
|
||||
test(
|
||||
'exits with exception if --skip-tagging is provided but commit isn\'t '
|
||||
'already tagged', () {
|
||||
test("exits with exception if --skip-tagging is provided but commit isn't already tagged", () {
|
||||
processManager.addCommands(<FakeCommand>[
|
||||
const FakeCommand(command: <String>[
|
||||
'git',
|
||||
'clone',
|
||||
'--origin',
|
||||
'upstream',
|
||||
'--',
|
||||
kUpstreamRemote,
|
||||
'${checkoutsParentDirectory}flutter_conductor_checkouts/framework',
|
||||
@@ -283,6 +287,8 @@ void main() {
|
||||
const FakeCommand(command: <String>[
|
||||
'git',
|
||||
'clone',
|
||||
'--origin',
|
||||
'upstream',
|
||||
'--',
|
||||
kUpstreamRemote,
|
||||
'${checkoutsParentDirectory}flutter_conductor_checkouts/framework',
|
||||
@@ -356,6 +362,8 @@ void main() {
|
||||
const FakeCommand(command: <String>[
|
||||
'git',
|
||||
'clone',
|
||||
'--origin',
|
||||
'upstream',
|
||||
'--',
|
||||
kUpstreamRemote,
|
||||
'${checkoutsParentDirectory}flutter_conductor_checkouts/framework',
|
||||
@@ -433,6 +441,8 @@ void main() {
|
||||
const FakeCommand(command: <String>[
|
||||
'git',
|
||||
'clone',
|
||||
'--origin',
|
||||
'upstream',
|
||||
'--',
|
||||
kUpstreamRemote,
|
||||
'${checkoutsParentDirectory}flutter_conductor_checkouts/framework',
|
||||
@@ -526,6 +536,8 @@ void main() {
|
||||
const FakeCommand(command: <String>[
|
||||
'git',
|
||||
'clone',
|
||||
'--origin',
|
||||
'upstream',
|
||||
'--',
|
||||
kUpstreamRemote,
|
||||
'${checkoutsParentDirectory}flutter_conductor_checkouts/framework',
|
||||
@@ -623,6 +635,8 @@ void main() {
|
||||
const FakeCommand(command: <String>[
|
||||
'git',
|
||||
'clone',
|
||||
'--origin',
|
||||
'upstream',
|
||||
'--',
|
||||
kUpstreamRemote,
|
||||
'${checkoutsParentDirectory}flutter_conductor_checkouts/framework',
|
||||
|
||||
255
dev/tools/test/start_test.dart
Normal file
255
dev/tools/test/start_test.dart
Normal file
@@ -0,0 +1,255 @@
|
||||
// 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:convert' show jsonDecode;
|
||||
|
||||
import 'package:args/command_runner.dart';
|
||||
import 'package:dev_tools/proto/conductor_state.pb.dart' as pb;
|
||||
import 'package:dev_tools/proto/conductor_state.pbenum.dart' show ReleasePhase;
|
||||
import 'package:dev_tools/start.dart';
|
||||
import 'package:dev_tools/state.dart';
|
||||
import 'package:dev_tools/repository.dart';
|
||||
import 'package:file/file.dart';
|
||||
import 'package:file/memory.dart';
|
||||
import 'package:platform/platform.dart';
|
||||
|
||||
import '../../../packages/flutter_tools/test/src/fake_process_manager.dart';
|
||||
import './common.dart';
|
||||
|
||||
void main() {
|
||||
group('start command', () {
|
||||
const String flutterRoot = '/flutter';
|
||||
const String checkoutsParentDirectory = '$flutterRoot/dev/tools/';
|
||||
const String frameworkMirror = 'https://github.com/user/flutter.git';
|
||||
const String engineMirror = 'https://github.com/user/engine.git';
|
||||
const String candidateBranch = 'flutter-1.2-candidate.3';
|
||||
const String releaseChannel = 'stable';
|
||||
const String revision = 'abcd1234';
|
||||
Checkouts checkouts;
|
||||
MemoryFileSystem fileSystem;
|
||||
FakePlatform platform;
|
||||
TestStdio stdio;
|
||||
FakeProcessManager processManager;
|
||||
|
||||
setUp(() {
|
||||
stdio = TestStdio();
|
||||
fileSystem = MemoryFileSystem.test();
|
||||
});
|
||||
|
||||
CommandRunner<void> createRunner({
|
||||
Map<String, String> environment,
|
||||
String operatingSystem,
|
||||
List<FakeCommand> commands,
|
||||
}) {
|
||||
operatingSystem ??= const LocalPlatform().operatingSystem;
|
||||
final String pathSeparator = operatingSystem == 'windows' ? r'\' : '/';
|
||||
environment ??= <String, String>{
|
||||
'HOME': '/path/to/user/home',
|
||||
};
|
||||
final Directory homeDir = fileSystem.directory(
|
||||
environment['HOME'],
|
||||
);
|
||||
// Tool assumes this exists
|
||||
homeDir.createSync(recursive: true);
|
||||
platform = FakePlatform(
|
||||
environment: environment,
|
||||
operatingSystem: operatingSystem,
|
||||
pathSeparator: pathSeparator,
|
||||
);
|
||||
processManager = FakeProcessManager.list(commands ?? <FakeCommand>[]);
|
||||
checkouts = Checkouts(
|
||||
fileSystem: fileSystem,
|
||||
parentDirectory: fileSystem.directory(checkoutsParentDirectory),
|
||||
platform: platform,
|
||||
processManager: processManager,
|
||||
stdio: stdio,
|
||||
);
|
||||
final StartCommand command = StartCommand(
|
||||
checkouts: checkouts,
|
||||
flutterRoot: fileSystem.directory(flutterRoot),
|
||||
);
|
||||
return CommandRunner<void>('codesign-test', '')..addCommand(command);
|
||||
}
|
||||
|
||||
tearDown(() {
|
||||
// Ensure we don't re-use these between tests.
|
||||
processManager = null;
|
||||
checkouts = null;
|
||||
platform = null;
|
||||
});
|
||||
|
||||
test('throws exception if run from Windows', () async {
|
||||
final CommandRunner<void> runner = createRunner(
|
||||
commands: <FakeCommand>[
|
||||
const FakeCommand(
|
||||
command: <String>['git', 'rev-parse', 'HEAD'],
|
||||
stdout: revision,
|
||||
),
|
||||
],
|
||||
operatingSystem: 'windows',
|
||||
);
|
||||
await expectLater(
|
||||
() async => runner.run(<String>['start']),
|
||||
throwsExceptionWith(
|
||||
'Error! This tool is only supported on macOS and Linux',
|
||||
),
|
||||
);
|
||||
});
|
||||
|
||||
test('throws if --$kFrameworkMirrorOption not provided', () async {
|
||||
final CommandRunner<void> runner = createRunner(
|
||||
commands: <FakeCommand>[
|
||||
const FakeCommand(
|
||||
command: <String>['git', 'rev-parse', 'HEAD'],
|
||||
stdout: revision,
|
||||
),
|
||||
],
|
||||
);
|
||||
|
||||
await expectLater(
|
||||
() async => runner.run(<String>['start']),
|
||||
throwsExceptionWith(
|
||||
'Expected either the CLI arg --$kFrameworkMirrorOption or the environment variable FRAMEWORK_MIRROR to be provided',
|
||||
),
|
||||
);
|
||||
});
|
||||
|
||||
test('creates state file if provided correct inputs', () async {
|
||||
const String revision2 = 'def789';
|
||||
const String revision3 = '123abc';
|
||||
|
||||
final List<FakeCommand> engineCommands = <FakeCommand>[
|
||||
FakeCommand(
|
||||
command: <String>[
|
||||
'git',
|
||||
'clone',
|
||||
'--origin',
|
||||
'upstream',
|
||||
'--',
|
||||
EngineRepository.defaultUpstream,
|
||||
fileSystem.path.join(
|
||||
checkoutsParentDirectory,
|
||||
'flutter_conductor_checkouts',
|
||||
'engine',
|
||||
),
|
||||
],
|
||||
),
|
||||
const FakeCommand(
|
||||
command: <String>['git', 'remote', 'add', 'mirror', engineMirror],
|
||||
),
|
||||
const FakeCommand(
|
||||
command: <String>['git', 'fetch', 'mirror'],
|
||||
),
|
||||
const FakeCommand(
|
||||
command: <String>['git', 'checkout', 'upstream/$candidateBranch'],
|
||||
),
|
||||
const FakeCommand(
|
||||
command: <String>['git', 'rev-parse', 'HEAD'],
|
||||
stdout: revision2,
|
||||
),
|
||||
const FakeCommand(
|
||||
command: <String>[
|
||||
'git',
|
||||
'checkout',
|
||||
'-b',
|
||||
'cherrypicks-$candidateBranch',
|
||||
],
|
||||
),
|
||||
const FakeCommand(
|
||||
command: <String>['git', 'rev-parse', 'HEAD'],
|
||||
stdout: revision2,
|
||||
),
|
||||
];
|
||||
final List<FakeCommand> frameworkCommands = <FakeCommand>[
|
||||
FakeCommand(
|
||||
command: <String>[
|
||||
'git',
|
||||
'clone',
|
||||
'--origin',
|
||||
'upstream',
|
||||
'--',
|
||||
FrameworkRepository.defaultUpstream,
|
||||
fileSystem.path.join(
|
||||
checkoutsParentDirectory,
|
||||
'flutter_conductor_checkouts',
|
||||
'framework',
|
||||
),
|
||||
],
|
||||
),
|
||||
const FakeCommand(
|
||||
command: <String>['git', 'remote', 'add', 'mirror', frameworkMirror],
|
||||
),
|
||||
const FakeCommand(
|
||||
command: <String>['git', 'fetch', 'mirror'],
|
||||
),
|
||||
const FakeCommand(
|
||||
command: <String>['git', 'checkout', 'upstream/$candidateBranch'],
|
||||
),
|
||||
const FakeCommand(
|
||||
command: <String>['git', 'rev-parse', 'HEAD'],
|
||||
stdout: revision3,
|
||||
),
|
||||
const FakeCommand(
|
||||
command: <String>[
|
||||
'git',
|
||||
'checkout',
|
||||
'-b',
|
||||
'cherrypicks-$candidateBranch',
|
||||
],
|
||||
),
|
||||
const FakeCommand(
|
||||
command: <String>['git', 'rev-parse', 'HEAD'],
|
||||
stdout: revision3,
|
||||
),
|
||||
];
|
||||
final CommandRunner<void> runner = createRunner(
|
||||
commands: <FakeCommand>[
|
||||
const FakeCommand(
|
||||
command: <String>['git', 'rev-parse', 'HEAD'],
|
||||
stdout: revision,
|
||||
),
|
||||
...engineCommands,
|
||||
...frameworkCommands,
|
||||
],
|
||||
);
|
||||
|
||||
final String stateFilePath = fileSystem.path.join(
|
||||
platform.environment['HOME'],
|
||||
kStateFileName,
|
||||
);
|
||||
|
||||
await runner.run(<String>[
|
||||
'start',
|
||||
'--$kFrameworkMirrorOption',
|
||||
frameworkMirror,
|
||||
'--$kEngineMirrorOption',
|
||||
engineMirror,
|
||||
'--$kCandidateOption',
|
||||
candidateBranch,
|
||||
'--$kReleaseOption',
|
||||
releaseChannel,
|
||||
'--$kStateOption',
|
||||
stateFilePath,
|
||||
]);
|
||||
|
||||
final File stateFile = fileSystem.file(stateFilePath);
|
||||
|
||||
final pb.ConductorState state = pb.ConductorState();
|
||||
state.mergeFromProto3Json(
|
||||
jsonDecode(stateFile.readAsStringSync()),
|
||||
);
|
||||
|
||||
expect(state.isInitialized(), true);
|
||||
expect(state.releaseChannel, releaseChannel);
|
||||
expect(state.engine.candidateBranch, candidateBranch);
|
||||
expect(state.engine.startingGitHead, revision2);
|
||||
expect(state.framework.candidateBranch, candidateBranch);
|
||||
expect(state.framework.startingGitHead, revision3);
|
||||
expect(state.lastPhase, ReleasePhase.INITIALIZE);
|
||||
expect(state.conductorVersion, revision);
|
||||
});
|
||||
}, onPlatform: <String, dynamic>{
|
||||
'windows': const Skip('Flutter Conductor only supported on macos/linux'),
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user