From 06fedbc4715bd287fcaa1667a948dccb77d9de43 Mon Sep 17 00:00:00 2001 From: Erick Date: Wed, 19 Jun 2024 11:14:22 -0300 Subject: [PATCH] fix: accurate message when patching a release that doesn't contains the platform (#2268) --- .../lib/src/commands/patch/patch_command.dart | 16 +++++++++ .../commands/patch/patch_command_test.dart | 35 +++++++++++++++++++ 2 files changed, 51 insertions(+) diff --git a/packages/shorebird_cli/lib/src/commands/patch/patch_command.dart b/packages/shorebird_cli/lib/src/commands/patch/patch_command.dart index 50aa2fd8..be72d883 100644 --- a/packages/shorebird_cli/lib/src/commands/patch/patch_command.dart +++ b/packages/shorebird_cli/lib/src/commands/patch/patch_command.dart @@ -237,6 +237,7 @@ NOTE: this is ${styleBold.wrap('not')} recommended. Asset changes cannot be incl ); } + assertReleaseContainsPlatform(release: release, patcher: patcher); assertReleaseIsActive(release: release, patcher: patcher); try { @@ -323,6 +324,21 @@ NOTE: this is ${styleBold.wrap('not')} recommended. Asset changes cannot be incl ); } + void assertReleaseContainsPlatform({ + required Release release, + required Patcher patcher, + }) { + final releasePlatform = patcher.releaseType.releasePlatform; + final contains = release.platformStatuses.containsKey(releasePlatform); + if (!contains) { + final platformName = releasePlatform.name; + logger.err( + '''No release exists for $platformName in release version ${release.version}. Please run shorebird release $platformName to create one.''', + ); + throw ProcessExit(ExitCode.software.code); + } + } + void assertReleaseIsActive({ required Release release, required Patcher patcher, diff --git a/packages/shorebird_cli/test/src/commands/patch/patch_command_test.dart b/packages/shorebird_cli/test/src/commands/patch/patch_command_test.dart index dcc3157e..bcaa1bd9 100644 --- a/packages/shorebird_cli/test/src/commands/patch/patch_command_test.dart +++ b/packages/shorebird_cli/test/src/commands/patch/patch_command_test.dart @@ -853,6 +853,41 @@ Please re-run the release command for this version or create a new release.''', }); }); + group('when the target release does not contain the provided platform', () { + setUp(() { + when( + () => codePushClientWrapper.getRelease( + appId: any(named: 'appId'), + releaseVersion: any(named: 'releaseVersion'), + ), + ).thenAnswer( + (_) async => Release( + id: 0, + appId: appId, + version: releaseVersion, + flutterRevision: flutterRevision, + displayName: '1.2.3+1', + platformStatuses: {ReleasePlatform.ios: ReleaseStatus.active}, + createdAt: DateTime(2023), + updatedAt: DateTime(2023), + ), + ); + }); + + test('logs error and exits with code 70', () async { + await expectLater( + () => runWithOverrides(command.run), + exitsWithCode(ExitCode.software), + ); + + verify( + () => logger.err( + '''No release exists for android in release version ${release.version}. Please run shorebird release android to create one.''', + ), + ).called(1); + }); + }); + group('when primary release artifact fails to download', () { final error = Exception('Failed to download primary release artifact.');