Skip to content

Commit 86c9362

Browse files
authored
feat: add verbose logging to shorebird_tests for CI debugging (#107)
Stream subprocess output in real time when VERBOSE is set, and dump stdout/stderr on failure. This helps diagnose flaky timeout failures in CI where buffered output is lost when the test times out.
1 parent c2c56ab commit 86c9362

2 files changed

Lines changed: 25 additions & 9 deletions

File tree

.github/workflows/shorebird_ci.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,3 +138,6 @@ jobs:
138138
# Quick sanity check that Android builds work on macOS too
139139
run: dart test test/android_test.dart --name "can build an apk"
140140
working-directory: packages/shorebird_tests
141+
env:
142+
# Enables streaming subprocess output for debugging timeouts.
143+
VERBOSE: "1"

packages/shorebird_tests/test/shorebird_tests.dart

Lines changed: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,16 @@ File get _flutterBinaryFile => File(
2323
),
2424
);
2525

26+
/// Whether to print line-by-line subprocess output.
27+
///
28+
/// Set the `VERBOSE` environment variable to enable streaming output,
29+
/// which is useful for debugging timeouts in CI.
30+
final bool _verbose = Platform.environment.containsKey('VERBOSE');
31+
2632
/// Runs a flutter command using the correct binary ([_flutterBinaryFile]) with the given arguments.
2733
///
28-
/// Streams stdout and stderr to the test output in real time so that
29-
/// CI logs show progress even if the process hangs or times out.
34+
/// Streams stdout and stderr to the test output in real time when [_verbose]
35+
/// is true, so CI logs show progress even if the process hangs or times out.
3036
Future<ProcessResult> _runFlutterCommand(
3137
List<String> arguments, {
3238
required Directory workingDirectory,
@@ -51,19 +57,22 @@ Future<ProcessResult> _runFlutterCommand(
5157

5258
process.stdout.transform(utf8.decoder).listen((String data) {
5359
stdoutBuffer.write(data);
54-
// Print each line with a prefix so it's easy to identify in CI logs.
55-
for (final String line in data.split('\n')) {
56-
if (line.isNotEmpty) {
57-
print(' [$command] $line');
60+
if (_verbose) {
61+
for (final String line in data.split('\n')) {
62+
if (line.isNotEmpty) {
63+
print(' [$command] $line');
64+
}
5865
}
5966
}
6067
});
6168

6269
process.stderr.transform(utf8.decoder).listen((String data) {
6370
stderrBuffer.write(data);
64-
for (final String line in data.split('\n')) {
65-
if (line.isNotEmpty) {
66-
print(' [$command] (stderr) $line');
71+
if (_verbose) {
72+
for (final String line in data.split('\n')) {
73+
if (line.isNotEmpty) {
74+
print(' [$command] (stderr) $line');
75+
}
6776
}
6877
}
6978
});
@@ -72,6 +81,10 @@ Future<ProcessResult> _runFlutterCommand(
7281
stopwatch.stop();
7382
print('[$command] completed in ${stopwatch.elapsed} '
7483
'(exit code $exitCode)');
84+
if (exitCode != 0 && !_verbose) {
85+
print('[$command] stdout:\n$stdoutBuffer');
86+
print('[$command] stderr:\n$stderrBuffer');
87+
}
7588

7689
return ProcessResult(
7790
process.pid,

0 commit comments

Comments
 (0)