git branch flag (#71886)
This commit is contained in:
@@ -22,6 +22,9 @@ List<String> _taskNames = <String>[];
|
||||
/// The device-id to run test on.
|
||||
String deviceId;
|
||||
|
||||
/// The git branch being tested on.
|
||||
String gitBranch;
|
||||
|
||||
/// The build of the local engine to use.
|
||||
///
|
||||
/// Required for A/B test mode.
|
||||
@@ -88,6 +91,7 @@ Future<void> main(List<String> rawArgs) async {
|
||||
|
||||
deviceId = args['device-id'] as String;
|
||||
exitOnFirstTestFailure = args['exit'] as bool;
|
||||
gitBranch = args['git-branch'] as String;
|
||||
localEngine = args['local-engine'] as String;
|
||||
localEngineSrcPath = args['local-engine-src-path'] as String;
|
||||
luciBuilder = args['luci-builder'] as String;
|
||||
@@ -119,7 +123,7 @@ Future<void> _runTasks() async {
|
||||
if (serviceAccountTokenFile != null) {
|
||||
final Cocoon cocoon = Cocoon(serviceAccountTokenPath: serviceAccountTokenFile);
|
||||
/// Cocoon references LUCI tasks by the [luciBuilder] instead of [taskName].
|
||||
await cocoon.sendTaskResult(builderName: luciBuilder, result: result);
|
||||
await cocoon.sendTaskResult(builderName: luciBuilder, result: result, gitBranch: gitBranch);
|
||||
}
|
||||
|
||||
if (!result.succeeded) {
|
||||
@@ -326,6 +330,11 @@ final ArgParser _argParser = ArgParser()
|
||||
defaultsTo: true,
|
||||
help: 'Exit on the first test failure.',
|
||||
)
|
||||
..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.',
|
||||
)
|
||||
..addOption(
|
||||
'local-engine',
|
||||
help: 'Name of a build output within the engine out directory, if you\n'
|
||||
|
||||
@@ -48,9 +48,6 @@ class Cocoon {
|
||||
|
||||
static final Logger logger = Logger('CocoonClient');
|
||||
|
||||
String get commitBranch => _commitBranch ?? _readCommitBranch();
|
||||
String _commitBranch;
|
||||
|
||||
String get commitSha => _commitSha ?? _readCommitSha();
|
||||
String _commitSha;
|
||||
|
||||
@@ -64,18 +61,12 @@ class Cocoon {
|
||||
return _commitSha = result.stdout as String;
|
||||
}
|
||||
|
||||
/// Parse the local repo for the current running branch.
|
||||
String _readCommitBranch() {
|
||||
final ProcessResult result = processRunSync('git', <String>['rev-parse', '--abbrev-ref', 'HEAD']);
|
||||
if (result.exitCode != 0) {
|
||||
throw CocoonException(result.stderr as String);
|
||||
}
|
||||
|
||||
return _commitBranch = result.stdout as String;
|
||||
}
|
||||
|
||||
/// Send [TaskResult] to Cocoon.
|
||||
Future<void> sendTaskResult({String builderName, TaskResult result}) async {
|
||||
Future<void> sendTaskResult({@required String builderName, @required TaskResult result, @required String gitBranch}) async {
|
||||
assert(builderName != null);
|
||||
assert(gitBranch != null);
|
||||
assert(result != null);
|
||||
|
||||
// Skip logging on test runs
|
||||
Logger.root.level = Level.ALL;
|
||||
Logger.root.onRecord.listen((LogRecord rec) {
|
||||
@@ -83,7 +74,7 @@ class Cocoon {
|
||||
});
|
||||
|
||||
final Map<String, dynamic> status = <String, dynamic>{
|
||||
'CommitBranch': commitBranch,
|
||||
'CommitBranch': gitBranch,
|
||||
'CommitSha': commitSha,
|
||||
'BuilderName': builderName,
|
||||
'NewStatus': result.succeeded ? 'Succeeded' : 'Failed',
|
||||
|
||||
@@ -27,7 +27,6 @@ void main() {
|
||||
_processResult;
|
||||
|
||||
// Expected test values.
|
||||
const String commitBranch = 'flutter-1.23-candidate.18';
|
||||
const String commitSha = 'a4952838bf288a81d8ea11edfd4b4cd649fa94cc';
|
||||
const String serviceAccountTokenPath = 'test_account_file';
|
||||
const String serviceAccountToken = 'test_token';
|
||||
@@ -45,18 +44,6 @@ void main() {
|
||||
serviceAccountFile.writeAsStringSync(serviceAccountToken);
|
||||
});
|
||||
|
||||
test('returns expected commit branch', () {
|
||||
_processResult = ProcessResult(1, 0, commitBranch, '');
|
||||
cocoon = Cocoon(
|
||||
serviceAccountTokenPath: serviceAccountTokenPath,
|
||||
filesystem: fs,
|
||||
httpClient: mockClient,
|
||||
processRunSync: runSyncStub,
|
||||
);
|
||||
|
||||
expect(cocoon.commitBranch, commitBranch);
|
||||
});
|
||||
|
||||
test('returns expected commit sha', () {
|
||||
_processResult = ProcessResult(1, 0, commitSha, '');
|
||||
cocoon = Cocoon(
|
||||
@@ -78,7 +65,6 @@ void main() {
|
||||
processRunSync: runSyncStub,
|
||||
);
|
||||
|
||||
expect(() => cocoon.commitBranch, throwsA(isA<CocoonException>()));
|
||||
expect(() => cocoon.commitSha, throwsA(isA<CocoonException>()));
|
||||
});
|
||||
|
||||
@@ -93,7 +79,7 @@ void main() {
|
||||
|
||||
final TaskResult result = TaskResult.success(<String, dynamic>{});
|
||||
// This should not throw an error.
|
||||
await cocoon.sendTaskResult(builderName: 'builderAbc', result: result);
|
||||
await cocoon.sendTaskResult(builderName: 'builderAbc', gitBranch: 'branchAbc', result: result);
|
||||
});
|
||||
|
||||
test('throws client exception on non-200 responses', () async {
|
||||
@@ -106,7 +92,20 @@ void main() {
|
||||
);
|
||||
|
||||
final TaskResult result = TaskResult.success(<String, dynamic>{});
|
||||
expect(() => cocoon.sendTaskResult(builderName: 'builderAbc', result: result), throwsA(isA<ClientException>()));
|
||||
expect(() => cocoon.sendTaskResult(builderName: 'builderAbc', gitBranch: 'branchAbc', result: result), throwsA(isA<ClientException>()));
|
||||
});
|
||||
|
||||
test('null git branch throws error', () async {
|
||||
mockClient = MockClient((Request request) async => Response('', 500));
|
||||
|
||||
cocoon = Cocoon(
|
||||
serviceAccountTokenPath: serviceAccountTokenPath,
|
||||
filesystem: fs,
|
||||
httpClient: mockClient,
|
||||
);
|
||||
|
||||
final TaskResult result = TaskResult.success(<String, dynamic>{});
|
||||
expect(() => cocoon.sendTaskResult(builderName: 'builderAbc', gitBranch: null, result: result), throwsA(isA<AssertionError>()));
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user