Unverified Commit ab9df836 authored by Hans Muller's avatar Hans Muller Committed by GitHub

Retry dev/snippets git status, deflake snippets generator (#84728)

parent 8d506c77
...@@ -21,19 +21,46 @@ const String _kTemplateOption = 'template'; ...@@ -21,19 +21,46 @@ const String _kTemplateOption = 'template';
const String _kTypeOption = 'type'; const String _kTypeOption = 'type';
const String _kShowDartPad = 'dartpad'; const String _kShowDartPad = 'dartpad';
class GitStatusFailed implements Exception {
GitStatusFailed(this.gitResult);
final ProcessResult gitResult;
@override
String toString() => 'git status exited with a non-zero exit code: ${gitResult.exitCode}:\n${gitResult.stderr}\n${gitResult.stdout}';
}
String getChannelName() { String getChannelName() {
final RegExp gitBranchRegexp = RegExp(r'^## (?<branch>.*)'); final RegExp gitBranchRegexp = RegExp(r'^## (?<branch>.*)');
final ProcessResult gitResult = Process.runSync('git', <String>['status', '-b', '--porcelain'], environment: <String, String>{ final ProcessResult gitResult = Process.runSync('git', <String>['status', '-b', '--porcelain'],
'GIT_TRACE': '2', environment: <String, String>{
'GIT_TRACE_SETUP': '2', 'GIT_TRACE': '2',
}, includeParentEnvironment: true); 'GIT_TRACE_SETUP': '2'
if (gitResult.exitCode != 0) },
throw 'git status exit with non-zero exit code: ${gitResult.exitCode}: ${gitResult.stderr}'; includeParentEnvironment: true
final RegExpMatch? gitBranchMatch = gitBranchRegexp.firstMatch( );
(gitResult.stdout as String).trim().split('\n').first); if (gitResult.exitCode != 0) {
throw GitStatusFailed(gitResult);
}
final RegExpMatch? gitBranchMatch = gitBranchRegexp.firstMatch((gitResult.stdout as String).trim().split('\n').first);
return gitBranchMatch == null ? '<unknown>' : gitBranchMatch.namedGroup('branch')!.split('...').first; return gitBranchMatch == null ? '<unknown>' : gitBranchMatch.namedGroup('branch')!.split('...').first;
} }
// This is a hack to workaround the fact that git status inexplicably fails
// (random non-zero error code) about 2% of the time.
String getChannelNameWithRetries() {
int retryCount = 0;
while(retryCount < 2) {
try {
return getChannelName();
} on GitStatusFailed catch (e) {
retryCount += 1;
stderr.write('git status failed, retrying ($retryCount)\nError report:\n$e');
}
}
return getChannelName();
}
/// Generates snippet dartdoc output for a given input, and creates any sample /// Generates snippet dartdoc output for a given input, and creates any sample
/// applications needed by the snippet. /// applications needed by the snippet.
void main(List<String> argList) { void main(List<String> argList) {
...@@ -185,7 +212,7 @@ void main(List<String> argList) { ...@@ -185,7 +212,7 @@ void main(List<String> argList) {
? int.tryParse(environment['SOURCE_LINE']!) ? int.tryParse(environment['SOURCE_LINE']!)
: null, : null,
'id': id.join('.'), 'id': id.join('.'),
'channel': getChannelName(), 'channel': getChannelNameWithRetries(),
'serial': serial, 'serial': serial,
'package': packageName, 'package': packageName,
'library': libraryName, 'library': libraryName,
......
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