Skip to content

Commit f2f7a4e

Browse files
committed
Update
1 parent 0d4ba97 commit f2f7a4e

File tree

2 files changed

+93
-12
lines changed

2 files changed

+93
-12
lines changed

lib/sentry_dart_plugin.dart

Lines changed: 49 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,8 @@ class SentryDartPlugin {
6060
await _executeFinalizeRelease(release);
6161
} on ExitError catch (e) {
6262
return e.code;
63+
} finally {
64+
Log.tasksSummary();
6365
}
6466
return 0;
6567
}
@@ -187,13 +189,27 @@ class SentryDartPlugin {
187189
}
188190

189191
Future<void> _executeNewRelease(String release) async {
190-
await _executeAndLog('Failed to create a new release',
192+
final taskName = 'create new release: $release';
193+
Log.startingTask(taskName);
194+
final isSuccess = await _executeAndLog('Failed to create a new release',
191195
[..._releasesCliParams(), 'new', release]);
196+
if (isSuccess) {
197+
Log.taskCompleted(taskName);
198+
} else {
199+
Log.taskSkipped(taskName);
200+
}
192201
}
193202

194203
Future<void> _executeFinalizeRelease(String release) async {
195-
await _executeAndLog('Failed to finalize the new release',
204+
final taskName = 'finalize new release: $release';
205+
Log.startingTask(taskName);
206+
final isSuccess = await _executeAndLog('Failed to finalize the new release',
196207
[..._releasesCliParams(), 'finalize', release]);
208+
if (isSuccess) {
209+
Log.taskCompleted(taskName);
210+
} else {
211+
Log.taskSkipped(taskName);
212+
}
197213
}
198214

199215
Future<void> _executeSetCommits(String release) async {
@@ -214,7 +230,14 @@ class SentryDartPlugin {
214230
params.add('--ignore-missing');
215231
}
216232

217-
await _executeAndLog('Failed to set commits', params);
233+
final taskName = 'set commits';
234+
Log.startingTask(taskName);
235+
final isSuccess = await _executeAndLog('Failed to set commits', params);
236+
if (isSuccess) {
237+
Log.taskCompleted(taskName);
238+
} else {
239+
Log.taskSkipped(taskName);
240+
}
218241
}
219242

220243
Future<List<String>> _findAllJsFilePaths() async {
@@ -280,7 +303,7 @@ class SentryDartPlugin {
280303
return await _executeAndLog('Failed to inject debug ids', params);
281304
}
282305

283-
Future<void> _uploadSourceMaps(
306+
Future<bool> _uploadSourceMaps(
284307
{required String release, required String? dist}) async {
285308
List<String> params = [];
286309

@@ -325,7 +348,7 @@ class SentryDartPlugin {
325348

326349
params.addAll(_baseCliParams());
327350

328-
await _executeAndLog('Failed to sources files', params);
351+
return await _executeAndLog('Failed to sources files', params);
329352
}
330353

331354
/// Extracts and returns a list of path prefixes to strip from source maps.
@@ -417,7 +440,7 @@ class SentryDartPlugin {
417440
}
418441
}
419442

420-
const taskName = 'uploading source maps';
443+
const taskName = 'uploading source maps (legacy)';
421444
Log.startingTask(taskName);
422445

423446
final params = <String>[];
@@ -440,7 +463,13 @@ class SentryDartPlugin {
440463
_addWait(releaseJsFilesParams);
441464
_addUrlPrefix(releaseJsFilesParams);
442465

443-
await _executeAndLog('Failed to upload source maps', releaseJsFilesParams);
466+
final isSourcemapsUploadSuccessful = await _executeAndLog(
467+
'Failed to upload source maps', releaseJsFilesParams);
468+
if (!isSourcemapsUploadSuccessful) {
469+
Log.taskSkipped(taskName);
470+
// no need to continue if it was a failure
471+
return;
472+
}
444473

445474
if (_configuration.uploadSources) {
446475
// upload source files (dart)
@@ -457,8 +486,13 @@ class SentryDartPlugin {
457486

458487
_addWait(releaseDartFilesParams);
459488

460-
await _executeAndLog(
489+
final isSourcesUploadSuccessful = await _executeAndLog(
461490
'Failed to upload source files', releaseDartFilesParams);
491+
if (!isSourcesUploadSuccessful) {
492+
Log.taskSkipped(taskName);
493+
// no need to continue if it was a failure
494+
return;
495+
}
462496
}
463497

464498
Log.taskCompleted(taskName);
@@ -471,12 +505,16 @@ class SentryDartPlugin {
471505

472506
final debugIdInjectionSucceeded = await _injectDebugIds();
473507
if (debugIdInjectionSucceeded) {
474-
await _uploadSourceMaps(release: release, dist: dist);
508+
final isSuccess = await _uploadSourceMaps(release: release, dist: dist);
509+
if (isSuccess) {
510+
Log.taskCompleted(taskName);
511+
} else {
512+
Log.taskSkipped(taskName);
513+
}
475514
} else {
476515
Log.warn('Skipping source maps upload. Could not inject debug ids.');
516+
Log.taskSkipped(taskName);
477517
}
478-
479-
Log.taskCompleted(taskName);
480518
}
481519

482520
void _addUrlPrefix(List<String> releaseDartFilesParams) {

lib/src/utils/log.dart

Lines changed: 44 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ class Log {
3535
static final _gray09 = AnsiPen()..gray(level: 0.9);
3636
static int _numberOfTasksCompleted = 0;
3737
static int _lastMessageLength = 0;
38+
static Map<String, String> tasks = {};
3839

3940
/// Log with colors.
4041
Log();
@@ -81,6 +82,7 @@ class Log {
8182

8283
/// Info log on a new task
8384
static void startingTask(String name) {
85+
tasks[name] = 'start';
8486
final emptyStr = _getlastMessageemptyStringLength();
8587
_lastMessageLength = name.length;
8688
_renderProgressBar();
@@ -89,9 +91,10 @@ class Log {
8991

9092
/// Info log on a completed task
9193
static void taskCompleted(String name) {
94+
tasks[name] = 'completed';
9295
_numberOfTasksCompleted++;
9396
stdout.writeCharCode(13);
94-
stdout.write(_green(' '));
97+
stdout.write(_green(' '));
9598
stdout.writeln(
9699
'$name ');
97100
if (_numberOfTasksCompleted >= _numberOfAllTasks) {
@@ -101,6 +104,46 @@ class Log {
101104
}
102105
}
103106

107+
/// Info log on a skipped task.
108+
///
109+
/// e.g when some operations implicitly trigger related tasks for example,
110+
/// uploading debug symbols for a Windows build may also queue a sourcemap upload
111+
/// if the sourcemaps upload config is set up
112+
static void taskSkipped(String name) {
113+
tasks[name] = 'skipped';
114+
stdout.writeCharCode(13);
115+
stdout.write(_green('⏭ '));
116+
stdout.writeln(
117+
'$name ');
118+
}
119+
120+
/// Logs a summary of executed tasks
121+
static void tasksSummary() {
122+
stdout.writeln();
123+
stdout.writeln(_gray09('Tasks Summary:'));
124+
var completedCount = tasks.values.where((s) => s == 'completed').length;
125+
var skippedCount = tasks.values.where((s) => s == 'skipped').length;
126+
var startedCount = tasks.values.where((s) => s == 'started').length;
127+
128+
stdout.writeln(_green('✔ Completed: $completedCount'));
129+
stdout.writeln(_yellow('⏭ Skipped: $skippedCount'));
130+
stdout.writeln();
131+
132+
tasks.forEach((name, status) {
133+
if (status == 'completed' || status == 'skipped') {
134+
String icon = status == 'completed' ? '✔' : '⏭';
135+
AnsiPen pen = status == 'completed' ? _green : _yellow;
136+
stdout.writeln(pen('$icon $name'));
137+
} else if (status == 'started') {
138+
// This case is very unlikely to happen but let's still log it if it does
139+
AnsiPen pen = _yellow;
140+
stdout
141+
.writeln(pen('$startedCount tasks were started but not finished.'));
142+
}
143+
});
144+
stdout.writeln();
145+
}
146+
104147
static String _getlastMessageemptyStringLength() {
105148
var emptyStr = '';
106149
for (var i = 0; i < _lastMessageLength + 8; i++) {

0 commit comments

Comments
 (0)