Refactor sample catalog screenshot production (#10676)
This commit is contained in:
parent
e5213b8e0a
commit
ede575a92e
@ -9,6 +9,8 @@ import '../framework/adb.dart';
|
|||||||
import '../framework/framework.dart';
|
import '../framework/framework.dart';
|
||||||
import '../framework/ios.dart';
|
import '../framework/ios.dart';
|
||||||
import '../framework/utils.dart';
|
import '../framework/utils.dart';
|
||||||
|
import 'save_catalog_screenshots.dart' show saveCatalogScreenshots;
|
||||||
|
|
||||||
|
|
||||||
Future<TaskResult> samplePageCatalogGenerator(String authorizationToken) async {
|
Future<TaskResult> samplePageCatalogGenerator(String authorizationToken) async {
|
||||||
final Device device = await devices.workingDevice;
|
final Device device = await devices.workingDevice;
|
||||||
@ -19,7 +21,8 @@ Future<TaskResult> samplePageCatalogGenerator(String authorizationToken) async {
|
|||||||
await inDirectory(catalogDirectory, () async {
|
await inDirectory(catalogDirectory, () async {
|
||||||
await flutter('packages', options: <String>['get']);
|
await flutter('packages', options: <String>['get']);
|
||||||
|
|
||||||
if (deviceOperatingSystem == DeviceOperatingSystem.ios)
|
final bool isIosDevice = deviceOperatingSystem == DeviceOperatingSystem.ios;
|
||||||
|
if (isIosDevice)
|
||||||
await prepareProvisioningCertificates(catalogDirectory.path);
|
await prepareProvisioningCertificates(catalogDirectory.path);
|
||||||
|
|
||||||
await dart(<String>['bin/sample_page.dart']);
|
await dart(<String>['bin/sample_page.dart']);
|
||||||
@ -31,11 +34,12 @@ Future<TaskResult> samplePageCatalogGenerator(String authorizationToken) async {
|
|||||||
deviceId,
|
deviceId,
|
||||||
]);
|
]);
|
||||||
|
|
||||||
await dart(<String>[
|
await saveCatalogScreenshots(
|
||||||
'bin/save_screenshots.dart',
|
directory: dir('${flutterDirectory.path}/examples/catalog/.generated'),
|
||||||
await getCurrentFlutterRepoCommit(),
|
commit: await getCurrentFlutterRepoCommit(),
|
||||||
authorizationToken,
|
token: authorizationToken,
|
||||||
]);
|
prefix: isIosDevice ? 'ios_' : '',
|
||||||
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
return new TaskResult.success(null);
|
return new TaskResult.success(null);
|
||||||
|
@ -1,3 +1,7 @@
|
|||||||
|
// Copyright 2017 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:async';
|
||||||
import 'dart:convert';
|
import 'dart:convert';
|
||||||
import 'dart:io';
|
import 'dart:io';
|
||||||
@ -56,6 +60,7 @@ class Upload {
|
|||||||
|
|
||||||
final HttpClientResponse response = await request.close().timeout(timeLimit);
|
final HttpClientResponse response = await request.close().timeout(timeLimit);
|
||||||
if (response.statusCode == HttpStatus.OK) {
|
if (response.statusCode == HttpStatus.OK) {
|
||||||
|
logMessage('Saved $name');
|
||||||
await response.drain<Null>();
|
await response.drain<Null>();
|
||||||
} else {
|
} else {
|
||||||
// TODO(hansmuller): only retry on 5xx and 429 responses
|
// TODO(hansmuller): only retry on 5xx and 429 responses
|
||||||
@ -96,40 +101,40 @@ Future<Null> saveScreenshots(List<String> fromPaths, List<String> largeNames, Li
|
|||||||
for (int index = 0; index < uploads.length; index += 1)
|
for (int index = 0; index < uploads.length; index += 1)
|
||||||
uploads[index] = new Upload(fromPaths[index], largeNames[index], smallNames[index]);
|
uploads[index] = new Upload(fromPaths[index], largeNames[index], smallNames[index]);
|
||||||
|
|
||||||
final HttpClient client = new HttpClient();
|
|
||||||
while(uploads.any(Upload.isNotComplete)) {
|
while(uploads.any(Upload.isNotComplete)) {
|
||||||
|
final HttpClient client = new HttpClient();
|
||||||
uploads = uploads.where(Upload.isNotComplete).toList();
|
uploads = uploads.where(Upload.isNotComplete).toList();
|
||||||
await Future.wait(uploads.map((Upload upload) => upload.run(client)));
|
await Future.wait(uploads.map((Upload upload) => upload.run(client)));
|
||||||
|
client.close(force: true);
|
||||||
}
|
}
|
||||||
client.close();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// If path is lib/foo.png then screenshotName is foo.
|
// If path is lib/foo.png then screenshotName is foo.
|
||||||
String screenshotName(String path) => basenameWithoutExtension(path);
|
String screenshotName(String path) => basenameWithoutExtension(path);
|
||||||
|
|
||||||
Future<Null> main(List<String> args) async {
|
Future<Null> saveCatalogScreenshots({
|
||||||
if (args.length != 2)
|
Directory directory, // Where the *.png screenshots are.
|
||||||
throw new UploadError('Usage: dart bin/save_screenshots.dart commit authorization');
|
String commit, // The commit hash to be used as a cloud storage "directory".
|
||||||
|
String token, // Cloud storage authorization token.
|
||||||
final Directory outputDirectory = new Directory('.generated');
|
String prefix, // Prefix for all file names.
|
||||||
|
}) async {
|
||||||
final List<String> screenshots = <String>[];
|
final List<String> screenshots = <String>[];
|
||||||
outputDirectory.listSync().forEach((FileSystemEntity entity) {
|
directory.listSync().forEach((FileSystemEntity entity) {
|
||||||
if (entity is File && entity.path.endsWith('.png')) {
|
if (entity is File && entity.path.endsWith('.png')) {
|
||||||
final File file = entity;
|
final File file = entity;
|
||||||
screenshots.add(file.path);
|
screenshots.add(file.path);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
final String commit = args[0];
|
|
||||||
final List<String> largeNames = <String>[]; // Cloud storage names for the full res screenshots.
|
final List<String> largeNames = <String>[]; // Cloud storage names for the full res screenshots.
|
||||||
final List<String> smallNames = <String>[]; // Likewise for the scaled down screenshots.
|
final List<String> smallNames = <String>[]; // Likewise for the scaled down screenshots.
|
||||||
for (String path in screenshots) {
|
for (String path in screenshots) {
|
||||||
final String name = screenshotName(path);
|
final String name = screenshotName(path);
|
||||||
largeNames.add('$commit/$name.png');
|
largeNames.add('$commit/$prefix$name.png');
|
||||||
smallNames.add('$commit/${name}_small.png');
|
smallNames.add('$commit/$prefix${name}_small.png');
|
||||||
}
|
}
|
||||||
|
|
||||||
authorizationToken = args[1];
|
authorizationToken = token;
|
||||||
await saveScreenshots(screenshots, largeNames, smallNames);
|
await saveScreenshots(screenshots, largeNames, smallNames);
|
||||||
}
|
}
|
@ -118,7 +118,7 @@ tasks:
|
|||||||
description: >
|
description: >
|
||||||
Builds sample catalog markdown pages and Android screenshots
|
Builds sample catalog markdown pages and Android screenshots
|
||||||
stage: devicelab
|
stage: devicelab
|
||||||
required_agent_capabilities: ["linux/android"]
|
required_agent_capabilities: ["has-android-device"]
|
||||||
flaky: true
|
flaky: true
|
||||||
|
|
||||||
complex_layout_semantics_perf:
|
complex_layout_semantics_perf:
|
||||||
|
@ -9,6 +9,7 @@ environment:
|
|||||||
|
|
||||||
dependencies:
|
dependencies:
|
||||||
args: ^0.13.4
|
args: ^0.13.4
|
||||||
|
image: ^1.1.27
|
||||||
meta: ^1.0.5
|
meta: ^1.0.5
|
||||||
path: ^1.4.0
|
path: ^1.4.0
|
||||||
process: 2.0.3
|
process: 2.0.3
|
||||||
|
@ -180,7 +180,7 @@ void generate() {
|
|||||||
screenshotDriverTemplate,
|
screenshotDriverTemplate,
|
||||||
<String, String>{
|
<String, String>{
|
||||||
'paths': samples.map((SampleGenerator sample) {
|
'paths': samples.map((SampleGenerator sample) {
|
||||||
return "'${outputFile('\${prefix}' + sample.sourceName + '.png').path}'";
|
return "'${outputFile(sample.sourceName + '.png').path}'";
|
||||||
}).toList().join(',\n'),
|
}).toList().join(',\n'),
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
@ -8,7 +8,6 @@ import 'package:test/test.dart';
|
|||||||
|
|
||||||
void main() {
|
void main() {
|
||||||
group('sample screenshots', () {
|
group('sample screenshots', () {
|
||||||
final String prefix = Platform.isMacOS ? 'ios_' : "";
|
|
||||||
FlutterDriver driver;
|
FlutterDriver driver;
|
||||||
|
|
||||||
setUpAll(() async {
|
setUpAll(() async {
|
||||||
|
@ -3,7 +3,6 @@ description: A collection of Flutter sample apps
|
|||||||
dependencies:
|
dependencies:
|
||||||
flutter:
|
flutter:
|
||||||
sdk: flutter
|
sdk: flutter
|
||||||
image:
|
|
||||||
path: ^1.4.0
|
path: ^1.4.0
|
||||||
|
|
||||||
dev_dependencies:
|
dev_dependencies:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user