Visitar URL original
Add supported Luci builders for packages repo by keyonghan · Pull Request #184 · flutter/packages · GitHub
Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
add code to validate json contents
  • Loading branch information
keyonghan committed Aug 5, 2020
commit 9e3ec3084e6642cd717b5eda430fec19c4628c1f
5 changes: 4 additions & 1 deletion dev/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,7 @@ for packages. It follows format:
This file will be mainly used in [`flutter/cocoon`](https://github.com/flutter/cocoon)
to update luci task statuses of packages pre-submit tests.


If any new changes, please validate json contents by running
```
dart validate_json.dart packages_try_builders.json
```
73 changes: 73 additions & 0 deletions dev/validate_json.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
// Copyright 2020 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 'dart:convert';
import 'dart:io';
import 'dart:io' show File;
import 'dart:io' as io_internals show exit;

final bool hasColor = stdout.supportsAnsiEscapes;
final String bold = hasColor ? '\x1B[1m' : ''; // used for shard titles
final String red = hasColor ? '\x1B[31m' : ''; // used for errors
final String reset = hasColor ? '\x1B[0m' : '';
final String reverse = hasColor ? '\x1B[7m' : ''; // used for clocks

/// Validates if the input builders JSON file has valid contents.
///
/// Examples:
/// dart validate_json.dart /path/to/json/file
Future<void> main(List<String> args) async {
final String jsonString = await File(args[0]).readAsString();
Map<String, dynamic> decodedJson;
final List<String> messages = <String>[];
try {
decodedJson = json.decode(jsonString) as Map<String, dynamic>;
final List<dynamic> builders = decodedJson['builders'] as List<dynamic>;
if (builders == null) {
messages.add('${bold}Json format is violated: no "builders" exists. Please follow: $reset');
messages.add('''
{
"builders":[
{
"name":"xxx",
"repo":"cocoon"
}
]
}''');
exitWithError(messages);
}
} on ExitException catch (error) {
error.apply();
}
print('$clock ${bold}Analysis successful.$reset');
}

class ExitException implements Exception {
ExitException(this.exitCode);

final int exitCode;

void apply() {
io_internals.exit(exitCode);
}
}

void exitWithError(List<String> messages) {
final String redLine = '$red━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━$reset';
print(redLine);
messages.forEach(print);
print(redLine);
exit(1);
}

String get clock {
final DateTime now = DateTime.now();
return '$reverse▌'
'${now.hour.toString().padLeft(2, "0")}:'
'${now.minute.toString().padLeft(2, "0")}:'
'${now.second.toString().padLeft(2, "0")}'
'▐$reset';
}