Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: show progress when updating cache artifacts #2448

Merged
merged 4 commits into from
Aug 28, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 14 additions & 1 deletion packages/shorebird_cli/lib/src/cache.dart
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,8 @@
// Clear any existing artifact files.
await _delete();

final updateProgress = logger.progress('Downloading $fileName...');

final request = http.Request('GET', Uri.parse(storageUrl));
final http.StreamedResponse response;
try {
Expand All @@ -201,17 +203,27 @@
return;
}

updateProgress.fail();
throw CacheUpdateFailure(
'''Failed to download $fileName: ${response.statusCode} ${response.reasonPhrase}''',
);
}

updateProgress.complete();

final extractProgress = logger.progress('Extracting $fileName...');
final artifactDirectory = Directory(p.dirname(file.path));
await extractArtifact(response.stream, artifactDirectory.path);
try {
await extractArtifact(response.stream, artifactDirectory.path);
} catch (_) {
extractProgress.fail();

Check warning on line 219 in packages/shorebird_cli/lib/src/cache.dart

View check run for this annotation

Codecov / codecov/patch

packages/shorebird_cli/lib/src/cache.dart#L219

Added line #L219 was not covered by tests
bryanoltman marked this conversation as resolved.
Show resolved Hide resolved
rethrow;
}

final expectedChecksum = checksum;
if (expectedChecksum != null) {
if (!checksumChecker.checkFile(file, expectedChecksum)) {
extractProgress.fail();
// Delete the artifact directory, so if the download is retried, it will
// be re-downloaded.
artifactDirectory.deleteSync(recursive: true);
Expand All @@ -230,6 +242,7 @@
await result.exitCode;
}

extractProgress.complete();
_writeStampFile();
}

Expand Down
8 changes: 8 additions & 0 deletions packages/shorebird_cli/test/src/cache_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ void main() {
late ShorebirdLogger logger;
late Platform platform;
late Process chmodProcess;
late Progress progress;
late ShorebirdEnv shorebirdEnv;
late ShorebirdProcess shorebirdProcess;

Expand Down Expand Up @@ -77,6 +78,7 @@ void main() {
httpClient = MockHttpClient();
logger = MockShorebirdLogger();
platform = MockPlatform();
progress = MockProgress();
shorebirdEnv = MockShorebirdEnv();
shorebirdProcess = MockShorebirdProcess();

Expand All @@ -90,6 +92,7 @@ void main() {
(invocation.namedArguments[#outputDirectory] as Directory)
.createSync(recursive: true);
});
when(() => logger.progress(any())).thenReturn(progress);
when(
() => shorebirdEnv.shorebirdEngineRevision,
).thenReturn(shorebirdEngineRevision);
Expand Down Expand Up @@ -375,6 +378,7 @@ void main() {
late http.Client httpClient;
late ShorebirdLogger logger;
late Platform platform;
late Progress progress;
late _TestCachedArtifact cachedArtifact;

R runWithOverrides<R>(R Function() body) {
Expand All @@ -399,13 +403,17 @@ void main() {
httpClient = MockHttpClient();
logger = MockShorebirdLogger();
platform = MockPlatform();
progress = MockProgress();

when(() => httpClient.send(any())).thenAnswer(
(_) async => http.StreamedResponse(
const Stream.empty(),
HttpStatus.notFound,
),
);

when(() => logger.progress(any())).thenReturn(progress);

cachedArtifact = _TestCachedArtifact(cache: cache, platform: platform);
});

Expand Down
Loading