upload_results.dart 2.99 KB
Newer Older
1 2 3 4 5 6 7
// Copyright 2014 The Flutter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

import 'package:args/command_runner.dart';

import '../framework/cocoon.dart';
8
import '../framework/metrics_center.dart';
9 10 11 12 13 14 15 16

class UploadResultsCommand extends Command<void> {
  UploadResultsCommand() {
    argParser.addOption('results-file', help: 'Test results JSON to upload to Cocoon.');
    argParser.addOption(
      'service-account-token-file',
      help: 'Authentication token for uploading results.',
    );
keyonghan's avatar
keyonghan committed
17
    argParser.addOption('test-flaky', help: 'Flag to show whether the test is flaky: "True" or "False"');
18 19 20 21 22 23
    argParser.addOption(
      'git-branch',
      help: '[Flutter infrastructure] Git branch of the current commit. LUCI\n'
          'checkouts run in detached HEAD state, so the branch must be passed.',
    );
    argParser.addOption('luci-builder', help: '[Flutter infrastructure] Name of the LUCI builder being run on.');
24
    argParser.addOption('task-name', help: '[Flutter infrastructure] Name of the task being run on.');
25
    argParser.addOption('benchmark-tags', help: '[Flutter infrastructure] Benchmark tags to surface on Skia Perf');
26
    argParser.addOption('test-status', help: 'Test status: Succeeded|Failed');
27
    argParser.addOption('commit-time', help: 'Commit time in UNIX timestamp');
28
    argParser.addOption('builder-bucket', help: '[Flutter infrastructure] Luci builder bucket the test is running in.');
29 30 31 32 33 34
  }

  @override
  String get name => 'upload-metrics';

  @override
35
  String get description => '[Flutter infrastructure] Upload results data to Cocoon/Skia Perf';
36 37 38 39 40

  @override
  Future<void> run() async {
    final String? resultsPath = argResults!['results-file'] as String?;
    final String? serviceAccountTokenFile = argResults!['service-account-token-file'] as String?;
keyonghan's avatar
keyonghan committed
41
    final String? testFlakyStatus = argResults!['test-flaky'] as String?;
42 43 44
    final String? gitBranch = argResults!['git-branch'] as String?;
    final String? builderName = argResults!['luci-builder'] as String?;
    final String? testStatus = argResults!['test-status'] as String?;
45
    final String? commitTime = argResults!['commit-time'] as String?;
46
    final String? taskName = argResults!['task-name'] as String?;
47
    final String? benchmarkTags = argResults!['benchmark-tags'] as String?;
48
    final String? builderBucket = argResults!['builder-bucket'] as String?;
49

50 51
    // Upload metrics to skia perf from test runner when `resultsPath` is specified.
    if (resultsPath != null) {
52
      await uploadToSkiaPerf(resultsPath, commitTime, taskName, benchmarkTags);
53
      print('Successfully uploaded metrics to skia perf');
54
    }
55 56

    final Cocoon cocoon = Cocoon(serviceAccountTokenPath: serviceAccountTokenFile);
57
    return cocoon.sendTaskStatus(
58
      resultsPath: resultsPath,
keyonghan's avatar
keyonghan committed
59
      isTestFlaky: testFlakyStatus == 'True',
60 61 62
      gitBranch: gitBranch,
      builderName: builderName,
      testStatus: testStatus,
63
      builderBucket: builderBucket,
64 65 66
    );
  }
}