appendBuildHistory method
Appends a build record to the project-local history file, keeping only
the most recent _maxHistoryEntries. Newest entries are stored first.
Implementation
Future<void> appendBuildHistory({
required String client,
required String platform,
required String type,
required String? version,
required bool success,
required Duration duration,
String? errorMessage,
String? artifactPath,
}) async {
final entry = {
'timestamp': DateTime.now().toIso8601String(),
'client': client,
'platform': platform,
'type': type,
'version': version,
'success': success,
'durationSeconds': duration.inSeconds,
if (errorMessage != null) 'error': errorMessage,
if (artifactPath != null) 'artifact': artifactPath,
};
try {
final history = await loadBuildHistory();
history.insert(0, entry);
if (history.length > _maxHistoryEntries) {
history.removeRange(_maxHistoryEntries, history.length);
}
await File(_historyFilePath).writeAsString(
const JsonEncoder.withIndent(' ').convert(history),
);
} catch (e) {
// Never let history recording break a build.
Logger.warning('Failed to record build history: $e');
}
}