2018-11-06 01:08:50 +00:00
|
|
|
#!/usr/bin/env dart
|
|
|
|
// Copyright (c) 2018, the Dart project authors. Please see the AUTHORS file
|
|
|
|
// for details. All rights reserved. Use of this source code is governed by a
|
|
|
|
// BSD-style license that can be found in the LICENSE file.
|
|
|
|
|
|
|
|
/// List tests whose results are different from the previously approved results,
|
|
|
|
/// and ask whether to update the currently approved results, turning the bots
|
|
|
|
/// green.
|
|
|
|
|
|
|
|
import 'dart:async';
|
2019-03-12 14:51:24 +00:00
|
|
|
import 'dart:collection';
|
2018-11-06 01:08:50 +00:00
|
|
|
import 'dart:convert';
|
|
|
|
import 'dart:io';
|
|
|
|
import 'dart:math';
|
|
|
|
|
|
|
|
import 'package:args/args.dart';
|
|
|
|
import 'package:glob/glob.dart';
|
|
|
|
|
|
|
|
import 'bots/results.dart';
|
|
|
|
|
2019-03-22 11:11:00 +00:00
|
|
|
/// Returns whether two decoded JSON objects are identical.
|
|
|
|
bool isIdenticalJson(dynamic a, dynamic b) {
|
|
|
|
if (a is Map<String, dynamic> && b is Map<String, dynamic>) {
|
|
|
|
if (a.length != b.length) return false;
|
|
|
|
for (final key in a.keys) {
|
|
|
|
if (!b.containsKey(key)) return false;
|
|
|
|
if (!isIdenticalJson(a[key], b[key])) return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
} else if (a is List<dynamic> && b is List<dynamic>) {
|
|
|
|
if (a.length != b.length) return false;
|
|
|
|
for (int i = 0; i < a.length; i++) {
|
|
|
|
if (!isIdenticalJson(a[i], b[i])) return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
} else {
|
|
|
|
return a == b;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Returns whether two sets of approvals are identical.
|
|
|
|
bool isIdenticalApprovals(
|
|
|
|
Map<String, Map<String, dynamic>> a, Map<String, Map<String, dynamic>> b) {
|
|
|
|
if (a.length != b.length) return false;
|
|
|
|
for (final key in a.keys) {
|
|
|
|
if (!b.containsKey(key)) return false;
|
|
|
|
if (!isIdenticalJson(a[key], b[key])) return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2018-11-06 01:08:50 +00:00
|
|
|
/// The bot names and named configurations are highly redundant if both are
|
|
|
|
/// listed. This function returns a simplified named configuration that doesn't
|
|
|
|
/// contain any aspects that's part of the bots name. This is used to get a more
|
|
|
|
/// compact and readable output.
|
|
|
|
String simplifyNamedConfiguration(String bot, String namedConfiguration) {
|
|
|
|
final botComponents = new Set<String>.from(bot.split("-"));
|
|
|
|
return namedConfiguration
|
|
|
|
.split("-")
|
|
|
|
.where((component) => !botComponents.contains(component))
|
|
|
|
.join("-");
|
|
|
|
}
|
|
|
|
|
2019-03-22 11:11:00 +00:00
|
|
|
/// Represents a test on a bot with the baseline results (if tryrun), the
|
|
|
|
/// current result, the current approved result, and flakiness data.
|
2018-11-06 01:08:50 +00:00
|
|
|
class Test implements Comparable {
|
|
|
|
final String bot;
|
2019-03-22 11:11:00 +00:00
|
|
|
final Map<String, dynamic> baselineData;
|
2018-11-06 01:08:50 +00:00
|
|
|
final Map<String, dynamic> resultData;
|
|
|
|
final Map<String, dynamic> approvedResultData;
|
|
|
|
final Map<String, dynamic> flakinessData;
|
|
|
|
|
2019-03-22 11:11:00 +00:00
|
|
|
Test(this.bot, this.baselineData, this.resultData, this.approvedResultData,
|
2018-11-06 01:08:50 +00:00
|
|
|
this.flakinessData);
|
|
|
|
|
|
|
|
int compareTo(Object other) {
|
|
|
|
if (other is Test) {
|
|
|
|
if (bot.compareTo(other.bot) < 0) return -1;
|
|
|
|
if (other.bot.compareTo(bot) < 0) return 1;
|
|
|
|
if (configuration.compareTo(other.configuration) < 0) return -1;
|
|
|
|
if (other.configuration.compareTo(configuration) < 0) return 1;
|
|
|
|
if (name.compareTo(other.name) < 0) return -1;
|
|
|
|
if (other.name.compareTo(name) < 0) return 1;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2019-03-22 11:11:00 +00:00
|
|
|
Map<String, dynamic> get _sharedData =>
|
|
|
|
resultData ?? baselineData ?? approvedResultData;
|
|
|
|
String get name => _sharedData["name"];
|
2019-03-25 14:34:21 +00:00
|
|
|
String get configuration => _sharedData["configuration"];
|
2019-03-22 11:11:00 +00:00
|
|
|
String get key => "$configuration:$name";
|
|
|
|
String get expected => _sharedData["expected"];
|
|
|
|
String get result => (resultData ?? const {})["result"];
|
2019-03-22 11:41:53 +00:00
|
|
|
bool get matches => _sharedData["matches"];
|
2019-03-22 11:11:00 +00:00
|
|
|
String get baselineResult => (baselineData ?? const {})["result"];
|
|
|
|
String get approvedResult => (approvedResultData ?? const {})["result"];
|
|
|
|
bool get isDifferent => result != null && result != baselineResult;
|
2019-03-22 12:19:17 +00:00
|
|
|
bool get isApproved => result == null || result == approvedResult;
|
2018-11-06 01:08:50 +00:00
|
|
|
List<String> get flakyModes =>
|
|
|
|
flakinessData != null ? flakinessData["outcomes"].cast<String>() : null;
|
|
|
|
bool get isFlake => flakinessData != null && flakyModes.contains(result);
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Loads the results file as as a map if the file exists, otherwise returns the
|
|
|
|
/// empty map.
|
|
|
|
Future<Map<String, Map<String, dynamic>>> loadResultsMapIfExists(
|
|
|
|
String path) async =>
|
|
|
|
await new File(path).exists()
|
|
|
|
? loadResultsMap(path)
|
|
|
|
: <String, Map<String, dynamic>>{};
|
|
|
|
|
2019-03-12 14:51:24 +00:00
|
|
|
/// Exception for when the results for a builder can't be found.
|
|
|
|
class NoResultsException implements Exception {
|
|
|
|
final String message;
|
|
|
|
final String buildUrl;
|
|
|
|
|
|
|
|
NoResultsException(this.message, this.buildUrl);
|
|
|
|
|
|
|
|
String toString() => message;
|
|
|
|
}
|
|
|
|
|
2018-11-30 17:08:04 +00:00
|
|
|
/// Loads a log from logdog.
|
|
|
|
Future<String> loadLog(String id, String step) async {
|
2019-03-12 14:51:24 +00:00
|
|
|
final buildUrl = "https://ci.chromium.org/b/$id";
|
2018-11-30 17:08:04 +00:00
|
|
|
final logUrl = Uri.parse("https://logs.chromium.org/"
|
|
|
|
"logs/dart/buildbucket/cr-buildbucket.appspot.com/"
|
|
|
|
"$id/+/steps/$step?format=raw");
|
|
|
|
final client = new HttpClient();
|
2019-03-12 14:51:24 +00:00
|
|
|
try {
|
|
|
|
final request =
|
|
|
|
await client.getUrl(logUrl).timeout(const Duration(seconds: 60));
|
|
|
|
final response = await request.close().timeout(const Duration(seconds: 60));
|
|
|
|
if (response.statusCode == HttpStatus.notFound) {
|
|
|
|
await response.drain();
|
|
|
|
throw new NoResultsException(
|
|
|
|
"The log at $logUrl doesn't exist: ${response.statusCode}", buildUrl);
|
|
|
|
}
|
|
|
|
if (response.statusCode != HttpStatus.ok) {
|
|
|
|
await response.drain();
|
|
|
|
throw new Exception("Failed to download $logUrl: ${response.statusCode}");
|
|
|
|
}
|
|
|
|
final contents = (await response
|
2019-06-27 00:21:07 +00:00
|
|
|
.cast<List<int>>()
|
2019-03-12 14:51:24 +00:00
|
|
|
.transform(new Utf8Decoder())
|
|
|
|
.timeout(const Duration(seconds: 60))
|
|
|
|
.toList())
|
|
|
|
.join("");
|
|
|
|
return contents;
|
|
|
|
} finally {
|
|
|
|
client.close();
|
2018-11-30 17:08:04 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-02-25 10:02:28 +00:00
|
|
|
/// TODO(https://github.com/dart-lang/sdk/issues/36015): The step name changed
|
|
|
|
/// incompatibly, allow both temporarily to reduce the user breakage. Remove
|
|
|
|
/// this 2019-03-25.
|
|
|
|
Future<String> todoFallbackLoadLog(
|
|
|
|
String id, String primary, String secondary) async {
|
|
|
|
try {
|
|
|
|
return await loadLog(id, primary);
|
|
|
|
} catch (e) {
|
|
|
|
if (e.toString().startsWith("Exception: The log at ") &&
|
|
|
|
e.toString().endsWith(" doesn't exist")) {
|
|
|
|
return await loadLog(id, secondary);
|
|
|
|
}
|
|
|
|
rethrow;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-11-06 01:08:50 +00:00
|
|
|
/// Loads the results from the bot.
|
2018-11-30 17:08:04 +00:00
|
|
|
Future<List<Test>> loadResultsFromBot(String bot, ArgResults options,
|
2019-03-22 11:11:00 +00:00
|
|
|
String changeId, Map<String, dynamic> changelistBuild) async {
|
2018-11-06 01:08:50 +00:00
|
|
|
if (options["verbose"]) {
|
|
|
|
print("Loading $bot...");
|
|
|
|
}
|
|
|
|
// gsutil cp -r requires a destination directory, use a temporary one.
|
|
|
|
final tmpdir = await Directory.systemTemp.createTemp("approve_results.");
|
|
|
|
try {
|
|
|
|
// The 'latest' file contains the name of the latest build that we
|
2018-11-30 17:08:04 +00:00
|
|
|
// should download. When preapproving a changelist, we instead find out
|
|
|
|
// which build the commit queue was rebased on.
|
2019-02-25 10:02:28 +00:00
|
|
|
/// TODO(https://github.com/dart-lang/sdk/issues/36015): The step name
|
|
|
|
/// changed incompatibly, allow both temporarily to reduce the user
|
|
|
|
/// breakage. Remove this 2019-03-25.
|
2019-03-22 11:11:00 +00:00
|
|
|
final build = (changeId != null
|
2019-02-25 10:02:28 +00:00
|
|
|
? await todoFallbackLoadLog(
|
|
|
|
changelistBuild["id"],
|
2019-02-25 09:10:29 +00:00
|
|
|
"download_previous_results/0/steps/gsutil_find_latest_build/0/logs/"
|
2019-06-26 12:56:57 +00:00
|
|
|
"raw_io.output_text_latest_/0",
|
2019-02-25 10:02:28 +00:00
|
|
|
"gsutil_find_latest_build/0/logs/raw_io.output_text_latest_/0")
|
2018-11-30 17:08:04 +00:00
|
|
|
: await readFile(bot, "latest"))
|
|
|
|
.trim();
|
2018-11-06 01:08:50 +00:00
|
|
|
|
|
|
|
// Asynchronously download the latest build and the current approved
|
2018-11-30 17:08:04 +00:00
|
|
|
// results. Download try results from trybot try runs if preapproving.
|
|
|
|
final tryResults = <String, Map<String, dynamic>>{};
|
2018-11-06 01:08:50 +00:00
|
|
|
await Future.wait([
|
|
|
|
cpRecursiveGsutil(buildCloudPath(bot, build), tmpdir.path),
|
2018-11-08 18:53:19 +00:00
|
|
|
cpRecursiveGsutil(
|
|
|
|
"$approvedResultsStoragePath/$bot/approved_results.json",
|
|
|
|
"${tmpdir.path}/approved_results.json"),
|
2018-11-30 17:08:04 +00:00
|
|
|
new Future(() async {
|
2019-03-22 11:11:00 +00:00
|
|
|
if (changeId != null) {
|
2018-11-30 17:08:04 +00:00
|
|
|
tryResults.addAll(parseResultsMap(await loadLog(
|
|
|
|
changelistBuild["id"], "test_results/0/logs/results.json/0")));
|
|
|
|
}
|
|
|
|
}),
|
2018-11-06 01:08:50 +00:00
|
|
|
]);
|
|
|
|
|
|
|
|
// Check the build was properly downloaded.
|
|
|
|
final buildPath = "${tmpdir.path}/$build";
|
|
|
|
final buildDirectory = new Directory(buildPath);
|
|
|
|
if (!await buildDirectory.exists()) {
|
|
|
|
print("$bot: Build directory didn't exist");
|
|
|
|
return <Test>[];
|
|
|
|
}
|
|
|
|
|
|
|
|
// Load the run.json to find the named configuration.
|
|
|
|
final resultsFile = new File("$buildPath/results.json");
|
|
|
|
if (!await resultsFile.exists()) {
|
|
|
|
print("$bot: No results.json exists");
|
|
|
|
return <Test>[];
|
|
|
|
}
|
|
|
|
|
|
|
|
// Load the current results, the approved resutls, and the flakiness
|
|
|
|
// information.
|
|
|
|
final results = await loadResultsMapIfExists("$buildPath/results.json");
|
|
|
|
final flaky = await loadResultsMapIfExists("$buildPath/flaky.json");
|
|
|
|
final approvedResults =
|
|
|
|
await loadResultsMapIfExists("${tmpdir.path}/approved_results.json");
|
|
|
|
|
2019-03-25 15:01:35 +00:00
|
|
|
// TODO: Remove 2019-04-08: Discard any invalid pre-approvals made with a
|
|
|
|
// version of approve_results between 065910f0 and a13ac1b4. Pre-approving
|
|
|
|
// a new test could add pre-approvals with null configuration and null name.
|
|
|
|
approvedResults.remove("null:null");
|
|
|
|
|
2018-11-06 01:08:50 +00:00
|
|
|
// Construct an object for every test containing its current result,
|
|
|
|
// what the last approved result was, and whether it's flaky.
|
|
|
|
final tests = <Test>[];
|
2019-03-22 11:11:00 +00:00
|
|
|
final testResults = changeId != null ? tryResults : results;
|
|
|
|
for (final key in testResults.keys) {
|
|
|
|
final baselineResult = changeId != null ? results[key] : null;
|
|
|
|
final testResult = testResults[key];
|
2018-11-07 00:05:57 +00:00
|
|
|
final approvedResult = approvedResults[key];
|
|
|
|
final flakiness = flaky[key];
|
2019-03-22 11:11:00 +00:00
|
|
|
final test =
|
|
|
|
new Test(bot, baselineResult, testResult, approvedResult, flakiness);
|
2018-11-06 01:08:50 +00:00
|
|
|
tests.add(test);
|
|
|
|
}
|
2019-03-22 11:11:00 +00:00
|
|
|
// Add in approvals whose test was no longer in the results.
|
|
|
|
for (final key in approvedResults.keys) {
|
|
|
|
if (testResults.containsKey(key)) continue;
|
|
|
|
final baselineResult = changeId != null ? results[key] : null;
|
|
|
|
final approvedResult = approvedResults[key];
|
2018-11-30 17:08:04 +00:00
|
|
|
final flakiness = flaky[key];
|
2019-03-22 11:11:00 +00:00
|
|
|
final test =
|
|
|
|
new Test(bot, baselineResult, null, approvedResult, flakiness);
|
2018-11-30 17:08:04 +00:00
|
|
|
tests.add(test);
|
|
|
|
}
|
2018-11-06 01:08:50 +00:00
|
|
|
if (options["verbose"]) {
|
|
|
|
print("Loaded $bot (${tests.length} tests).");
|
|
|
|
}
|
|
|
|
return tests;
|
|
|
|
} finally {
|
|
|
|
// Always clean up the temporary directory when we don't need it.
|
|
|
|
await tmpdir.delete(recursive: true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-03-22 11:11:00 +00:00
|
|
|
Future<Map<String, dynamic>> loadJsonPrefixedAPI(String url) async {
|
|
|
|
final client = new HttpClient();
|
|
|
|
try {
|
|
|
|
final request = await client
|
|
|
|
.getUrl(Uri.parse(url))
|
|
|
|
.timeout(const Duration(seconds: 30));
|
|
|
|
final response = await request.close().timeout(const Duration(seconds: 30));
|
|
|
|
if (response.statusCode != HttpStatus.ok) {
|
|
|
|
throw new Exception("Failed to request $url: ${response.statusCode}");
|
|
|
|
}
|
|
|
|
final text = await response
|
2019-06-27 00:21:07 +00:00
|
|
|
.cast<List<int>>()
|
2019-03-22 11:11:00 +00:00
|
|
|
.transform(utf8.decoder)
|
|
|
|
.join()
|
|
|
|
.timeout(const Duration(seconds: 30));
|
|
|
|
return jsonDecode(text.substring(5 /* ")]}'\n" */));
|
|
|
|
} finally {
|
|
|
|
client.close();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Future<Map<String, dynamic>> loadChangelistDetails(
|
|
|
|
String gerritHost, String changeId) async {
|
|
|
|
// ?O=516714 requests the revisions field.
|
|
|
|
final url = "https://$gerritHost/changes/$changeId/detail?O=516714";
|
|
|
|
return await loadJsonPrefixedAPI(url);
|
|
|
|
}
|
|
|
|
|
2018-11-06 01:08:50 +00:00
|
|
|
main(List<String> args) async {
|
|
|
|
final parser = new ArgParser();
|
2019-01-21 12:02:26 +00:00
|
|
|
parser.addFlag("automated-approver",
|
|
|
|
help: "Record the approval as done by an automated process.",
|
|
|
|
negatable: false);
|
2018-11-06 01:08:50 +00:00
|
|
|
parser.addMultiOption("bot",
|
|
|
|
abbr: "b",
|
|
|
|
help: "Select the bots matching the glob pattern [option is repeatable]",
|
|
|
|
splitCommas: false);
|
|
|
|
parser.addFlag("help", help: "Show the program usage.", negatable: false);
|
2019-01-21 12:02:26 +00:00
|
|
|
parser.addFlag("failures-only",
|
|
|
|
help: "Approve failures only.", negatable: false);
|
2018-11-06 01:08:50 +00:00
|
|
|
parser.addFlag("list",
|
|
|
|
abbr: "l", help: "List the available bots.", negatable: false);
|
|
|
|
parser.addFlag("no",
|
|
|
|
abbr: "n",
|
|
|
|
help: "Show changed results but don't approve.",
|
|
|
|
negatable: false);
|
2018-11-30 17:08:04 +00:00
|
|
|
parser.addOption("preapprove",
|
|
|
|
abbr: "p", help: "Preapprove the new failures in a gerrit CL.");
|
2019-01-21 12:02:26 +00:00
|
|
|
parser.addFlag("successes-only",
|
|
|
|
help: "Approve successes only.", negatable: false);
|
2018-11-06 01:08:50 +00:00
|
|
|
parser.addFlag("verbose",
|
|
|
|
abbr: "v", help: "Describe asynchronous operations.", negatable: false);
|
|
|
|
parser.addFlag("yes",
|
|
|
|
abbr: "y", help: "Approve the results.", negatable: false);
|
2019-01-22 11:09:32 +00:00
|
|
|
parser.addOption("table",
|
|
|
|
abbr: "T",
|
|
|
|
help: "Select table format.",
|
|
|
|
allowed: ["markdown", "indent"],
|
|
|
|
defaultsTo: "markdown");
|
2018-11-06 01:08:50 +00:00
|
|
|
|
|
|
|
final options = parser.parse(args);
|
2018-11-30 17:08:04 +00:00
|
|
|
if ((options["preapprove"] == null &&
|
|
|
|
options["bot"].isEmpty &&
|
|
|
|
!options["list"]) ||
|
|
|
|
options["help"]) {
|
2018-11-06 01:08:50 +00:00
|
|
|
print("""
|
|
|
|
Usage: approve_results.dart [OPTION]...
|
|
|
|
List tests whose results are different from the previously approved results, and
|
|
|
|
ask whether to update the currently approved results, turning the bots green.
|
|
|
|
|
2019-03-06 15:06:40 +00:00
|
|
|
See the documentation at https://goto.google.com/dart-status-file-free-workflow
|
|
|
|
|
2018-11-06 01:08:50 +00:00
|
|
|
The options are as follows:
|
|
|
|
|
|
|
|
${parser.usage}""");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (options["no"] && options["yes"]) {
|
|
|
|
stderr.writeln("The --no and --yes options are mutually incompatible");
|
|
|
|
exitCode = 1;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2019-03-08 09:39:12 +00:00
|
|
|
if (options.rest.isNotEmpty) {
|
|
|
|
stderr.writeln("Unexpected extra argument: ${options.rest.first}");
|
|
|
|
exitCode = 1;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2019-01-23 12:52:41 +00:00
|
|
|
// Locate gsutil.py.
|
|
|
|
gsutilPy =
|
|
|
|
Platform.script.resolve("../third_party/gsutil/gsutil.py").toFilePath();
|
|
|
|
|
2018-11-06 01:08:50 +00:00
|
|
|
// Load the list of bots according to the test matrix.
|
2018-11-12 18:47:10 +00:00
|
|
|
final testMatrixPath =
|
|
|
|
Platform.script.resolve("bots/test_matrix.json").toFilePath();
|
2018-11-06 01:08:50 +00:00
|
|
|
final testMatrix = jsonDecode(await new File(testMatrixPath).readAsString());
|
|
|
|
final builderConfigurations = testMatrix["builder_configurations"];
|
|
|
|
final testMatrixBots = <String>[];
|
|
|
|
for (final builderConfiguration in builderConfigurations) {
|
|
|
|
final steps = builderConfiguration["steps"];
|
2019-06-26 12:56:57 +00:00
|
|
|
// Only consider bots that use tools/test.py or custom test runners.
|
2018-11-06 01:08:50 +00:00
|
|
|
if (!steps.any((step) =>
|
2019-06-26 12:56:57 +00:00
|
|
|
step["script"] == null ||
|
|
|
|
step["script"] == "tools/test.py" ||
|
|
|
|
step["testRunner"] == true)) {
|
2018-11-06 01:08:50 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
final builders = builderConfiguration["builders"].cast<String>();
|
|
|
|
testMatrixBots.addAll(builders);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Load the list of bots that have data in cloud storage.
|
|
|
|
if (options["verbose"]) {
|
|
|
|
print("Loading list of bots...");
|
|
|
|
}
|
|
|
|
final botsWithData = (await listBots())
|
|
|
|
.where((bot) => !bot.endsWith("-try"))
|
|
|
|
.where((bot) => !bot.endsWith("-dev"))
|
|
|
|
.where((bot) => !bot.endsWith("-stable"));
|
|
|
|
if (options["verbose"]) {
|
|
|
|
print("Loaded list of bots.");
|
|
|
|
}
|
|
|
|
|
|
|
|
// The currently active bots are the bots both mentioned in the test matrix
|
|
|
|
// and that have results in cloud storage.
|
|
|
|
final allBots = new Set<String>.from(testMatrixBots)
|
|
|
|
.intersection(new Set<String>.from(botsWithData))
|
|
|
|
.toList()
|
|
|
|
..sort();
|
|
|
|
|
|
|
|
// List the currently active bots if requested.
|
|
|
|
if (options["list"]) {
|
|
|
|
for (final bot in allBots) {
|
|
|
|
print(bot);
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-11-30 17:08:04 +00:00
|
|
|
// Determine which builders have run for the changelist.
|
|
|
|
final changelistBuilds = <String, Map<String, dynamic>>{};
|
2019-03-22 11:11:00 +00:00
|
|
|
final isPreapproval = options["preapprove"] != null;
|
|
|
|
String changeId;
|
|
|
|
if (isPreapproval) {
|
2018-11-30 17:08:04 +00:00
|
|
|
if (options["verbose"]) {
|
2019-03-22 11:11:00 +00:00
|
|
|
print("Loading changelist details...");
|
2018-11-30 17:08:04 +00:00
|
|
|
}
|
|
|
|
final gerritHost = "dart-review.googlesource.com";
|
|
|
|
final gerritProject = "sdk";
|
|
|
|
final prefix = "https://$gerritHost/c/$gerritProject/+/";
|
|
|
|
final gerrit = options["preapprove"];
|
|
|
|
if (!gerrit.startsWith(prefix)) {
|
|
|
|
stderr.writeln("error: $gerrit doesn't start with $prefix");
|
|
|
|
exitCode = 1;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
final components = gerrit.substring(prefix.length).split("/");
|
2019-03-22 11:11:00 +00:00
|
|
|
if (!((components.length == 1 && int.tryParse(components[0]) != null) ||
|
|
|
|
(components.length == 2 &&
|
|
|
|
int.tryParse(components[0]) != null &&
|
|
|
|
int.tryParse(components[1]) != null))) {
|
2018-11-30 17:08:04 +00:00
|
|
|
stderr.writeln("error: $gerrit must be in the form of "
|
2019-03-22 11:11:00 +00:00
|
|
|
"$prefix<changelist> or $prefix<changelist>/<patchset>");
|
2018-11-30 17:08:04 +00:00
|
|
|
exitCode = 1;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
final changelist = int.parse(components[0]);
|
2019-03-22 11:11:00 +00:00
|
|
|
final details =
|
|
|
|
await loadChangelistDetails(gerritHost, changelist.toString());
|
|
|
|
changeId = details["change_id"];
|
|
|
|
final patchset = 2 <= components.length
|
|
|
|
? int.parse(components[1])
|
|
|
|
: details["revisions"][details["current_revision"]]["_number"];
|
|
|
|
if (2 <= components.length) {
|
|
|
|
print("Using Change-Id $changeId patchset $patchset");
|
|
|
|
} else {
|
|
|
|
print("Using Change-Id $changeId with the latest patchset $patchset");
|
|
|
|
}
|
|
|
|
if (options["verbose"]) {
|
|
|
|
print("Loading list of try runs...");
|
|
|
|
}
|
2018-11-30 17:08:04 +00:00
|
|
|
final buildset = "buildset:patch/gerrit/$gerritHost/$changelist/$patchset";
|
2019-07-29 11:54:20 +00:00
|
|
|
|
2019-07-29 12:32:40 +00:00
|
|
|
Future<Map<String, dynamic>> searchBuilds(String cursor) async {
|
2019-07-29 11:54:20 +00:00
|
|
|
final url = Uri.parse(
|
|
|
|
"https://cr-buildbucket.appspot.com/_ah/api/buildbucket/v1/search"
|
|
|
|
"?bucket=luci.dart.try"
|
|
|
|
"&tag=${Uri.encodeComponent(buildset)}"
|
|
|
|
"&fields=builds(id%2Ctags%2Cstatus%2Cstarted_ts),next_cursor"
|
|
|
|
"&start_cursor=$cursor");
|
|
|
|
final client = new HttpClient();
|
|
|
|
final request =
|
|
|
|
await client.getUrl(url).timeout(const Duration(seconds: 30));
|
|
|
|
final response =
|
|
|
|
await request.close().timeout(const Duration(seconds: 30));
|
|
|
|
if (response.statusCode != HttpStatus.ok) {
|
|
|
|
throw new Exception("Failed to request try runs for $gerrit");
|
|
|
|
}
|
|
|
|
final Map<String, dynamic> object = await response
|
|
|
|
.cast<List<int>>()
|
|
|
|
.transform(new Utf8Decoder())
|
|
|
|
.transform(new JsonDecoder())
|
|
|
|
.first
|
|
|
|
.timeout(const Duration(seconds: 30));
|
|
|
|
client.close();
|
|
|
|
return object;
|
2018-11-30 17:08:04 +00:00
|
|
|
}
|
|
|
|
|
2019-07-29 11:54:20 +00:00
|
|
|
var cursor = "";
|
|
|
|
final builds = [];
|
|
|
|
do {
|
|
|
|
final object = await searchBuilds(cursor);
|
|
|
|
if (cursor.isEmpty && object["builds"] == null) {
|
|
|
|
stderr.writeln(
|
|
|
|
"error: $prefix$changelist has no try runs for patchset $patchset");
|
|
|
|
exitCode = 1;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
builds.addAll(object["builds"]);
|
|
|
|
cursor = object["next_cursor"];
|
|
|
|
} while (cursor != null);
|
|
|
|
|
2018-11-30 17:08:04 +00:00
|
|
|
// Prefer the newest completed build.
|
|
|
|
Map<String, dynamic> preferredBuild(
|
|
|
|
Map<String, dynamic> a, Map<String, dynamic> b) {
|
|
|
|
if (a != null && b == null) return a;
|
|
|
|
if (a == null && b != null) return b;
|
|
|
|
if (a != null && b != null) {
|
|
|
|
if (a["status"] == "COMPLETED" && b["status"] != "COMPLETED") return a;
|
|
|
|
if (a["status"] != "COMPLETED" && b["status"] == "COMPLETED") return b;
|
|
|
|
if (a["started_ts"] == null && b["started_ts"] != null) return a;
|
|
|
|
if (a["started_ts"] != null && b["started_ts"] == null) return b;
|
|
|
|
if (a["started_ts"] != null && b["started_ts"] != null) {
|
|
|
|
if (int.parse(a["started_ts"]) > int.parse(b["started_ts"])) return a;
|
|
|
|
if (int.parse(a["started_ts"]) < int.parse(b["started_ts"])) return b;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return b;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (final build in builds) {
|
|
|
|
final tags = (build["tags"] as List<dynamic>).cast<String>();
|
|
|
|
final builder = tags
|
|
|
|
.firstWhere((tag) => tag.startsWith("builder:"))
|
|
|
|
.substring("builder:".length);
|
|
|
|
final ciBuilder = builder.replaceFirst(new RegExp("-try\$"), "");
|
|
|
|
if (!allBots.contains(ciBuilder)) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
changelistBuilds[ciBuilder] =
|
|
|
|
preferredBuild(changelistBuilds[ciBuilder], build);
|
|
|
|
}
|
|
|
|
if (options["verbose"]) {
|
|
|
|
print("Loaded list of try runs.");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
final changelistBuilders = new Set<String>.from(changelistBuilds.keys);
|
|
|
|
|
2018-11-06 01:08:50 +00:00
|
|
|
// Select all the bots matching the glob patterns,
|
2018-11-30 17:08:04 +00:00
|
|
|
final finalBotList =
|
|
|
|
options["preapprove"] != null ? changelistBuilders : allBots;
|
|
|
|
final botPatterns = options["preapprove"] != null && options["bot"].isEmpty
|
|
|
|
? ["*"]
|
|
|
|
: options["bot"];
|
2018-11-06 01:08:50 +00:00
|
|
|
final bots = new Set<String>();
|
2018-11-30 17:08:04 +00:00
|
|
|
for (final botPattern in botPatterns) {
|
2018-11-06 01:08:50 +00:00
|
|
|
final glob = new Glob(botPattern);
|
|
|
|
bool any = false;
|
2018-11-30 17:08:04 +00:00
|
|
|
for (final bot in finalBotList) {
|
2018-11-06 01:08:50 +00:00
|
|
|
if (glob.matches(bot)) {
|
|
|
|
bots.add(bot);
|
|
|
|
any = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!any) {
|
|
|
|
stderr.writeln("error: No bots matched pattern: $botPattern");
|
|
|
|
stderr.writeln("Try --list to get the list of bots, or --help for help");
|
|
|
|
exitCode = 1;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
for (final bot in bots) {
|
|
|
|
print("Selected bot: $bot");
|
|
|
|
}
|
|
|
|
|
2018-11-30 17:08:04 +00:00
|
|
|
// Error out if any of the requested try runs are incomplete.
|
|
|
|
bool anyIncomplete = false;
|
|
|
|
for (final bot in bots) {
|
|
|
|
if (options["preapprove"] != null &&
|
|
|
|
changelistBuilds[bot]["status"] != "COMPLETED") {
|
2019-01-21 11:58:43 +00:00
|
|
|
stderr.writeln("error: The try run for $bot isn't complete yet: " +
|
2018-11-30 17:08:04 +00:00
|
|
|
changelistBuilds[bot]["status"]);
|
|
|
|
anyIncomplete = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (anyIncomplete) {
|
|
|
|
exitCode = 1;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-11-06 01:08:50 +00:00
|
|
|
// Load all the latest results for the selected bots, as well as flakiness
|
|
|
|
// data, and the set of currently approved results. Each bot's latest build
|
|
|
|
// is downloaded in parallel to make this phase faster.
|
2019-03-12 14:51:24 +00:00
|
|
|
final testListFutures = <Future<List<Test>>>[];
|
|
|
|
final noResultsBuilds = new SplayTreeMap<String, String>();
|
2018-11-06 01:08:50 +00:00
|
|
|
for (final String bot in bots) {
|
2019-03-12 14:51:24 +00:00
|
|
|
testListFutures.add(new Future(() async {
|
|
|
|
try {
|
2019-03-22 11:11:00 +00:00
|
|
|
return await loadResultsFromBot(
|
|
|
|
bot, options, changeId, changelistBuilds[bot]);
|
2019-03-12 14:51:24 +00:00
|
|
|
} on NoResultsException catch (e) {
|
|
|
|
print(
|
|
|
|
"Error: Failed to find results for $bot build <${e.buildUrl}>: $e");
|
|
|
|
noResultsBuilds[bot] = e.buildUrl;
|
|
|
|
return <Test>[];
|
|
|
|
}
|
|
|
|
}));
|
2018-11-06 01:08:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Collect all the tests from the synchronous downloads.
|
|
|
|
final tests = <Test>[];
|
|
|
|
for (final testList in await Future.wait(testListFutures)) {
|
|
|
|
tests.addAll(testList);
|
|
|
|
}
|
|
|
|
tests.sort();
|
|
|
|
print("");
|
|
|
|
|
|
|
|
// Compute statistics and the set of interesting tests.
|
2019-03-22 11:11:00 +00:00
|
|
|
final flakyTestsCount =
|
|
|
|
tests.where((test) => test.resultData != null && test.isFlake).length;
|
|
|
|
final failingTestsCount = tests
|
|
|
|
.where(
|
|
|
|
(test) => test.resultData != null && !test.isFlake && !test.matches)
|
|
|
|
.length;
|
|
|
|
final differentTests = tests
|
|
|
|
.where((test) =>
|
|
|
|
(isPreapproval ? test.isDifferent : !test.isApproved) &&
|
|
|
|
!test.isFlake)
|
|
|
|
.toList();
|
|
|
|
final selectedTests = differentTests
|
|
|
|
.where((test) => !(test.matches
|
|
|
|
? options["failures-only"]
|
|
|
|
: options["successes-only"]))
|
|
|
|
.toList();
|
|
|
|
final fixedTests = selectedTests.where((test) => test.matches).toList();
|
|
|
|
final brokenTests = selectedTests.where((test) => !test.matches).toList();
|
2018-11-06 01:08:50 +00:00
|
|
|
|
|
|
|
// Find out which bots have multiple configurations.
|
|
|
|
final configurationsForBots = <String, Set<String>>{};
|
|
|
|
for (final test in tests) {
|
|
|
|
var configurationSet = configurationsForBots[test.bot];
|
|
|
|
if (configurationSet == null) {
|
|
|
|
configurationsForBots[test.bot] = configurationSet = new Set<String>();
|
|
|
|
}
|
|
|
|
configurationSet.add(test.configuration);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Compute a nice displayed name for the bot and configuration. If the bot
|
|
|
|
// only has a single configuration, then only mention the bot. Otherwise,
|
|
|
|
// remove the redundant parts from configuration and present it compactly.
|
|
|
|
// This is needed to avoid the tables becoming way too large.
|
|
|
|
String getBotDisplayName(String bot, String configuration) {
|
|
|
|
if (configurationsForBots[bot].length == 1) {
|
|
|
|
return bot;
|
|
|
|
} else {
|
|
|
|
final simpleConfig = simplifyNamedConfiguration(bot, configuration);
|
|
|
|
return "$bot/$simpleConfig";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Compute the width of the fields in the below tables.
|
|
|
|
final unapprovedBots = new Set<String>();
|
|
|
|
int longestBot = "BOT/CONFIG".length;
|
|
|
|
int longestTest = "TEST".length;
|
|
|
|
int longestResult = "RESULT".length;
|
2019-01-22 11:09:32 +00:00
|
|
|
int longestExpected = "EXPECTED".length;
|
2019-03-22 11:11:00 +00:00
|
|
|
for (final test in selectedTests) {
|
2018-11-06 01:08:50 +00:00
|
|
|
unapprovedBots.add(test.bot);
|
|
|
|
final botDisplayName = getBotDisplayName(test.bot, test.configuration);
|
|
|
|
longestBot = max(longestBot, botDisplayName.length);
|
2019-01-22 11:09:32 +00:00
|
|
|
longestTest = max(longestTest, test.name.length);
|
|
|
|
longestResult = max(longestResult, test.result.length);
|
|
|
|
longestExpected = max(longestExpected, test.expected.length);
|
2018-11-06 01:08:50 +00:00
|
|
|
}
|
|
|
|
longestTest = min(longestTest, 120); // Some tests names are extremely long.
|
|
|
|
|
|
|
|
// Table of lists that now succeed.
|
|
|
|
if (fixedTests.isNotEmpty) {
|
|
|
|
print("The following tests are now succeeding:\n");
|
2019-01-22 11:09:32 +00:00
|
|
|
if (options["table"] == "markdown") {
|
|
|
|
print("| ${'BOT/CONFIG'.padRight(longestBot)} "
|
|
|
|
"| ${'TEST'.padRight(longestTest)} |");
|
|
|
|
print("| ${'-' * longestBot} "
|
|
|
|
"| ${'-' * longestTest} |");
|
|
|
|
} else if (options["table"] == "indent") {
|
|
|
|
print("${'BOT/CONFIG'.padRight(longestBot)} "
|
|
|
|
"TEST");
|
|
|
|
}
|
2018-11-06 01:08:50 +00:00
|
|
|
for (final test in fixedTests) {
|
|
|
|
final botDisplayName = getBotDisplayName(test.bot, test.configuration);
|
2019-01-22 11:09:32 +00:00
|
|
|
if (options["table"] == "markdown") {
|
|
|
|
print("| ${botDisplayName.padRight(longestBot)} "
|
|
|
|
"| ${test.name.padRight(longestTest)} |");
|
|
|
|
} else if (options["table"] == "indent") {
|
|
|
|
print("${botDisplayName.padRight(longestBot)} "
|
|
|
|
"${test.name}");
|
|
|
|
}
|
2018-11-06 01:08:50 +00:00
|
|
|
}
|
|
|
|
print("");
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Table of lists that now fail.
|
|
|
|
if (brokenTests.isNotEmpty) {
|
|
|
|
print("The following tests are now failing:\n");
|
2019-01-22 11:09:32 +00:00
|
|
|
if (options["table"] == "markdown") {
|
|
|
|
print("| ${'BOT'.padRight(longestBot)} "
|
|
|
|
"| ${'TEST'.padRight(longestTest)} "
|
|
|
|
"| ${'RESULT'.padRight(longestResult)} "
|
|
|
|
"| ${'EXPECTED'.padRight(longestExpected)} | ");
|
|
|
|
print("| ${'-' * longestBot} "
|
|
|
|
"| ${'-' * longestTest} "
|
|
|
|
"| ${'-' * longestResult} "
|
|
|
|
"| ${'-' * longestExpected} | ");
|
|
|
|
} else if (options["table"] == "indent") {
|
|
|
|
print("${'BOT'.padRight(longestBot)} "
|
|
|
|
"${'TEST'.padRight(longestTest)} "
|
|
|
|
"${'RESULT'.padRight(longestResult)} "
|
|
|
|
"EXPECTED");
|
|
|
|
}
|
2018-11-06 01:08:50 +00:00
|
|
|
for (final test in brokenTests) {
|
|
|
|
final botDisplayName = getBotDisplayName(test.bot, test.configuration);
|
2019-01-22 11:09:32 +00:00
|
|
|
if (options["table"] == "markdown") {
|
|
|
|
print("| ${botDisplayName.padRight(longestBot)} "
|
|
|
|
"| ${test.name.padRight(longestTest)} "
|
|
|
|
"| ${test.result.padRight(longestResult)} "
|
|
|
|
"| ${test.expected.padRight(longestExpected)} |");
|
|
|
|
} else if (options["table"] == "indent") {
|
|
|
|
print("${botDisplayName.padRight(longestBot)} "
|
|
|
|
"${test.name.padRight(longestTest)} "
|
|
|
|
"${test.result.padRight(longestResult)} "
|
|
|
|
"${test.expected}");
|
|
|
|
}
|
2018-11-06 01:08:50 +00:00
|
|
|
}
|
|
|
|
print("");
|
|
|
|
}
|
|
|
|
|
|
|
|
// Provide statistics on how well the bots are doing.
|
|
|
|
void statistic(int numerator, int denominator, String what) {
|
|
|
|
double percent = numerator / denominator * 100.0;
|
|
|
|
String percentString = percent.toStringAsFixed(2) + "%";
|
|
|
|
print("$numerator of $denominator $what ($percentString)");
|
|
|
|
}
|
|
|
|
|
|
|
|
statistic(failingTestsCount, tests.length, "tests are failing");
|
|
|
|
statistic(flakyTestsCount, tests.length, "tests are flaky");
|
|
|
|
statistic(
|
|
|
|
fixedTests.length, tests.length, "tests were fixed since last approval");
|
|
|
|
statistic(brokenTests.length, tests.length,
|
|
|
|
"tests were broken since last approval");
|
|
|
|
|
2019-03-12 14:51:24 +00:00
|
|
|
// Warn about any builders where results weren't available.
|
|
|
|
if (noResultsBuilds.isNotEmpty) {
|
|
|
|
print("");
|
|
|
|
noResultsBuilds.forEach((String builder, String buildUrl) {
|
|
|
|
print("Warning: No results were found for $builder: <$buildUrl>");
|
|
|
|
});
|
|
|
|
print("Warning: Builders without results are usually due to infrastructure "
|
|
|
|
"issues, please have a closer look at the affected builders and try "
|
|
|
|
"the build again.");
|
|
|
|
}
|
|
|
|
|
2018-11-06 01:08:50 +00:00
|
|
|
// Stop if there's nothing to do.
|
|
|
|
if (unapprovedBots.isEmpty) {
|
|
|
|
print("\nEvery test result has already been approved.");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Stop if this is a dry run.
|
|
|
|
if (options["no"]) {
|
2019-03-22 11:11:00 +00:00
|
|
|
if (selectedTests.length == 1) {
|
2018-11-06 01:08:50 +00:00
|
|
|
print("1 test has a changed result and needs approval");
|
|
|
|
} else {
|
2019-03-22 11:11:00 +00:00
|
|
|
print("${selectedTests.length} "
|
2018-11-06 01:08:50 +00:00
|
|
|
"tests have changed results and need approval");
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Confirm the approval if run interactively.
|
|
|
|
if (!options["yes"]) {
|
|
|
|
print("");
|
|
|
|
print("Note: It is assumed bugs have been filed about the above failures "
|
|
|
|
"before they are approved here.");
|
|
|
|
if (brokenTests.isNotEmpty) {
|
2019-03-22 11:11:00 +00:00
|
|
|
final builderPlural = bots.length == 1 ? "builder" : "builders";
|
|
|
|
final tryBuilders = isPreapproval ? "try$builderPlural" : builderPlural;
|
|
|
|
final tryCommit = isPreapproval ? "tryrun" : "commit";
|
2018-11-06 01:08:50 +00:00
|
|
|
print("Note: Approving the failures will turn the "
|
2019-03-22 11:11:00 +00:00
|
|
|
"$tryBuilders green on the next $tryCommit.");
|
2018-11-30 17:08:04 +00:00
|
|
|
}
|
2018-11-06 01:08:50 +00:00
|
|
|
while (true) {
|
2019-03-22 11:11:00 +00:00
|
|
|
final approve = isPreapproval ? "pre-approve" : "approve";
|
|
|
|
stdout.write("Do you want to $approve? (yes/no) [yes] ");
|
2018-11-06 01:08:50 +00:00
|
|
|
final line = stdin.readLineSync();
|
|
|
|
// End of file condition is considered no.
|
|
|
|
if (line == null) {
|
|
|
|
print("n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (line.toLowerCase() == "n" || line.toLowerCase() == "no") {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (line == "" ||
|
|
|
|
line.toLowerCase() == "y" ||
|
|
|
|
line.toLowerCase() == "yes") {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
print("Note: It is assumed bugs have been filed about the above failures.");
|
|
|
|
}
|
|
|
|
print("");
|
|
|
|
|
2018-12-05 10:58:29 +00:00
|
|
|
// Log who approved these results.
|
2019-01-21 12:02:26 +00:00
|
|
|
final username =
|
|
|
|
(options["automated-approver"] ? "automatic-approval" : null) ??
|
|
|
|
Platform.environment["LOGNAME"] ??
|
|
|
|
Platform.environment["USER"] ??
|
|
|
|
Platform.environment["USERNAME"];
|
2018-12-05 10:58:29 +00:00
|
|
|
if (username == null || username == "") {
|
|
|
|
stderr.writeln("error: Your identity could not be established. "
|
|
|
|
"Please set one of the LOGNAME, USER, USERNAME environment variables.");
|
|
|
|
exitCode = 1;
|
|
|
|
return;
|
|
|
|
}
|
2019-03-22 12:07:35 +00:00
|
|
|
final nowDate = new DateTime.now().toUtc();
|
|
|
|
final now = nowDate.toIso8601String();
|
2018-12-05 10:58:29 +00:00
|
|
|
|
2019-03-22 11:11:00 +00:00
|
|
|
// Deep clones a decoded json object.
|
|
|
|
dynamic deepClone(dynamic object) {
|
|
|
|
if (object is Map<String, dynamic>) {
|
|
|
|
final result = <String, dynamic>{};
|
|
|
|
for (final key in object.keys) {
|
|
|
|
result[key] = deepClone(object[key]);
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
} else if (object is List<dynamic>) {
|
|
|
|
final result = <dynamic>[];
|
|
|
|
for (final value in object) {
|
|
|
|
result.add(deepClone(value));
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
} else {
|
|
|
|
return object;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Build the new approval data with the changes in test results applied.
|
|
|
|
final newApprovalsForBuilders = <String, Map<String, Map<String, dynamic>>>{};
|
|
|
|
|
|
|
|
if (isPreapproval) {
|
|
|
|
// Import all the existing approval data, keeping tests that don't exist
|
|
|
|
// anymore.
|
|
|
|
for (final test in tests) {
|
|
|
|
if (test.approvedResultData == null) continue;
|
|
|
|
final approvalData = deepClone(test.approvedResultData);
|
|
|
|
// TODO(https://github.com/dart-lang/sdk/issues/36279): Remove needless
|
|
|
|
// fields that shouldn't be in the approvals data. Remove this 2019-04-03.
|
|
|
|
approvalData.remove("bot_name");
|
|
|
|
approvalData.remove("builder_name");
|
|
|
|
approvalData.remove("build_number");
|
|
|
|
approvalData.remove("changed");
|
|
|
|
approvalData.remove("commit_hash");
|
|
|
|
approvalData.remove("commit_time");
|
|
|
|
approvalData.remove("commit_hash");
|
|
|
|
approvalData.remove("flaky");
|
|
|
|
approvalData.remove("previous_build_number");
|
|
|
|
approvalData.remove("previous_commit_hash");
|
|
|
|
approvalData.remove("previous_commit_time");
|
|
|
|
approvalData.remove("previous_flaky");
|
|
|
|
approvalData.remove("previous_result");
|
|
|
|
approvalData.remove("time_ms");
|
|
|
|
// Discard all the existing pre-approvals for this changelist.
|
|
|
|
final preapprovals =
|
|
|
|
approvalData.putIfAbsent("preapprovals", () => <String, dynamic>{});
|
|
|
|
preapprovals.remove(changeId);
|
|
|
|
final newApprovals = newApprovalsForBuilders.putIfAbsent(
|
|
|
|
test.bot, () => new SplayTreeMap<String, Map<String, dynamic>>());
|
|
|
|
newApprovals[test.key] = approvalData;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Pre-approve all the regressions (no need to pre-approve fixed tests).
|
|
|
|
for (final test in brokenTests) {
|
|
|
|
final newApprovals = newApprovalsForBuilders.putIfAbsent(
|
|
|
|
test.bot, () => new SplayTreeMap<String, Map<String, dynamic>>());
|
|
|
|
final approvalData =
|
|
|
|
newApprovals.putIfAbsent(test.key, () => <String, dynamic>{});
|
2019-03-25 14:34:21 +00:00
|
|
|
approvalData["name"] = test.name;
|
|
|
|
approvalData["configuration"] = test.configuration;
|
|
|
|
approvalData["suite"] = test.resultData["suite"];
|
|
|
|
approvalData["test_name"] = test.resultData["test_name"];
|
2019-03-22 11:11:00 +00:00
|
|
|
final preapprovals =
|
|
|
|
approvalData.putIfAbsent("preapprovals", () => <String, dynamic>{});
|
|
|
|
final preapproval =
|
|
|
|
preapprovals.putIfAbsent(changeId, () => <String, dynamic>{});
|
|
|
|
preapproval["from"] = test.approvedResult;
|
|
|
|
preapproval["result"] = test.result;
|
|
|
|
preapproval["matches"] = test.matches;
|
|
|
|
preapproval["expected"] = test.expected;
|
|
|
|
preapproval["preapprover"] = username;
|
|
|
|
preapproval["preapproved_at"] = now;
|
2019-03-22 12:07:35 +00:00
|
|
|
preapproval["expires"] =
|
|
|
|
nowDate.add(const Duration(days: 30)).toIso8601String();
|
2019-03-22 11:11:00 +00:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
// Import all the existing approval data for tests, removing tests that
|
|
|
|
// don't exist anymore unless they have pre-approvals.
|
2018-11-06 01:08:50 +00:00
|
|
|
for (final test in tests) {
|
2019-03-22 11:11:00 +00:00
|
|
|
if (test.approvedResultData == null) continue;
|
|
|
|
if (test.result == null &&
|
2019-03-25 14:34:21 +00:00
|
|
|
(test.approvedResultData["preapprovals"] ?? <dynamic>[]).isEmpty) {
|
|
|
|
continue;
|
|
|
|
}
|
2019-03-22 11:11:00 +00:00
|
|
|
final approvalData = deepClone(test.approvedResultData);
|
|
|
|
// TODO(https://github.com/dart-lang/sdk/issues/36279): Remove needless
|
|
|
|
// fields that shouldn't be in the approvals data. Remove this 2019-04-03.
|
|
|
|
approvalData.remove("bot_name");
|
|
|
|
approvalData.remove("builder_name");
|
|
|
|
approvalData.remove("build_number");
|
|
|
|
approvalData.remove("changed");
|
|
|
|
approvalData.remove("commit_hash");
|
|
|
|
approvalData.remove("commit_time");
|
|
|
|
approvalData.remove("commit_hash");
|
|
|
|
approvalData.remove("flaky");
|
|
|
|
approvalData.remove("previous_build_number");
|
|
|
|
approvalData.remove("previous_commit_hash");
|
|
|
|
approvalData.remove("previous_commit_time");
|
|
|
|
approvalData.remove("previous_flaky");
|
|
|
|
approvalData.remove("previous_result");
|
|
|
|
approvalData.remove("time_ms");
|
|
|
|
approvalData.putIfAbsent("preapprovals", () => <String, dynamic>{});
|
|
|
|
final newApprovals = newApprovalsForBuilders.putIfAbsent(
|
|
|
|
test.bot, () => new SplayTreeMap<String, Map<String, dynamic>>());
|
|
|
|
newApprovals[test.key] = approvalData;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Approve the changes in test results.
|
|
|
|
for (final test in selectedTests) {
|
|
|
|
final newApprovals = newApprovalsForBuilders.putIfAbsent(
|
|
|
|
test.bot, () => new SplayTreeMap<String, Map<String, dynamic>>());
|
|
|
|
final approvalData =
|
|
|
|
newApprovals.putIfAbsent(test.key, () => <String, dynamic>{});
|
|
|
|
approvalData["name"] = test.name;
|
|
|
|
approvalData["configuration"] = test.configuration;
|
|
|
|
approvalData["suite"] = test.resultData["suite"];
|
|
|
|
approvalData["test_name"] = test.resultData["test_name"];
|
|
|
|
approvalData["result"] = test.result;
|
|
|
|
approvalData["expected"] = test.expected;
|
|
|
|
approvalData["matches"] = test.matches;
|
|
|
|
approvalData["approver"] = username;
|
|
|
|
approvalData["approved_at"] = now;
|
|
|
|
approvalData.putIfAbsent("preapprovals", () => <String, dynamic>{});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-03-27 09:56:22 +00:00
|
|
|
// Reconstruct the old approvals so we can double check there was no race
|
|
|
|
// condition when uploading.
|
|
|
|
final oldApprovalsForBuilders = <String, Map<String, Map<String, dynamic>>>{};
|
|
|
|
for (final test in tests) {
|
|
|
|
if (test.approvedResultData == null) continue;
|
|
|
|
final oldApprovals = oldApprovalsForBuilders.putIfAbsent(
|
|
|
|
test.bot, () => new SplayTreeMap<String, Map<String, dynamic>>());
|
|
|
|
oldApprovals[test.key] = test.approvedResultData;
|
|
|
|
}
|
2019-03-22 11:11:00 +00:00
|
|
|
for (final builder in newApprovalsForBuilders.keys) {
|
2019-03-27 09:56:22 +00:00
|
|
|
oldApprovalsForBuilders.putIfAbsent(
|
|
|
|
builder, () => <String, Map<String, dynamic>>{});
|
2019-03-22 11:11:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Update approved_results.json for each builder with unapproved changes.
|
|
|
|
final outDirectory =
|
|
|
|
await Directory.systemTemp.createTemp("approved_results.");
|
|
|
|
bool raceCondition = false;
|
|
|
|
try {
|
2018-11-06 01:08:50 +00:00
|
|
|
print("Uploading approved results...");
|
|
|
|
final futures = <Future>[];
|
2019-03-22 11:11:00 +00:00
|
|
|
for (final String builder in newApprovalsForBuilders.keys) {
|
|
|
|
final approvals = newApprovalsForBuilders[builder].values;
|
|
|
|
final localPath = "${outDirectory.path}/$builder.json";
|
2018-11-06 01:08:50 +00:00
|
|
|
await new File(localPath).writeAsString(
|
2019-03-22 11:11:00 +00:00
|
|
|
approvals.map((approval) => jsonEncode(approval) + "\n").join(""));
|
2018-11-08 18:53:19 +00:00
|
|
|
final remotePath =
|
2019-03-22 11:11:00 +00:00
|
|
|
"$approvedResultsStoragePath/$builder/approved_results.json";
|
|
|
|
futures.add(new Future(() async {
|
|
|
|
if (!options["yes"]) {
|
|
|
|
if (options["verbose"]) {
|
|
|
|
print("Checking for race condition on $builder...");
|
|
|
|
}
|
|
|
|
final oldApprovedResults = oldApprovalsForBuilders[builder];
|
|
|
|
final oldApprovalPath = "${outDirectory.path}/$builder.json.old";
|
|
|
|
await cpGsutil(remotePath, oldApprovalPath);
|
|
|
|
final checkApprovedResults =
|
|
|
|
await loadResultsMapIfExists(oldApprovalPath);
|
|
|
|
if (!isIdenticalApprovals(oldApprovedResults, checkApprovedResults)) {
|
|
|
|
print("error: Race condition: "
|
|
|
|
"$builder approvals have changed, please try again.");
|
|
|
|
raceCondition = true;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (options["verbose"]) {
|
|
|
|
print("Uploading approved results for $builder...");
|
|
|
|
}
|
|
|
|
await cpGsutil(localPath, remotePath);
|
|
|
|
print("Uploaded approved results for $builder");
|
|
|
|
}));
|
2018-11-06 01:08:50 +00:00
|
|
|
}
|
|
|
|
await Future.wait(futures);
|
2019-03-22 11:11:00 +00:00
|
|
|
if (raceCondition) {
|
|
|
|
exitCode = 1;
|
|
|
|
print("error: Somebody else has approved, please try again");
|
|
|
|
return;
|
|
|
|
}
|
2018-11-06 01:08:50 +00:00
|
|
|
if (brokenTests.isNotEmpty) {
|
2019-03-22 11:11:00 +00:00
|
|
|
final approved = isPreapproval ? "pre-approved" : "approved";
|
|
|
|
final commit = isPreapproval ? "tryrun" : "commit";
|
|
|
|
print("Successfully $approved results, the next $commit "
|
|
|
|
"will turn builders green");
|
2018-11-06 01:08:50 +00:00
|
|
|
} else {
|
|
|
|
print("Successfully approved results");
|
|
|
|
}
|
|
|
|
} finally {
|
|
|
|
await outDirectory.delete(recursive: true);
|
|
|
|
}
|
|
|
|
}
|