diff --git a/packages/shorebird_cli/lib/src/commands/release/android_releaser.dart b/packages/shorebird_cli/lib/src/commands/release/android_releaser.dart index a4f1e66d0..3b5796800 100644 --- a/packages/shorebird_cli/lib/src/commands/release/android_releaser.dart +++ b/packages/shorebird_cli/lib/src/commands/release/android_releaser.dart @@ -61,8 +61,6 @@ class AndroidReleaser extends Releaser { @override Future assertArgsAreValid() async { - argResults.assertAbsentOrValidPublicKey(); - if (argResults.wasParsed('release-version')) { logger.err( ''' diff --git a/packages/shorebird_cli/lib/src/commands/release/ios_releaser.dart b/packages/shorebird_cli/lib/src/commands/release/ios_releaser.dart index 18a25046d..c7a79edad 100644 --- a/packages/shorebird_cli/lib/src/commands/release/ios_releaser.dart +++ b/packages/shorebird_cli/lib/src/commands/release/ios_releaser.dart @@ -42,8 +42,6 @@ class IosReleaser extends Releaser { @override Future assertArgsAreValid() async { - argResults.assertAbsentOrValidPublicKey(); - if (argResults.wasParsed('release-version')) { logger.err( ''' diff --git a/packages/shorebird_cli/lib/src/commands/release/release_command.dart b/packages/shorebird_cli/lib/src/commands/release/release_command.dart index 1bb8851ff..4ec3245f0 100644 --- a/packages/shorebird_cli/lib/src/commands/release/release_command.dart +++ b/packages/shorebird_cli/lib/src/commands/release/release_command.dart @@ -248,6 +248,7 @@ of the iOS app that is using this module. (aar and ios-framework only)''', @visibleForTesting Future createRelease(Releaser releaser) async { await releaser.assertPreconditions(); + await assertArgsAreValid(); await releaser.assertArgsAreValid(); await shorebirdValidator.validateFlavors(flavorArg: flavor); @@ -327,6 +328,11 @@ of the iOS app that is using this module. (aar and ios-framework only)''', ); } + /// Validates arguments that are common to all release types. + Future assertArgsAreValid() async { + results.assertAbsentOrValidPublicKey(); + } + /// Determines which Flutter version to use for the release. This will be /// either the version specified by the user or the version provided by /// [shorebirdEnv]. Will exit with [ExitCode.software] if the version diff --git a/packages/shorebird_cli/lib/src/commands/release/windows_releaser.dart b/packages/shorebird_cli/lib/src/commands/release/windows_releaser.dart index a92d4f7da..99e8de508 100644 --- a/packages/shorebird_cli/lib/src/commands/release/windows_releaser.dart +++ b/packages/shorebird_cli/lib/src/commands/release/windows_releaser.dart @@ -37,8 +37,6 @@ class WindowsReleaser extends Releaser { @override Future assertArgsAreValid() async { - argResults.assertAbsentOrValidPublicKey(); - if (argResults.wasParsed('release-version')) { logger.err( ''' diff --git a/packages/shorebird_cli/test/src/commands/release/android_releaser_test.dart b/packages/shorebird_cli/test/src/commands/release/android_releaser_test.dart index a74c007bf..6e2f9297f 100644 --- a/packages/shorebird_cli/test/src/commands/release/android_releaser_test.dart +++ b/packages/shorebird_cli/test/src/commands/release/android_releaser_test.dart @@ -235,45 +235,6 @@ To change the version of this release, change your app's version in your pubspec ); }); }); - - group('when a public key is provided and it exists', () { - setUp(() { - when(() => argResults['artifact']).thenReturn('apk'); - final publicKeyFile = File( - p.join( - Directory.systemTemp.createTempSync().path, - 'public-key.pem', - ), - )..writeAsStringSync('public key'); - when(() => argResults[CommonArguments.publicKeyArg.name]) - .thenReturn(publicKeyFile.path); - }); - - test('returns normally', () async { - expect( - () => runWithOverrides(androidReleaser.assertArgsAreValid), - returnsNormally, - ); - }); - }); - - group('when a public key is provided but does not exist', () { - setUp(() { - when(() => argResults['artifact']).thenReturn('apk'); - when(() => argResults[CommonArguments.publicKeyArg.name]) - .thenReturn('non-existing-key.pem'); - }); - - test('logs and exits with usage err', () async { - await expectLater( - () => runWithOverrides(androidReleaser.assertArgsAreValid), - exitsWithCode(ExitCode.usage), - ); - - verify(() => logger.err('No file found at non-existing-key.pem')) - .called(1); - }); - }); }); group('buildReleaseArtifacts', () { diff --git a/packages/shorebird_cli/test/src/commands/release/ios_releaser_test.dart b/packages/shorebird_cli/test/src/commands/release/ios_releaser_test.dart index a5221212a..01f5414f3 100644 --- a/packages/shorebird_cli/test/src/commands/release/ios_releaser_test.dart +++ b/packages/shorebird_cli/test/src/commands/release/ios_releaser_test.dart @@ -278,43 +278,6 @@ To change the version of this release, change your app's version in your pubspec ); }); }); - - group('when a public key is provided and it exists', () { - setUp(() { - final publicKeyFile = File( - p.join( - Directory.systemTemp.createTempSync().path, - 'public-key.pem', - ), - )..writeAsStringSync('public key'); - when(() => argResults[CommonArguments.publicKeyArg.name]) - .thenReturn(publicKeyFile.path); - }); - - test('returns normally', () async { - expect( - () => runWithOverrides(iosReleaser.assertArgsAreValid), - returnsNormally, - ); - }); - }); - - group('when the provided public key is a nonexistent file', () { - setUp(() { - when(() => argResults[CommonArguments.publicKeyArg.name]) - .thenReturn('non-existing-key.pem'); - }); - - test('logs and exits with usage err', () async { - await expectLater( - () => runWithOverrides(iosReleaser.assertArgsAreValid), - exitsWithCode(ExitCode.usage), - ); - - verify(() => logger.err('No file found at non-existing-key.pem')) - .called(1); - }); - }); }); group('buildReleaseArtifacts', () { diff --git a/packages/shorebird_cli/test/src/commands/release/release_command_test.dart b/packages/shorebird_cli/test/src/commands/release/release_command_test.dart index ebc71fab6..7f8020b88 100644 --- a/packages/shorebird_cli/test/src/commands/release/release_command_test.dart +++ b/packages/shorebird_cli/test/src/commands/release/release_command_test.dart @@ -252,6 +252,24 @@ void main() { }); }); + group('when public key path is provided but no key exists', () { + setUp(() { + when(() => argResults[CommonArguments.publicKeyArg.name]) + .thenReturn('/path/to/nonexistent/file'); + }); + + test('exits with usage code', () async { + await expectLater( + runWithOverrides(command.run), + exitsWithCode(ExitCode.usage), + ); + + verifyNever( + () => codePushClientWrapper.getApp(appId: any(named: 'appId')), + ); + }); + }); + test('executes commands in order, completes successfully', () async { final exitCode = await runWithOverrides(command.run); expect(exitCode, equals(ExitCode.success.code)); diff --git a/packages/shorebird_cli/test/src/commands/release/windows_releaser_test.dart b/packages/shorebird_cli/test/src/commands/release/windows_releaser_test.dart index c67a89974..6ab16babb 100644 --- a/packages/shorebird_cli/test/src/commands/release/windows_releaser_test.dart +++ b/packages/shorebird_cli/test/src/commands/release/windows_releaser_test.dart @@ -151,22 +151,6 @@ To change the version of this release, change your app's version in your pubspec ).called(1); }); }); - - group('when public key is provided but file does not exist', () { - setUp(() { - when(() => argResults.wasParsed(CommonArguments.publicKeyArg.name)) - .thenReturn(true); - when(() => argResults[CommonArguments.publicKeyArg.name]) - .thenReturn('nonexistent'); - }); - - test('fails progress, exits', () async { - await expectLater( - () => runWithOverrides(releaser.assertArgsAreValid), - exitsWithCode(ExitCode.usage), - ); - }); - }); }); group('assertPreconditions', () {