From f91b0f2569076f68489a975a3fe874908c43caac Mon Sep 17 00:00:00 2001 From: Bryan Oltman Date: Thu, 18 Jan 2024 15:41:16 -0500 Subject: [PATCH] fix(shorebird_cli): handle renamed Runner (#1649) --- .../src/commands/patch/patch_ios_command.dart | 12 +++--- .../commands/release/release_ios_command.dart | 11 ++++-- .../lib/src/shorebird_artifact_mixin.dart | 9 +---- .../patch/patch_ios_command_test.dart | 39 ++++++++++++++++++- 4 files changed, 54 insertions(+), 17 deletions(-) diff --git a/packages/shorebird_cli/lib/src/commands/patch/patch_ios_command.dart b/packages/shorebird_cli/lib/src/commands/patch/patch_ios_command.dart index bbb780d4..43ec0815 100644 --- a/packages/shorebird_cli/lib/src/commands/patch/patch_ios_command.dart +++ b/packages/shorebird_cli/lib/src/commands/patch/patch_ios_command.dart @@ -298,13 +298,15 @@ Current Flutter Revision: $originalFlutterRevision return tempDir.path; }); unzipProgress.complete(); - + final appDirectory = + getAppDirectory(xcarchiveDirectory: Directory(releaseXcarchivePath)); + if (appDirectory == null) { + logger.err('Unable to find release artifact .app directory'); + return ExitCode.software.code; + } final releaseArtifactFile = File( p.join( - releaseXcarchivePath, - 'Products', - 'Applications', - 'Runner.app', + appDirectory.path, 'Frameworks', 'App.framework', 'App', 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 6292ecfc..ae00bdb6 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 @@ -177,16 +177,19 @@ make smaller updates to your app. buildProgress.complete(); - final archivePath = getXcarchiveDirectory()?.path; - if (archivePath == null) { + final archiveDirectory = getXcarchiveDirectory(); + if (archiveDirectory == null) { logger.err('Unable to find .xcarchive directory'); return ExitCode.software.code; } - final runnerPath = getAppDirectory()?.path; - if (runnerPath == null) { + final archivePath = archiveDirectory.path; + + final appDirectory = getAppDirectory(xcarchiveDirectory: archiveDirectory); + if (appDirectory == null) { logger.err('Unable to find .app directory'); return ExitCode.software.code; } + final runnerPath = appDirectory.path; final plistFile = File(p.join(archivePath, 'Info.plist')); if (!plistFile.existsSync()) { diff --git a/packages/shorebird_cli/lib/src/shorebird_artifact_mixin.dart b/packages/shorebird_cli/lib/src/shorebird_artifact_mixin.dart index 93eb4a23..ac0237c6 100644 --- a/packages/shorebird_cli/lib/src/shorebird_artifact_mixin.dart +++ b/packages/shorebird_cli/lib/src/shorebird_artifact_mixin.dart @@ -93,15 +93,10 @@ mixin ShorebirdArtifactMixin on ShorebirdCommand { /// Returns the .app directory generated by `flutter build ipa`. This was /// traditionally named `Runner.app`, but can now be renamed. - Directory? getAppDirectory() { - final archiveDirectory = getXcarchiveDirectory(); - if (archiveDirectory == null) { - return null; - } - + Directory? getAppDirectory({required Directory xcarchiveDirectory}) { final applicationsDirectory = Directory( p.join( - archiveDirectory.path, + xcarchiveDirectory.path, 'Products', 'Applications', ), diff --git a/packages/shorebird_cli/test/src/commands/patch/patch_ios_command_test.dart b/packages/shorebird_cli/test/src/commands/patch/patch_ios_command_test.dart index 43ca538e..19b3b984 100644 --- a/packages/shorebird_cli/test/src/commands/patch/patch_ios_command_test.dart +++ b/packages/shorebird_cli/test/src/commands/patch/patch_ios_command_test.dart @@ -349,7 +349,21 @@ flutter: zipFile: any(named: 'zipFile'), outputDirectory: any(named: 'outputDirectory'), ), - ).thenAnswer((_) async {}); + ).thenAnswer((invocation) async { + final outputDirectory = + invocation.namedArguments[#outputDirectory] as Directory; + File( + p.join( + outputDirectory.path, + 'Products', + 'Applications', + 'App.app', + 'Frameworks', + 'App.framework', + 'App', + ), + ).createSync(recursive: true); + }); when( () => artifactManager.createDiff( releaseArtifactPath: any(named: 'releaseArtifactPath'), @@ -906,6 +920,29 @@ Please re-run the release command for this version or create a new release.'''), ).called(1); }); + group('when release artifact fails to extract', () { + setUp(() { + setUpProjectRoot(); + setUpProjectRootArtifacts(); + + when( + () => artifactManager.extractZip( + zipFile: any(named: 'zipFile'), + outputDirectory: any(named: 'outputDirectory'), + ), + ).thenAnswer((invocation) async {}); + }); + + test('prints error message and exits with code 70', () async { + final exitCode = await runWithOverrides(command.run); + + expect(exitCode, equals(ExitCode.software.code)); + verify( + () => logger.err('Unable to find release artifact .app directory'), + ).called(1); + }); + }); + test( '''exits with code 70 if zipAndConfirmUnpatchableDiffsIfNecessary throws UnpatchableChangeException''', () async {