diff --git a/packages/shorebird_cli/lib/src/code_push_client_wrapper.dart b/packages/shorebird_cli/lib/src/code_push_client_wrapper.dart index 108850ec..9f2430ab 100644 --- a/packages/shorebird_cli/lib/src/code_push_client_wrapper.dart +++ b/packages/shorebird_cli/lib/src/code_push_client_wrapper.dart @@ -129,31 +129,16 @@ This app may not exist or you may not have permission to view it.''', } } - /// Exits if [platform] release artifacts already exist for an - /// [existingRelease]. - Future ensureReleaseHasNoArtifacts({ - required String appId, - required Release existingRelease, + /// Prints an error message and exits with code 70 if [release] is in an + /// active state for [platform]. + void ensureReleaseIsNotActive({ + required Release release, required ReleasePlatform platform, - }) async { - logger.detail('Verifying ability to release'); - - final artifacts = await codePushClient.getReleaseArtifacts( - appId: appId, - releaseId: existingRelease.id, - platform: platform, - ); - - logger.detail( - ''' -Artifacts for release:${existingRelease.version} platform:$platform - $artifacts''', - ); - - if (artifacts.isNotEmpty) { + }) { + if (release.platformStatuses[platform] == ReleaseStatus.active) { logger.err( ''' -It looks like you have an existing ${platform.name} release for version ${lightCyan.wrap(existingRelease.version)}. +It looks like you have an existing ${platform.name} release for version ${lightCyan.wrap(release.version)}. Please bump your version number and try again.''', ); exit(ExitCode.software.code); diff --git a/packages/shorebird_cli/lib/src/commands/release/release_aar_command.dart b/packages/shorebird_cli/lib/src/commands/release/release_aar_command.dart index c6d2bc8e..5dda06ca 100644 --- a/packages/shorebird_cli/lib/src/commands/release/release_aar_command.dart +++ b/packages/shorebird_cli/lib/src/commands/release/release_aar_command.dart @@ -102,9 +102,8 @@ make smaller updates to your app. releaseVersion: releaseVersion, ); if (existingRelease != null) { - await codePushClientWrapper.ensureReleaseHasNoArtifacts( - appId: app.appId, - existingRelease: existingRelease, + codePushClientWrapper.ensureReleaseIsNotActive( + release: existingRelease, platform: platform, ); } diff --git a/packages/shorebird_cli/lib/src/commands/release/release_android_command.dart b/packages/shorebird_cli/lib/src/commands/release/release_android_command.dart index 082dc2a1..67eea595 100644 --- a/packages/shorebird_cli/lib/src/commands/release/release_android_command.dart +++ b/packages/shorebird_cli/lib/src/commands/release/release_android_command.dart @@ -122,9 +122,8 @@ make smaller updates to your app. ); if (existingRelease != null) { - await codePushClientWrapper.ensureReleaseHasNoArtifacts( - appId: app.appId, - existingRelease: existingRelease, + codePushClientWrapper.ensureReleaseIsNotActive( + release: existingRelease, platform: platform, ); } diff --git a/packages/shorebird_cli/lib/src/commands/release/release_ios_command.dart b/packages/shorebird_cli/lib/src/commands/release/release_ios_command.dart index 445a25cc..f4ba4439 100644 --- a/packages/shorebird_cli/lib/src/commands/release/release_ios_command.dart +++ b/packages/shorebird_cli/lib/src/commands/release/release_ios_command.dart @@ -126,9 +126,8 @@ make smaller updates to your app. releaseVersion: releaseVersion, ); if (existingRelease != null) { - await codePushClientWrapper.ensureReleaseHasNoArtifacts( - appId: app.appId, - existingRelease: existingRelease, + codePushClientWrapper.ensureReleaseIsNotActive( + release: existingRelease, platform: platform, ); } diff --git a/packages/shorebird_cli/test/src/code_push_client_wrapper_test.dart b/packages/shorebird_cli/test/src/code_push_client_wrapper_test.dart index 302df769..c2dd6359 100644 --- a/packages/shorebird_cli/test/src/code_push_client_wrapper_test.dart +++ b/packages/shorebird_cli/test/src/code_push_client_wrapper_test.dart @@ -392,24 +392,23 @@ void main() { }); group('release', () { - group('ensureReleaseHasNoArtifacts', () { - const appId = 'test-app-id'; + group('ensureReleaseIsIsNotActive', () { test( - '''exits with code 70 if release artifacts exist for the given release and platform''', - () async { - when( - () => codePushClient.getReleaseArtifacts( - appId: any(named: 'appId'), - releaseId: any(named: 'releaseId'), - platform: any(named: 'platform'), - ), - ).thenAnswer((_) async => [releaseArtifact]); - - await expectLater( - runWithOverrides( - () async => codePushClientWrapper.ensureReleaseHasNoArtifacts( - appId: appId, - existingRelease: release, + '''exits with code 70 if release is in an active state for the given platform''', + () { + expect( + () => runWithOverrides( + () => codePushClientWrapper.ensureReleaseIsNotActive( + release: const Release( + id: releaseId, + appId: appId, + version: releaseVersion, + flutterRevision: flutterRevision, + displayName: displayName, + platformStatuses: { + releasePlatform: ReleaseStatus.active, + }, + ), platform: releasePlatform, ), ), @@ -427,21 +426,41 @@ Please bump your version number and try again.''', ); test( - '''completes without error if release artifacts exist for the given release and platform''', + '''completes without error if release has no status for the given platform''', () async { - when( - () => codePushClient.getReleaseArtifacts( - appId: any(named: 'appId'), - releaseId: any(named: 'releaseId'), - platform: any(named: 'platform'), - ), - ).thenAnswer((_) async => []); - await expectLater( runWithOverrides( - () => codePushClientWrapper.ensureReleaseHasNoArtifacts( - appId: appId, - existingRelease: release, + () async => codePushClientWrapper.ensureReleaseIsNotActive( + release: const Release( + id: releaseId, + appId: appId, + version: releaseVersion, + flutterRevision: flutterRevision, + displayName: displayName, + platformStatuses: {}, + ), + platform: releasePlatform, + ), + ), + completes, + ); + }, + ); + + test( + '''completes without error if release has draft status for the given platform''', + () async { + await expectLater( + runWithOverrides( + () async => codePushClientWrapper.ensureReleaseIsNotActive( + release: const Release( + id: releaseId, + appId: appId, + version: releaseVersion, + flutterRevision: flutterRevision, + displayName: displayName, + platformStatuses: {releasePlatform: ReleaseStatus.draft}, + ), platform: releasePlatform, ), ), diff --git a/packages/shorebird_cli/test/src/commands/release/release_aar_command_test.dart b/packages/shorebird_cli/test/src/commands/release/release_aar_command_test.dart index 33139beb..2dbd4855 100644 --- a/packages/shorebird_cli/test/src/commands/release/release_aar_command_test.dart +++ b/packages/shorebird_cli/test/src/commands/release/release_aar_command_test.dart @@ -246,9 +246,8 @@ flutter: ), ).thenAnswer((_) async => null); when( - () => codePushClientWrapper.ensureReleaseHasNoArtifacts( - appId: any(named: 'appId'), - existingRelease: any(named: 'existingRelease'), + () => codePushClientWrapper.ensureReleaseIsNotActive( + release: any(named: 'release'), platform: any(named: 'platform'), ), ).thenAnswer((_) async => {}); diff --git a/packages/shorebird_cli/test/src/commands/release/release_android_command_test.dart b/packages/shorebird_cli/test/src/commands/release/release_android_command_test.dart index e9fc65ef..77fb7b79 100644 --- a/packages/shorebird_cli/test/src/commands/release/release_android_command_test.dart +++ b/packages/shorebird_cli/test/src/commands/release/release_android_command_test.dart @@ -215,9 +215,8 @@ flutter: ), ).thenAnswer((_) async => null); when( - () => codePushClientWrapper.ensureReleaseHasNoArtifacts( - appId: any(named: 'appId'), - existingRelease: any(named: 'existingRelease'), + () => codePushClientWrapper.ensureReleaseIsNotActive( + release: any(named: 'release'), platform: any(named: 'platform'), ), ).thenAnswer((_) async => {}); diff --git a/packages/shorebird_cli/test/src/commands/release/release_ios_command_test.dart b/packages/shorebird_cli/test/src/commands/release/release_ios_command_test.dart index 7da11146..87365902 100644 --- a/packages/shorebird_cli/test/src/commands/release/release_ios_command_test.dart +++ b/packages/shorebird_cli/test/src/commands/release/release_ios_command_test.dart @@ -214,9 +214,8 @@ flutter: ), ).thenAnswer((_) async => null); when( - () => codePushClientWrapper.ensureReleaseHasNoArtifacts( - appId: any(named: 'appId'), - existingRelease: any(named: 'existingRelease'), + () => codePushClientWrapper.ensureReleaseIsNotActive( + release: any(named: 'release'), platform: any(named: 'platform'), ), ).thenAnswer((_) async => {});