Skip to content

Commit

Permalink
[infra] Support posting results to staging in post_results_to_pubsub
Browse files Browse the repository at this point in the history
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 <whesse@google.com>
Commit-Queue: Karl Klose <karlklose@google.com>
  • Loading branch information
karlklose authored and commit-bot@chromium.org committed Jun 26, 2020
1 parent 63cf56d commit 718df63
Showing 1 changed file with 24 additions and 4 deletions.
28 changes: 24 additions & 4 deletions tools/bots/post_results_to_pubsub.dart
Original file line number Diff line number Diff line change
Expand Up @@ -17,20 +17,23 @@ import 'dart:io';
import 'package:args/args.dart';
import 'package:http/http.dart' as http;

void usage(ArgParser parser) {
void usage(ArgParser parser, {exitCode = 0}) {
print('''
Usage: post_results_to_pubsub.dart [OPTIONS]
Posts Dart CI results as messages to Google Cloud Pub/Sub
The options are as follows:
${parser.usage}''');
exit(1);
exit(exitCode);
}

const resultsPerMessage = 100;
const postUrl =
'https://pubsub.googleapis.com/v1/projects/dart-ci/topics/results:publish';

String getPostUrl(String project) {
return 'https://pubsub.googleapis.com/v1/projects/$project'
'/topics/results:publish';
}

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

final options = parser.parse(args);
if (options['help']) {
usage(parser);
}

if (options['result_file'] == null) {
print('Error: option "result_file" is required.\n');
usage(parser, exitCode: 1);
}

if (options['auth_token'] == null) {
print('Error: option "auth_token" is required.\n');
usage(parser, exitCode: 1);
}

final project = options['staging'] ? "dart-ci-staging" : "dart-ci";

final client = http.Client();

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

// TODO(karlklose): parse and validate data before sending it.

final changedPattern = '"changed":true';
List<String> changedResults =
lines.where((change) => change.contains(changedPattern)).toList();
Expand Down Expand Up @@ -95,6 +114,7 @@ main(List<String> args) async {
]
});
final headers = {'Authorization': 'Bearer $token'};
final postUrl = getPostUrl(project);
final response =
await client.post(postUrl, headers: headers, body: jsonMessage);

Expand Down

0 comments on commit 718df63

Please sign in to comment.