Commit e332ab85 authored by Kate Lovett's avatar Kate Lovett

Changed implementation to incorpoarate new init feature for goldctl. Reduces...

Changed implementation to incorpoarate new init feature for goldctl. Reduces redundant work as well.
parent a38311e6
...@@ -129,7 +129,7 @@ void main() { ...@@ -129,7 +129,7 @@ void main() {
await tester.pumpWidget(build(elevation.toDouble())); await tester.pumpWidget(build(elevation.toDouble()));
await expectLater( await expectLater(
find.byType(Container), find.byType(Container),
matchesSkiaGoldFile('shadow.PhysicalModel.disabled.1.png'), matchesSkiaGoldFile('shadow.PhysicalModel.disabled.1.$elevation.png'),
// matchesGoldenFile('shadow.PhysicalModel.disabled.png'), // matchesGoldenFile('shadow.PhysicalModel.disabled.png'),
); );
} }
......
...@@ -69,14 +69,14 @@ class FlutterGoldenFileComparator implements GoldenFileComparator { ...@@ -69,14 +69,14 @@ class FlutterGoldenFileComparator implements GoldenFileComparator {
// Calculate the appropriate basedir for the current test context. // Calculate the appropriate basedir for the current test context.
const FileSystem fs = LocalFileSystem(); const FileSystem fs = LocalFileSystem();
final Directory testDirectory = fs.directory(defaultComparator.basedir); final Directory testDirectory = fs.directory(defaultComparator.basedir);
//print('test: $testDirectory'); print('test: $testDirectory');
final Directory flutterRoot = fs.directory(Platform.environment[_kFlutterRootKey]); final Directory flutterRoot = fs.directory(Platform.environment[_kFlutterRootKey]);
//print('flutter: $flutterRoot'); print('flutter: $flutterRoot');
final Directory goldenRoot = flutterRoot.childDirectory(fs.path.join('bin', 'cache', 'pkg', 'goldens')); final Directory goldenRoot = flutterRoot.childDirectory(fs.path.join('bin', 'cache', 'pkg', 'goldens'));
//print('golden: $goldenRoot'); print('golden: $goldenRoot');
final String testDirectoryRelativePath = fs.path.relative(testDirectory.path, from: flutterRoot.path); final String testDirectoryRelativePath = fs.path.relative(testDirectory.path, from: flutterRoot.path);
//print('testDRP: $testDirectoryRelativePath'); print('testDRP: $testDirectoryRelativePath');
//print('FGFC instantiated with:${goldenRoot.childDirectory(testDirectoryRelativePath).uri}'); print('FGFC instantiated with:${goldenRoot.childDirectory(testDirectoryRelativePath).uri}');
return FlutterGoldenFileComparator(goldenRoot.childDirectory(testDirectoryRelativePath).uri); return FlutterGoldenFileComparator(goldenRoot.childDirectory(testDirectoryRelativePath).uri);
} }
......
...@@ -8,6 +8,7 @@ import 'dart:io' as io; ...@@ -8,6 +8,7 @@ import 'dart:io' as io;
import 'package:file/file.dart'; import 'package:file/file.dart';
import 'package:file/local.dart'; import 'package:file/local.dart';
import 'package:path/path.dart' as path;
import 'package:platform/platform.dart'; import 'package:platform/platform.dart';
import 'package:process/process.dart'; import 'package:process/process.dart';
...@@ -78,55 +79,88 @@ class SkiaGoldClient { ...@@ -78,55 +79,88 @@ class SkiaGoldClient {
/// This ensures that the goldctl tool is authorized and ready for testing. /// This ensures that the goldctl tool is authorized and ready for testing.
Future<bool> auth(Directory workDirectory) async { Future<bool> auth(Directory workDirectory) async {
_workDirectory = workDirectory; _workDirectory = workDirectory;
List<String> authArguments = <String>['auth'];
//TODO(katelovett): Cleanup for final CI implementation //TODO(katelovett): Cleanup for final CI implementation
if(_serviceAccount == null) if(_serviceAccount == null)
return false; return false; // We are not in the proper environment for running these tests.
//throw const NonZeroExitCode(1, 'No Service Account found.');
final File authFile = io.File(path.join(_workDirectory.path, 'temp', 'auth_opt.json'));
authArguments += <String>[ if(!authFile.existsSync()) {
'--service-account', _serviceAccount, final List<String> authArguments = <String>[
'--work-dir', _workDirectory.childDirectory('temp').path, 'auth',
]; '--service-account', _serviceAccount,
'--work-dir', _workDirectory.childDirectory('temp').path,
final io.ProcessResult authResults = io.Process.runSync(_goldctl, authArguments); ];
if (authResults.exitCode != 0) {
final StringBuffer buf = StringBuffer(); final io.ProcessResult authResults = io.Process.runSync(_goldctl, authArguments);
buf if (authResults.exitCode != 0) {
..writeln('Flutter + Skia Gold auth failed.') final StringBuffer buf = StringBuffer();
..writeln('stdout: ${authResults.stdout}') buf
..writeln('stderr: ${authResults.stderr}'); ..writeln('Flutter + Skia Gold auth failed.')
throw NonZeroExitCode(authResults.exitCode, buf.toString()); ..writeln('stdout: ${authResults.stdout}')
..writeln('stderr: ${authResults.stderr}');
throw NonZeroExitCode(authResults.exitCode, buf.toString());
}
} else {
print('The file is already here, skipping auth.');
}
// Run init
final File keysFile = io.File(path.join(_workDirectory.path, 'keys.json'));
if(!keysFile.existsSync()) {
final String commitHash = await _getCommitHash();
final String keys = '${_workDirectory.path}keys.json';
final String failures = '${_workDirectory.path}failures.json';
await io.File(keys).writeAsString(_getKeysJSON());
await io.File(failures).create();
final List<String> imgtestInitArguments = <String>[
'imgtest', 'init',
'--instance', _skiaGoldInstance,
'--work-dir', _workDirectory.childDirectory('temp').path,
'--commit', commitHash,
'--keys-file', keys,
'--failure-file', failures,
'--passfail',
];
if(imgtestInitArguments.contains(null)) {
final StringBuffer buf = StringBuffer();
buf.writeln('Null argument for Skia Gold imgtest init:');
imgtestInitArguments.forEach(buf.writeln);
throw NonZeroExitCode(1, buf.toString());
}
final io.ProcessResult imgtestInitResult = io.Process.runSync(
_goldctl,
imgtestInitArguments
);
if (imgtestInitResult.exitCode != 0) {
final StringBuffer buf = StringBuffer();
buf
..writeln('Flutter + Skia Gold imgtest init failed.')
..writeln('stdout: ${imgtestInitResult.stdout}')
..writeln('stderr: ${imgtestInitResult.stderr}');
throw NonZeroExitCode(imgtestInitResult.exitCode, buf.toString());
}
} else{
print('Already init, skipping.');
} }
return true; return true;
} }
Future<bool> imgtest(String testName, File goldenFile) async { Future<bool> imgtest(String testName, File goldenFile) async {
List<String> imgtestArguments = <String>[
'imgtest',
'add',
];
final String commitHash = await _getCommitHash();
final String keys = '${_workDirectory.path}keys.json';
final String failures = '${_workDirectory.path}failures.json';
await io.File(keys).writeAsString(_getKeysJSON());
await io.File(failures).create();
imgtestArguments += <String>[ final List<String> imgtestArguments = <String>[
'--instance', _skiaGoldInstance, 'imgtest', 'add',
'--work-dir', _workDirectory.childDirectory('temp').path, '--work-dir', _workDirectory.childDirectory('temp').path,
'--commit', commitHash,
'--test-name', testName, '--test-name', testName,
'--png-file', goldenFile.path, '--png-file', goldenFile.path,
'--keys-file', keys,
'--failure-file', failures,
'--passfail',
]; ];
if(imgtestArguments.contains(null)) { if(imgtestArguments.contains(null)) {
final StringBuffer buf = StringBuffer(); final StringBuffer buf = StringBuffer();
buf.writeln('null argument for Skia Gold imgtest:'); buf.writeln('Null argument for Skia Gold imgtest add:');
imgtestArguments.forEach(buf.writeln); imgtestArguments.forEach(buf.writeln);
throw NonZeroExitCode(1, buf.toString()); throw NonZeroExitCode(1, buf.toString());
} }
...@@ -135,20 +169,20 @@ class SkiaGoldClient { ...@@ -135,20 +169,20 @@ class SkiaGoldClient {
if (imgtestResult.exitCode != 0) { if (imgtestResult.exitCode != 0) {
final StringBuffer buf = StringBuffer(); final StringBuffer buf = StringBuffer();
buf buf
..writeln('Flutter + Skia Gold imgtest failed.') ..writeln('Flutter + Skia Gold imgtest add failed.')
..writeln('If this is the first execution of this test, it may need to be triaged.') ..writeln('If this is the first execution of this test, it may need to be triaged.')
..writeln('In this case, re-run the test after triage is completed.\n') ..writeln('In this case, re-run the test after triage is completed.\n')
..writeln('stdout: ${imgtestResult.stdout}') ..writeln('stdout: ${imgtestResult.stdout}')
..writeln('stderr: ${imgtestResult.stderr}'); ..writeln('stderr: ${imgtestResult.stderr}');
throw NonZeroExitCode(imgtestResult.exitCode, buf.toString()); throw NonZeroExitCode(imgtestResult.exitCode, buf.toString());
} }
print('PASS'); // print('PASS');
return true; return true;
} }
Future<String> _getCommitHash() async { Future<String> _getCommitHash() async {
// TODO: Remove after baseline is established and pre-commit works // TODO(katelovett): Remove after pre-commit tests can be ingested
return '96f15c74adebb221eb044d3fc71b2d62da0046c0'; return '0572f158fb10505b840281124d07f8785d4f13f0';
// if (!flutterRoot.existsSync()) { // if (!flutterRoot.existsSync()) {
// return null; // return null;
// } else { // } else {
...@@ -160,6 +194,7 @@ class SkiaGoldClient { ...@@ -160,6 +194,7 @@ class SkiaGoldClient {
} }
String _getKeysJSON() { String _getKeysJSON() {
// TODO(katelovett): Parse out cleaner key information
return convert.json.encode( return convert.json.encode(
<String, dynamic>{ <String, dynamic>{
'Operating System' : io.Platform.operatingSystem, 'Operating System' : io.Platform.operatingSystem,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment