Skip to content

Commit 718df63

Browse files
karlklosecommit-bot@chromium.org
authored andcommitted
[infra] Support posting results to staging in post_results_to_pubsub
This adds the option '-s' to select posting the results to the staging system instead of the production system. Change-Id: I990a39c7db3d0379935b69007ebc9477da5cc051 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/151528 Reviewed-by: William Hesse <[email protected]> Commit-Queue: Karl Klose <[email protected]>
1 parent 63cf56d commit 718df63

File tree

1 file changed

+24
-4
lines changed

1 file changed

+24
-4
lines changed

tools/bots/post_results_to_pubsub.dart

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,20 +17,23 @@ import 'dart:io';
1717
import 'package:args/args.dart';
1818
import 'package:http/http.dart' as http;
1919

20-
void usage(ArgParser parser) {
20+
void usage(ArgParser parser, {exitCode = 0}) {
2121
print('''
2222
Usage: post_results_to_pubsub.dart [OPTIONS]
2323
Posts Dart CI results as messages to Google Cloud Pub/Sub
2424
2525
The options are as follows:
2626
2727
${parser.usage}''');
28-
exit(1);
28+
exit(exitCode);
2929
}
3030

3131
const resultsPerMessage = 100;
32-
const postUrl =
33-
'https://pubsub.googleapis.com/v1/projects/dart-ci/topics/results:publish';
32+
33+
String getPostUrl(String project) {
34+
return 'https://pubsub.googleapis.com/v1/projects/$project'
35+
'/topics/results:publish';
36+
}
3437

3538
main(List<String> args) async {
3639
final parser = new ArgParser();
@@ -42,12 +45,26 @@ main(List<String> args) async {
4245
abbr: 'f', help: 'File containing the results to send');
4346
parser.addOption('id', abbr: 'i', help: 'Buildbucket ID of this build');
4447
parser.addOption('base_revision', help: 'A try build\'s patch base');
48+
parser.addFlag('staging',
49+
abbr: 's', help: 'Publish to the staging system', defaultsTo: false);
4550

4651
final options = parser.parse(args);
4752
if (options['help']) {
4853
usage(parser);
4954
}
5055

56+
if (options['result_file'] == null) {
57+
print('Error: option "result_file" is required.\n');
58+
usage(parser, exitCode: 1);
59+
}
60+
61+
if (options['auth_token'] == null) {
62+
print('Error: option "auth_token" is required.\n');
63+
usage(parser, exitCode: 1);
64+
}
65+
66+
final project = options['staging'] ? "dart-ci-staging" : "dart-ci";
67+
5168
final client = http.Client();
5269

5370
final lines = await File(options['result_file']).readAsLines();
@@ -59,6 +76,8 @@ main(List<String> args) async {
5976
return;
6077
}
6178

79+
// TODO(karlklose): parse and validate data before sending it.
80+
6281
final changedPattern = '"changed":true';
6382
List<String> changedResults =
6483
lines.where((change) => change.contains(changedPattern)).toList();
@@ -95,6 +114,7 @@ main(List<String> args) async {
95114
]
96115
});
97116
final headers = {'Authorization': 'Bearer $token'};
117+
final postUrl = getPostUrl(project);
98118
final response =
99119
await client.post(postUrl, headers: headers, body: jsonMessage);
100120

0 commit comments

Comments
 (0)