Unverified Commit 2565062d authored by Casey Hillers's avatar Casey Hillers Committed by GitHub

git branch flag (#71886)

parent c88ab79b
...@@ -22,6 +22,9 @@ List<String> _taskNames = <String>[]; ...@@ -22,6 +22,9 @@ List<String> _taskNames = <String>[];
/// The device-id to run test on. /// The device-id to run test on.
String deviceId; String deviceId;
/// The git branch being tested on.
String gitBranch;
/// The build of the local engine to use. /// The build of the local engine to use.
/// ///
/// Required for A/B test mode. /// Required for A/B test mode.
...@@ -88,6 +91,7 @@ Future<void> main(List<String> rawArgs) async { ...@@ -88,6 +91,7 @@ Future<void> main(List<String> rawArgs) async {
deviceId = args['device-id'] as String; deviceId = args['device-id'] as String;
exitOnFirstTestFailure = args['exit'] as bool; exitOnFirstTestFailure = args['exit'] as bool;
gitBranch = args['git-branch'] as String;
localEngine = args['local-engine'] as String; localEngine = args['local-engine'] as String;
localEngineSrcPath = args['local-engine-src-path'] as String; localEngineSrcPath = args['local-engine-src-path'] as String;
luciBuilder = args['luci-builder'] as String; luciBuilder = args['luci-builder'] as String;
...@@ -119,7 +123,7 @@ Future<void> _runTasks() async { ...@@ -119,7 +123,7 @@ Future<void> _runTasks() async {
if (serviceAccountTokenFile != null) { if (serviceAccountTokenFile != null) {
final Cocoon cocoon = Cocoon(serviceAccountTokenPath: serviceAccountTokenFile); final Cocoon cocoon = Cocoon(serviceAccountTokenPath: serviceAccountTokenFile);
/// Cocoon references LUCI tasks by the [luciBuilder] instead of [taskName]. /// 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) { if (!result.succeeded) {
...@@ -326,6 +330,11 @@ final ArgParser _argParser = ArgParser() ...@@ -326,6 +330,11 @@ final ArgParser _argParser = ArgParser()
defaultsTo: true, defaultsTo: true,
help: 'Exit on the first test failure.', 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( ..addOption(
'local-engine', 'local-engine',
help: 'Name of a build output within the engine out directory, if you\n' help: 'Name of a build output within the engine out directory, if you\n'
......
...@@ -48,9 +48,6 @@ class Cocoon { ...@@ -48,9 +48,6 @@ class Cocoon {
static final Logger logger = Logger('CocoonClient'); static final Logger logger = Logger('CocoonClient');
String get commitBranch => _commitBranch ?? _readCommitBranch();
String _commitBranch;
String get commitSha => _commitSha ?? _readCommitSha(); String get commitSha => _commitSha ?? _readCommitSha();
String _commitSha; String _commitSha;
...@@ -64,18 +61,12 @@ class Cocoon { ...@@ -64,18 +61,12 @@ class Cocoon {
return _commitSha = result.stdout as String; 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. /// 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 // Skip logging on test runs
Logger.root.level = Level.ALL; Logger.root.level = Level.ALL;
Logger.root.onRecord.listen((LogRecord rec) { Logger.root.onRecord.listen((LogRecord rec) {
...@@ -83,7 +74,7 @@ class Cocoon { ...@@ -83,7 +74,7 @@ class Cocoon {
}); });
final Map<String, dynamic> status = <String, dynamic>{ final Map<String, dynamic> status = <String, dynamic>{
'CommitBranch': commitBranch, 'CommitBranch': gitBranch,
'CommitSha': commitSha, 'CommitSha': commitSha,
'BuilderName': builderName, 'BuilderName': builderName,
'NewStatus': result.succeeded ? 'Succeeded' : 'Failed', 'NewStatus': result.succeeded ? 'Succeeded' : 'Failed',
......
...@@ -27,7 +27,6 @@ void main() { ...@@ -27,7 +27,6 @@ void main() {
_processResult; _processResult;
// Expected test values. // Expected test values.
const String commitBranch = 'flutter-1.23-candidate.18';
const String commitSha = 'a4952838bf288a81d8ea11edfd4b4cd649fa94cc'; const String commitSha = 'a4952838bf288a81d8ea11edfd4b4cd649fa94cc';
const String serviceAccountTokenPath = 'test_account_file'; const String serviceAccountTokenPath = 'test_account_file';
const String serviceAccountToken = 'test_token'; const String serviceAccountToken = 'test_token';
...@@ -45,18 +44,6 @@ void main() { ...@@ -45,18 +44,6 @@ void main() {
serviceAccountFile.writeAsStringSync(serviceAccountToken); 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', () { test('returns expected commit sha', () {
_processResult = ProcessResult(1, 0, commitSha, ''); _processResult = ProcessResult(1, 0, commitSha, '');
cocoon = Cocoon( cocoon = Cocoon(
...@@ -78,7 +65,6 @@ void main() { ...@@ -78,7 +65,6 @@ void main() {
processRunSync: runSyncStub, processRunSync: runSyncStub,
); );
expect(() => cocoon.commitBranch, throwsA(isA<CocoonException>()));
expect(() => cocoon.commitSha, throwsA(isA<CocoonException>())); expect(() => cocoon.commitSha, throwsA(isA<CocoonException>()));
}); });
...@@ -93,7 +79,7 @@ void main() { ...@@ -93,7 +79,7 @@ void main() {
final TaskResult result = TaskResult.success(<String, dynamic>{}); final TaskResult result = TaskResult.success(<String, dynamic>{});
// This should not throw an error. // 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 { test('throws client exception on non-200 responses', () async {
...@@ -106,7 +92,20 @@ void main() { ...@@ -106,7 +92,20 @@ void main() {
); );
final TaskResult result = TaskResult.success(<String, dynamic>{}); 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>()));
}); });
}); });
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment