|
| 1 | +#!/usr/bin/env dart |
| 2 | +// Copyright (c) 2023, the Dart project authors. Please see the AUTHORS file |
| 3 | +// for details. All rights reserved. Use of this source code is governed by a |
| 4 | +// BSD-style license that can be found in the LICENSE file. |
| 5 | + |
| 6 | +// A script to find all try jobs for a set of tests. |
| 7 | +// |
| 8 | +// Usage: |
| 9 | +// |
| 10 | +// ``` |
| 11 | +// $ tools/find_builders.dart ffi/regress_51504_test ffi/regress_51913_test |
| 12 | +// Cq-Include-Trybots: luci.dart.try:vm-kernel-linux-debug-x64,... |
| 13 | +// ``` |
| 14 | + |
| 15 | +import 'dart:convert'; |
| 16 | +import 'dart:io'; |
| 17 | + |
| 18 | +// TODO(dacoharkes): Be able to use test full paths instead of test names. |
| 19 | +// TODO(dacoharkes): Be able to use different filters. |
| 20 | +Future<void> main(List<String> args) async { |
| 21 | + if (args.contains('--help')) { |
| 22 | + return printHelp(); |
| 23 | + } |
| 24 | + final testNames = args; |
| 25 | + |
| 26 | + final configurations = _filterConfigurations({ |
| 27 | + for (final testName in testNames) ...await _testGetConfigurations(testName), |
| 28 | + }); |
| 29 | + final configurationBuilders = await _configurationBuilders(); |
| 30 | + final builders = [ |
| 31 | + for (final config in configurations) configurationBuilders[config] |
| 32 | + ]..sort(); |
| 33 | + |
| 34 | + print('Cq-Include-Trybots: luci.dart.try:${builders.join(',')}'); |
| 35 | +} |
| 36 | + |
| 37 | +Future<List<String>> _testGetConfigurations(String testName) async { |
| 38 | + final requestUrl = Uri.parse( |
| 39 | + 'https://current-results-qvyo5rktwa-uc.a.run.app/v1/results?filter=$testName'); |
| 40 | + final response = await _get(requestUrl); |
| 41 | + final object = jsonDecode(response) as Map<String, dynamic>; |
| 42 | + final results = (object['results'] as List).cast<Map<String, dynamic>>(); |
| 43 | + return [for (final result in results) result['configuration'] as String]; |
| 44 | +} |
| 45 | + |
| 46 | +Future<String> _get(Uri requestUrl) async { |
| 47 | + final client = HttpClient(); |
| 48 | + final request = await client.getUrl(requestUrl); |
| 49 | + final response = await request.close(); |
| 50 | + final responseString = |
| 51 | + await response.cast<List<int>>().transform(const Utf8Decoder()).join(); |
| 52 | + client.close(); |
| 53 | + return responseString; |
| 54 | +} |
| 55 | + |
| 56 | +Iterable<String> _filterConfigurations(Set<String> configs) { |
| 57 | + final result = <String>[]; |
| 58 | + for (final config in configs) { |
| 59 | + if (config.contains('debug')) { |
| 60 | + result.add(config); |
| 61 | + } else if (config.contains('release') && |
| 62 | + !configs.contains(config.replaceFirst('release', 'debug'))) { |
| 63 | + result.add(config); |
| 64 | + } else if (config.contains('profile') && |
| 65 | + !configs.contains(config.replaceFirst('profile', 'debug')) && |
| 66 | + !configs.contains(config.replaceFirst('profile', 'release'))) { |
| 67 | + result.add(config); |
| 68 | + } |
| 69 | + } |
| 70 | + return result..sort(); |
| 71 | +} |
| 72 | + |
| 73 | +Stream<Map<String, dynamic>> _configurationDocuments() async* { |
| 74 | + String? nextPageToken; |
| 75 | + while (true) { |
| 76 | + final requestUrl = Uri( |
| 77 | + scheme: 'https', |
| 78 | + host: 'firestore.googleapis.com', |
| 79 | + path: 'v1/projects/dart-ci/databases/(default)/documents/configurations', |
| 80 | + queryParameters: { |
| 81 | + 'pageSize': '300', |
| 82 | + if (nextPageToken != null) 'pageToken': nextPageToken, |
| 83 | + }, |
| 84 | + ); |
| 85 | + final response = await _get(requestUrl); |
| 86 | + final object = jsonDecode(response) as Map<String, dynamic>; |
| 87 | + final documents = |
| 88 | + (object['documents'] as List).cast<Map<String, dynamic>>(); |
| 89 | + for (final d in documents) { |
| 90 | + yield d; |
| 91 | + } |
| 92 | + |
| 93 | + nextPageToken = object['nextPageToken'] as String?; |
| 94 | + if (nextPageToken == null) { |
| 95 | + break; |
| 96 | + } |
| 97 | + } |
| 98 | +} |
| 99 | + |
| 100 | +Future<Map<String, String>> _configurationBuilders() async { |
| 101 | + final result = <String, String>{}; |
| 102 | + await for (final document in _configurationDocuments()) { |
| 103 | + final fullName = document['name'] as String; |
| 104 | + final name = fullName.split('/').last; |
| 105 | + final builder = document['fields']['builder']['stringValue'] as String?; |
| 106 | + if (builder != null) { |
| 107 | + result[name] = builder; |
| 108 | + } |
| 109 | + } |
| 110 | + return result; |
| 111 | +} |
| 112 | + |
| 113 | +void printHelp() { |
| 114 | + print(r''' |
| 115 | +A script to find all try jobs for a set of tests. |
| 116 | +
|
| 117 | + Usage: tools/find_builders.dart [selector] [selector2] [...] |
| 118 | +
|
| 119 | +Sample output: Cq-Include-Trybots: luci.dart.try:vm-kernel-linux-debug-x64,... |
| 120 | +'''); |
| 121 | +} |
0 commit comments