Create packages only for release builds, and publish when created. (#14476)
This changes the publishing of archives so that it happens on the chrome_infra bots when they build a packaged branch instead of as part of the dev_roll process. It uses the tagged version in the branch, and leaves the git repo that it clones checked out on the branch and hash used to build the package. It updates metadata located at gs://flutter_infra/releases/releases_.json (where is one of macos, linux, or windows) once published, since it would be complex to do the proper locking to keep them all in one shared .json file safely. A separate [change to the chrome_infra bots](https://chromium-review.googlesource.com/c/chromium/tools/build/+/902823) was made to instruct them to build packaged for the dev, beta, and release branches (but not master anymore).
This commit is contained in:
189
dev/bots/test/fake_process_manager.dart
Normal file
189
dev/bots/test/fake_process_manager.dart
Normal file
@@ -0,0 +1,189 @@
|
||||
// Copyright 2018 The Chromium 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:async';
|
||||
import 'dart:convert';
|
||||
import 'dart:io';
|
||||
|
||||
import 'package:process/process.dart';
|
||||
import 'package:mockito/mockito.dart';
|
||||
import 'package:test/test.dart';
|
||||
|
||||
/// A mock that can be used to fake a process manager that runs commands
|
||||
/// and returns results.
|
||||
///
|
||||
/// Call [setResults] to provide a list of results that will return from
|
||||
/// each command line (with arguments).
|
||||
///
|
||||
/// Call [verifyCalls] to verify that each desired call occurred.
|
||||
class FakeProcessManager extends Mock implements ProcessManager {
|
||||
FakeProcessManager({this.stdinResults}) {
|
||||
_setupMock();
|
||||
}
|
||||
|
||||
/// The callback that will be called each time stdin input is supplied to
|
||||
/// a call.
|
||||
final StringReceivedCallback stdinResults;
|
||||
|
||||
/// The list of results that will be sent back, organized by the command line
|
||||
/// that will produce them. Each command line has a list of returned stdout
|
||||
/// output that will be returned on each successive call.
|
||||
Map<String, List<ProcessResult>> _fakeResults = <String, List<ProcessResult>>{};
|
||||
Map<String, List<ProcessResult>> get fakeResults => _fakeResults;
|
||||
set fakeResults(Map<String, List<ProcessResult>> value) {
|
||||
_fakeResults = <String, List<ProcessResult>>{};
|
||||
for (String key in value.keys) {
|
||||
_fakeResults[key] = <ProcessResult>[]
|
||||
..addAll(value[key] ?? <ProcessResult>[new ProcessResult(0, 0, '', '')]);
|
||||
}
|
||||
}
|
||||
|
||||
/// The list of invocations that occurred, in the order they occurred.
|
||||
List<Invocation> invocations = <Invocation>[];
|
||||
|
||||
/// Verify that the given command lines were called, in the given order, and that the
|
||||
/// parameters were in the same order.
|
||||
void verifyCalls(List<String> calls) {
|
||||
int index = 0;
|
||||
for (String call in calls) {
|
||||
expect(call.split(' '), orderedEquals(invocations[index].positionalArguments[0]));
|
||||
index++;
|
||||
}
|
||||
expect(invocations.length, equals(calls.length));
|
||||
}
|
||||
|
||||
ProcessResult _popResult(List<String> command) {
|
||||
final String key = command.join(' ');
|
||||
expect(fakeResults, isNotEmpty);
|
||||
expect(fakeResults, contains(key));
|
||||
expect(fakeResults[key], isNotEmpty);
|
||||
return fakeResults[key].removeAt(0);
|
||||
}
|
||||
|
||||
FakeProcess _popProcess(List<String> command) =>
|
||||
new FakeProcess(_popResult(command), stdinResults: stdinResults);
|
||||
|
||||
Future<Process> _nextProcess(Invocation invocation) async {
|
||||
invocations.add(invocation);
|
||||
return new Future<Process>.value(_popProcess(invocation.positionalArguments[0]));
|
||||
}
|
||||
|
||||
ProcessResult _nextResultSync(Invocation invocation) {
|
||||
invocations.add(invocation);
|
||||
return _popResult(invocation.positionalArguments[0]);
|
||||
}
|
||||
|
||||
Future<ProcessResult> _nextResult(Invocation invocation) async {
|
||||
invocations.add(invocation);
|
||||
return new Future<ProcessResult>.value(_popResult(invocation.positionalArguments[0]));
|
||||
}
|
||||
|
||||
void _setupMock() {
|
||||
// Note that not all possible types of invocations are covered here, just the ones
|
||||
// expected to be called.
|
||||
// TODO(gspencer): make this more general so that any call will be captured.
|
||||
when(start(
|
||||
typed(captureAny),
|
||||
environment: typed(captureAny, named: 'environment'),
|
||||
workingDirectory: typed(captureAny, named: 'workingDirectory'),
|
||||
)).thenAnswer(_nextProcess);
|
||||
|
||||
when(start(typed(captureAny))).thenAnswer(_nextProcess);
|
||||
|
||||
when(run(
|
||||
typed(captureAny),
|
||||
environment: typed(captureAny, named: 'environment'),
|
||||
workingDirectory: typed(captureAny, named: 'workingDirectory'),
|
||||
)).thenAnswer(_nextResult);
|
||||
|
||||
when(run(typed(captureAny))).thenAnswer(_nextResult);
|
||||
|
||||
when(runSync(
|
||||
typed(captureAny),
|
||||
environment: typed(captureAny, named: 'environment'),
|
||||
workingDirectory: typed(captureAny, named: 'workingDirectory')
|
||||
)).thenAnswer(_nextResultSync);
|
||||
|
||||
when(runSync(typed(captureAny))).thenAnswer(_nextResultSync);
|
||||
|
||||
when(killPid(typed(captureAny), typed(captureAny))).thenReturn(true);
|
||||
|
||||
when(canRun(captureAny, workingDirectory: typed(captureAny, named: 'workingDirectory')))
|
||||
.thenReturn(true);
|
||||
}
|
||||
}
|
||||
|
||||
/// A fake process that can be used to interact with a process "started" by the FakeProcessManager.
|
||||
class FakeProcess extends Mock implements Process {
|
||||
FakeProcess(ProcessResult result, {void stdinResults(String input)})
|
||||
: stdoutStream = new Stream<List<int>>.fromIterable(<List<int>>[result.stdout.codeUnits]),
|
||||
stderrStream = new Stream<List<int>>.fromIterable(<List<int>>[result.stderr.codeUnits]),
|
||||
desiredExitCode = result.exitCode,
|
||||
stdinSink = new IOSink(new StringStreamConsumer(stdinResults)) {
|
||||
_setupMock();
|
||||
}
|
||||
|
||||
final IOSink stdinSink;
|
||||
final Stream<List<int>> stdoutStream;
|
||||
final Stream<List<int>> stderrStream;
|
||||
final int desiredExitCode;
|
||||
|
||||
void _setupMock() {
|
||||
when(kill(typed(captureAny))).thenReturn(true);
|
||||
}
|
||||
|
||||
@override
|
||||
Future<int> get exitCode => new Future<int>.value(desiredExitCode);
|
||||
|
||||
@override
|
||||
int get pid => 0;
|
||||
|
||||
@override
|
||||
IOSink get stdin => stdinSink;
|
||||
|
||||
@override
|
||||
Stream<List<int>> get stderr => stderrStream;
|
||||
|
||||
@override
|
||||
Stream<List<int>> get stdout => stdoutStream;
|
||||
}
|
||||
|
||||
/// Callback used to receive stdin input when it occurs.
|
||||
typedef void StringReceivedCallback(String received);
|
||||
|
||||
/// A stream consumer class that consumes UTF8 strings as lists of ints.
|
||||
class StringStreamConsumer implements StreamConsumer<List<int>> {
|
||||
StringStreamConsumer(this.sendString);
|
||||
|
||||
List<Stream<List<int>>> streams = <Stream<List<int>>>[];
|
||||
List<StreamSubscription<List<int>>> subscriptions = <StreamSubscription<List<int>>>[];
|
||||
List<Completer<dynamic>> completers = <Completer<dynamic>>[];
|
||||
|
||||
/// The callback called when this consumer receives input.
|
||||
StringReceivedCallback sendString;
|
||||
|
||||
@override
|
||||
Future<dynamic> addStream(Stream<List<int>> value) {
|
||||
streams.add(value);
|
||||
completers.add(new Completer<dynamic>());
|
||||
subscriptions.add(
|
||||
value.listen((List<int> data) {
|
||||
sendString(utf8.decode(data));
|
||||
}),
|
||||
);
|
||||
subscriptions.last.onDone(() => completers.last.complete(null));
|
||||
return new Future<dynamic>.value(null);
|
||||
}
|
||||
|
||||
@override
|
||||
Future<dynamic> close() async {
|
||||
for (Completer<dynamic> completer in completers) {
|
||||
await completer.future;
|
||||
}
|
||||
completers.clear();
|
||||
streams.clear();
|
||||
subscriptions.clear();
|
||||
return new Future<dynamic>.value(null);
|
||||
}
|
||||
}
|
||||
108
dev/bots/test/fake_process_manager_test.dart
Normal file
108
dev/bots/test/fake_process_manager_test.dart
Normal file
@@ -0,0 +1,108 @@
|
||||
// Copyright 2018 The Chromium 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';
|
||||
import 'dart:io';
|
||||
|
||||
import 'package:test/test.dart';
|
||||
|
||||
import 'fake_process_manager.dart';
|
||||
|
||||
void main() {
|
||||
group('ArchivePublisher', () {
|
||||
FakeProcessManager processManager;
|
||||
final List<String> stdinCaptured = <String>[];
|
||||
|
||||
void _captureStdin(String item) {
|
||||
stdinCaptured.add(item);
|
||||
}
|
||||
|
||||
setUp(() async {
|
||||
processManager = new FakeProcessManager(stdinResults: _captureStdin);
|
||||
});
|
||||
|
||||
tearDown(() async {});
|
||||
|
||||
test('start works', () async {
|
||||
final Map<String, List<ProcessResult>> calls = <String, List<ProcessResult>>{
|
||||
'gsutil acl get gs://flutter_infra/releases/releases.json': <ProcessResult>[
|
||||
new ProcessResult(0, 0, 'output1', '')
|
||||
],
|
||||
'gsutil cat gs://flutter_infra/releases/releases.json': <ProcessResult>[
|
||||
new ProcessResult(0, 0, 'output2', '')
|
||||
],
|
||||
};
|
||||
processManager.fakeResults = calls;
|
||||
for (String key in calls.keys) {
|
||||
final Process process = await processManager.start(key.split(' '));
|
||||
String output = '';
|
||||
process.stdout.listen((List<int> item) {
|
||||
output += utf8.decode(item);
|
||||
});
|
||||
await process.exitCode;
|
||||
expect(output, equals(calls[key][0].stdout));
|
||||
}
|
||||
processManager.verifyCalls(calls.keys.toList());
|
||||
});
|
||||
|
||||
test('run works', () async {
|
||||
final Map<String, List<ProcessResult>> calls = <String, List<ProcessResult>>{
|
||||
'gsutil acl get gs://flutter_infra/releases/releases.json': <ProcessResult>[
|
||||
new ProcessResult(0, 0, 'output1', '')
|
||||
],
|
||||
'gsutil cat gs://flutter_infra/releases/releases.json': <ProcessResult>[
|
||||
new ProcessResult(0, 0, 'output2', '')
|
||||
],
|
||||
};
|
||||
processManager.fakeResults = calls;
|
||||
for (String key in calls.keys) {
|
||||
final ProcessResult result = await processManager.run(key.split(' '));
|
||||
expect(result.stdout, equals(calls[key][0].stdout));
|
||||
}
|
||||
processManager.verifyCalls(calls.keys.toList());
|
||||
});
|
||||
|
||||
test('runSync works', () async {
|
||||
final Map<String, List<ProcessResult>> calls = <String, List<ProcessResult>>{
|
||||
'gsutil acl get gs://flutter_infra/releases/releases.json': <ProcessResult>[
|
||||
new ProcessResult(0, 0, 'output1', '')
|
||||
],
|
||||
'gsutil cat gs://flutter_infra/releases/releases.json': <ProcessResult>[
|
||||
new ProcessResult(0, 0, 'output2', '')
|
||||
],
|
||||
};
|
||||
processManager.fakeResults = calls;
|
||||
for (String key in calls.keys) {
|
||||
final ProcessResult result = processManager.runSync(key.split(' '));
|
||||
expect(result.stdout, equals(calls[key][0].stdout));
|
||||
}
|
||||
processManager.verifyCalls(calls.keys.toList());
|
||||
});
|
||||
|
||||
test('captures stdin', () async {
|
||||
final Map<String, List<ProcessResult>> calls = <String, List<ProcessResult>>{
|
||||
'gsutil acl get gs://flutter_infra/releases/releases.json': <ProcessResult>[
|
||||
new ProcessResult(0, 0, 'output1', '')
|
||||
],
|
||||
'gsutil cat gs://flutter_infra/releases/releases.json': <ProcessResult>[
|
||||
new ProcessResult(0, 0, 'output2', '')
|
||||
],
|
||||
};
|
||||
processManager.fakeResults = calls;
|
||||
for (String key in calls.keys) {
|
||||
final Process process = await processManager.start(key.split(' '));
|
||||
String output = '';
|
||||
process.stdout.listen((List<int> item) {
|
||||
output += utf8.decode(item);
|
||||
});
|
||||
final String testInput = '${calls[key][0].stdout} input';
|
||||
process.stdin.add(testInput.codeUnits);
|
||||
await process.exitCode;
|
||||
expect(output, equals(calls[key][0].stdout));
|
||||
expect(stdinCaptured.last, equals(testInput));
|
||||
}
|
||||
processManager.verifyCalls(calls.keys.toList());
|
||||
});
|
||||
});
|
||||
}
|
||||
@@ -2,154 +2,247 @@
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
import 'dart:async';
|
||||
import 'dart:io';
|
||||
import 'dart:convert';
|
||||
import 'dart:io' hide Platform;
|
||||
|
||||
import 'package:mockito/mockito.dart';
|
||||
import 'package:test/test.dart';
|
||||
import 'package:path/path.dart' as path;
|
||||
import 'package:process/process.dart';
|
||||
import 'package:platform/platform.dart' show FakePlatform;
|
||||
|
||||
import '../prepare_package.dart';
|
||||
import 'fake_process_manager.dart';
|
||||
|
||||
void main() {
|
||||
group('ArchiveCreator', () {
|
||||
ArchiveCreator preparer;
|
||||
Directory tmpDir;
|
||||
Directory flutterDir;
|
||||
File outputFile;
|
||||
MockProcessManager processManager;
|
||||
List<MockProcess> results = <MockProcess>[];
|
||||
final List<List<String>> args = <List<String>>[];
|
||||
final List<Map<Symbol, dynamic>> namedArgs = <Map<Symbol, dynamic>>[];
|
||||
String flutterExe;
|
||||
final String testRef = 'deadbeefdeadbeefdeadbeefdeadbeefdeadbeef';
|
||||
for (String platformName in <String>['macos', 'linux', 'windows']) {
|
||||
final FakePlatform platform = new FakePlatform(
|
||||
operatingSystem: platformName,
|
||||
environment: <String, String>{},
|
||||
);
|
||||
group('ArchiveCreator for $platformName', () {
|
||||
ArchiveCreator creator;
|
||||
Directory tmpDir;
|
||||
Directory flutterDir;
|
||||
FakeProcessManager processManager;
|
||||
final List<List<String>> args = <List<String>>[];
|
||||
final List<Map<Symbol, dynamic>> namedArgs = <Map<Symbol, dynamic>>[];
|
||||
String flutter;
|
||||
|
||||
void _verifyCommand(List<dynamic> args, String expected) {
|
||||
final List<String> expectedList = expected.split(' ');
|
||||
expect(args[0], orderedEquals(expectedList));
|
||||
setUp(() async {
|
||||
processManager = new FakeProcessManager();
|
||||
args.clear();
|
||||
namedArgs.clear();
|
||||
tmpDir = await Directory.systemTemp.createTemp('flutter_');
|
||||
flutterDir = new Directory(path.join(tmpDir.path, 'flutter'));
|
||||
flutterDir.createSync(recursive: true);
|
||||
creator = new ArchiveCreator(
|
||||
tmpDir,
|
||||
tmpDir,
|
||||
testRef,
|
||||
Branch.dev,
|
||||
processManager: processManager,
|
||||
subprocessOutput: false,
|
||||
platform: platform,
|
||||
);
|
||||
flutter = path.join(creator.flutterRoot.absolute.path, 'bin', 'flutter');
|
||||
});
|
||||
|
||||
tearDown(() async {
|
||||
// On Windows, the directory is locked and not able to be deleted yet. So
|
||||
// we just leave some (very small, because we're not actually building
|
||||
// archives here) trash around to be deleted at the next reboot.
|
||||
if (!platform.isWindows) {
|
||||
await tmpDir.delete(recursive: true);
|
||||
}
|
||||
});
|
||||
|
||||
test('sets PUB_CACHE properly', () async {
|
||||
final String createBase = path.join(tmpDir.absolute.path, 'create_');
|
||||
final Map<String, List<ProcessResult>> calls = <String, List<ProcessResult>>{
|
||||
'git clone -b dev https://chromium.googlesource.com/external/github.com/flutter/flutter':
|
||||
null,
|
||||
'git reset --hard $testRef': null,
|
||||
'git remote remove origin': null,
|
||||
'git remote add origin https://github.com/flutter/flutter.git': null,
|
||||
'git describe --tags --abbrev=0': <ProcessResult>[new ProcessResult(0, 0, 'v1.2.3', '')],
|
||||
};
|
||||
if (platform.isWindows) {
|
||||
calls['7za x ${path.join(tmpDir.path, 'mingit.zip')}'] = null;
|
||||
}
|
||||
calls.addAll(<String, List<ProcessResult>>{
|
||||
'$flutter doctor': null,
|
||||
'$flutter update-packages': null,
|
||||
'$flutter precache': null,
|
||||
'$flutter ide-config': null,
|
||||
'$flutter create --template=app ${createBase}app': null,
|
||||
'$flutter create --template=package ${createBase}package': null,
|
||||
'$flutter create --template=plugin ${createBase}plugin': null,
|
||||
'git clean -f -X **/.packages': null,
|
||||
});
|
||||
final String archiveName = path.join(tmpDir.absolute.path,
|
||||
'flutter_${platformName}_v1.2.3-dev${platform.isWindows ? '.zip' : '.tar.xz'}');
|
||||
if (platform.isWindows) {
|
||||
calls['7za a -tzip -mx=9 $archiveName flutter'] = null;
|
||||
} else {
|
||||
calls['tar cJf $archiveName flutter'] = null;
|
||||
}
|
||||
processManager.fakeResults = calls;
|
||||
await creator.initializeRepo();
|
||||
await creator.createArchive();
|
||||
expect(
|
||||
verify(processManager.start(
|
||||
captureAny,
|
||||
workingDirectory: captureAny,
|
||||
environment: captureAny,
|
||||
)).captured[1]['PUB_CACHE'],
|
||||
endsWith(path.join('flutter', '.pub-cache')),
|
||||
);
|
||||
});
|
||||
|
||||
test('calls the right commands for archive output', () async {
|
||||
final String createBase = path.join(tmpDir.absolute.path, 'create_');
|
||||
final Map<String, List<ProcessResult>> calls = <String, List<ProcessResult>>{
|
||||
'git clone -b dev https://chromium.googlesource.com/external/github.com/flutter/flutter':
|
||||
null,
|
||||
'git reset --hard $testRef': null,
|
||||
'git remote remove origin': null,
|
||||
'git remote add origin https://github.com/flutter/flutter.git': null,
|
||||
'git describe --tags --abbrev=0': <ProcessResult>[new ProcessResult(0, 0, 'v1.2.3', '')],
|
||||
};
|
||||
if (platform.isWindows) {
|
||||
calls['7za x ${path.join(tmpDir.path, 'mingit.zip')}'] = null;
|
||||
}
|
||||
calls.addAll(<String, List<ProcessResult>>{
|
||||
'$flutter doctor': null,
|
||||
'$flutter update-packages': null,
|
||||
'$flutter precache': null,
|
||||
'$flutter ide-config': null,
|
||||
'$flutter create --template=app ${createBase}app': null,
|
||||
// TODO(gspencer): Re-enable this when package works again:
|
||||
// https://github.com/flutter/flutter/issues/14448
|
||||
// '$flutter create --template=package ${createBase}package': null,
|
||||
'$flutter create --template=plugin ${createBase}plugin': null,
|
||||
'git clean -f -X **/.packages': null,
|
||||
});
|
||||
final String archiveName = path.join(tmpDir.absolute.path,
|
||||
'flutter_${platformName}_v1.2.3-dev${platform.isWindows ? '.zip' : '.tar.xz'}');
|
||||
if (platform.isWindows) {
|
||||
calls['7za a -tzip -mx=9 $archiveName flutter'] = null;
|
||||
} else {
|
||||
calls['tar cJf $archiveName flutter'] = null;
|
||||
}
|
||||
processManager.fakeResults = calls;
|
||||
creator = new ArchiveCreator(
|
||||
tmpDir,
|
||||
tmpDir,
|
||||
testRef,
|
||||
Branch.dev,
|
||||
processManager: processManager,
|
||||
subprocessOutput: false,
|
||||
platform: platform,
|
||||
);
|
||||
await creator.initializeRepo();
|
||||
await creator.createArchive();
|
||||
processManager.verifyCalls(calls.keys.toList());
|
||||
});
|
||||
|
||||
test('throws when a command errors out', () async {
|
||||
final Map<String, List<ProcessResult>> calls = <String, List<ProcessResult>>{
|
||||
'git clone -b dev https://chromium.googlesource.com/external/github.com/flutter/flutter':
|
||||
<ProcessResult>[new ProcessResult(0, 0, 'output1', '')],
|
||||
'git reset --hard $testRef': <ProcessResult>[new ProcessResult(0, -1, 'output2', '')],
|
||||
};
|
||||
processManager.fakeResults = calls;
|
||||
expect(expectAsync0(creator.initializeRepo),
|
||||
throwsA(const isInstanceOf<ProcessRunnerException>()));
|
||||
});
|
||||
});
|
||||
|
||||
group('ArchivePublisher for $platformName', () {
|
||||
FakeProcessManager processManager;
|
||||
Directory tempDir;
|
||||
|
||||
setUp(() async {
|
||||
processManager = new FakeProcessManager();
|
||||
tempDir = await Directory.systemTemp.createTemp('flutter_');
|
||||
tempDir.createSync();
|
||||
});
|
||||
|
||||
tearDown(() async {
|
||||
// On Windows, the directory is locked and not able to be deleted yet. So
|
||||
// we just leave some (very small, because we're not actually building
|
||||
// archives here) trash around to be deleted at the next reboot.
|
||||
if (!platform.isWindows) {
|
||||
await tempDir.delete(recursive: true);
|
||||
}
|
||||
});
|
||||
|
||||
test('calls the right processes', () async {
|
||||
final String releasesName = 'releases_$platformName.json';
|
||||
final String archivePath = path.join(tempDir.absolute.path, 'output_archive');
|
||||
final String gsArchivePath = 'gs://flutter_infra/releases/dev/$platformName/output_archive';
|
||||
final String jsonPath = path.join(tempDir.absolute.path, releasesName);
|
||||
final String gsJsonPath = 'gs://flutter_infra/releases/$releasesName';
|
||||
final String releasesJson = '''{
|
||||
"base_url": "https://storage.googleapis.com/flutter_infra/releases",
|
||||
"current_release": {
|
||||
"beta": "6da8ec6bd0c4801b80d666869e4069698561c043",
|
||||
"dev": "f88c60b38c3a5ef92115d24e3da4175b4890daba"
|
||||
},
|
||||
"releases": {
|
||||
"6da8ec6bd0c4801b80d666869e4069698561c043": {
|
||||
"${platformName}_archive": "dev/linux/flutter_${platformName}_0.21.0-beta.tar.xz",
|
||||
"release_date": "2017-12-19T10:30:00,847287019-08:00",
|
||||
"version": "0.21.0-beta"
|
||||
},
|
||||
"f88c60b38c3a5ef92115d24e3da4175b4890daba": {
|
||||
"${platformName}_archive": "dev/linux/flutter_${platformName}_0.22.0-dev.tar.xz",
|
||||
"release_date": "2018-01-19T13:30:09,728487019-08:00",
|
||||
"version": "0.22.0-dev"
|
||||
}
|
||||
}
|
||||
|
||||
Future<Process> _nextResult(Invocation invocation) async {
|
||||
args.add(invocation.positionalArguments);
|
||||
namedArgs.add(invocation.namedArguments);
|
||||
final Process result = results.isEmpty ? new MockProcess('', '', 0) : results.removeAt(0);
|
||||
return new Future<Process>.value(result);
|
||||
}
|
||||
|
||||
void _answerWithResults() {
|
||||
when(
|
||||
processManager.start(
|
||||
typed(captureAny),
|
||||
environment: typed(captureAny, named: 'environment'),
|
||||
workingDirectory: typed(captureAny, named: 'workingDirectory'),
|
||||
),
|
||||
).thenAnswer(_nextResult);
|
||||
}
|
||||
|
||||
setUp(() async {
|
||||
processManager = new MockProcessManager();
|
||||
args.clear();
|
||||
namedArgs.clear();
|
||||
tmpDir = await Directory.systemTemp.createTemp('flutter_');
|
||||
outputFile =
|
||||
new File(path.join(tmpDir.absolute.path, ArchiveCreator.defaultArchiveName('master')));
|
||||
flutterDir = new Directory(path.join(tmpDir.path, 'flutter'));
|
||||
flutterDir.createSync(recursive: true);
|
||||
flutterExe =
|
||||
path.join(flutterDir.path, 'bin', 'flutter');
|
||||
});
|
||||
|
||||
tearDown(() async {
|
||||
// On Windows, the directory is locked and not able to be deleted, because it is a
|
||||
// temporary directory. So we just leave some (very small, because we're not actually
|
||||
// building archives here) trash around to be deleted at the next reboot.
|
||||
if (!Platform.isWindows) {
|
||||
await tmpDir.delete(recursive: true);
|
||||
}
|
||||
});
|
||||
|
||||
test('sets PUB_CACHE properly', () async {
|
||||
preparer =
|
||||
new ArchiveCreator(tmpDir, processManager: processManager, subprocessOutput: false);
|
||||
_answerWithResults();
|
||||
await preparer.createArchive('master', outputFile);
|
||||
expect(
|
||||
verify(processManager.start(
|
||||
captureAny,
|
||||
workingDirectory: captureAny,
|
||||
environment: captureAny,
|
||||
)).captured[1]['PUB_CACHE'],
|
||||
endsWith(path.join('flutter', '.pub-cache')),
|
||||
);
|
||||
});
|
||||
|
||||
test('calls the right commands for archive output', () async {
|
||||
preparer =
|
||||
new ArchiveCreator(tmpDir, processManager: processManager, subprocessOutput: false);
|
||||
_answerWithResults();
|
||||
await preparer.createArchive('master', outputFile);
|
||||
final List<String> commands = <String>[
|
||||
'git clone -b master https://chromium.googlesource.com/external/github.com/flutter/flutter',
|
||||
'git reset --hard master',
|
||||
'git remote remove origin',
|
||||
'git remote add origin https://github.com/flutter/flutter.git',
|
||||
];
|
||||
if (Platform.isWindows) {
|
||||
commands.add('7za x ${path.join(tmpDir.path, 'mingit.zip')}');
|
||||
}
|
||||
commands.addAll(<String>[
|
||||
'$flutterExe doctor',
|
||||
'$flutterExe update-packages',
|
||||
'$flutterExe precache',
|
||||
'$flutterExe ide-config',
|
||||
'$flutterExe create --template=app ${path.join(tmpDir.path, 'create_app')}',
|
||||
'$flutterExe create --template=package ${path.join(tmpDir.path, 'create_package')}',
|
||||
'$flutterExe create --template=plugin ${path.join(tmpDir.path, 'create_plugin')}',
|
||||
'git clean -f -X **/.packages',
|
||||
]);
|
||||
if (Platform.isWindows) {
|
||||
commands.add('7za a -tzip -mx=9 ${outputFile.absolute.path} flutter');
|
||||
} else {
|
||||
commands.add('tar cJf ${outputFile.absolute.path} flutter');
|
||||
}
|
||||
int step = 0;
|
||||
for (String command in commands) {
|
||||
_verifyCommand(args[step++], command);
|
||||
}
|
||||
});
|
||||
|
||||
test('throws when a command errors out', () async {
|
||||
preparer =
|
||||
new ArchiveCreator(tmpDir, processManager: processManager, subprocessOutput: false);
|
||||
|
||||
results = <MockProcess>[
|
||||
new MockProcess('', '', 0),
|
||||
new MockProcess('', "Don't panic.\n", -1)
|
||||
];
|
||||
_answerWithResults();
|
||||
expect(expectAsync2<Null, String, File>(preparer.createArchive)('master', new File('foo')),
|
||||
throwsA(const isInstanceOf<ProcessFailedException>()));
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
class MockProcessManager extends Mock implements ProcessManager {}
|
||||
|
||||
class MockProcess extends Mock implements Process {
|
||||
MockProcess(this._stdout, [this._stderr, this._exitCode]);
|
||||
|
||||
String _stdout;
|
||||
String _stderr;
|
||||
int _exitCode;
|
||||
|
||||
@override
|
||||
Stream<List<int>> get stdout =>
|
||||
new Stream<List<int>>.fromIterable(<List<int>>[_stdout.codeUnits]);
|
||||
|
||||
@override
|
||||
Stream<List<int>> get stderr =>
|
||||
new Stream<List<int>>.fromIterable(<List<int>>[_stderr.codeUnits]);
|
||||
|
||||
@override
|
||||
Future<int> get exitCode => new Future<int>.value(_exitCode);
|
||||
''';
|
||||
final Map<String, List<ProcessResult>> calls = <String, List<ProcessResult>>{
|
||||
'gsutil rm $gsArchivePath': null,
|
||||
'gsutil cp $archivePath $gsArchivePath': null,
|
||||
'gsutil cat $gsJsonPath': <ProcessResult>[new ProcessResult(0, 0, releasesJson, '')],
|
||||
'gsutil rm $gsJsonPath': null,
|
||||
'gsutil cp $jsonPath $gsJsonPath': null,
|
||||
};
|
||||
processManager.fakeResults = calls;
|
||||
final File outputFile = new File(path.join(tempDir.absolute.path, 'output_archive'));
|
||||
assert(tempDir.existsSync());
|
||||
final ArchivePublisher publisher = new ArchivePublisher(
|
||||
tempDir,
|
||||
testRef,
|
||||
Branch.dev,
|
||||
'1.2.3',
|
||||
outputFile,
|
||||
processManager: processManager,
|
||||
subprocessOutput: false,
|
||||
platform: platform,
|
||||
);
|
||||
assert(tempDir.existsSync());
|
||||
await publisher.publishArchive();
|
||||
processManager.verifyCalls(calls.keys.toList());
|
||||
final File releaseFile = new File(jsonPath);
|
||||
expect(releaseFile.existsSync(), isTrue);
|
||||
final String contents = releaseFile.readAsStringSync();
|
||||
// Make sure new data is added.
|
||||
expect(contents, contains('"dev": "$testRef"'));
|
||||
expect(contents, contains('"$testRef": {'));
|
||||
expect(contents, contains('"${platformName}_archive": "dev/$platformName/output_archive"'));
|
||||
// Make sure existing entries are preserved.
|
||||
expect(contents, contains('"6da8ec6bd0c4801b80d666869e4069698561c043": {'));
|
||||
expect(contents, contains('"f88c60b38c3a5ef92115d24e3da4175b4890daba": {'));
|
||||
expect(contents, contains('"beta": "6da8ec6bd0c4801b80d666869e4069698561c043"'));
|
||||
// Make sure it's valid JSON, and in the right format.
|
||||
final Map<String, dynamic> jsonData = json.decode(contents);
|
||||
final JsonEncoder encoder = const JsonEncoder.withIndent(' ');
|
||||
expect(contents, equals(encoder.convert(jsonData)));
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user