diff --git a/packages/shorebird_cli/lib/src/commands/release/ios_framework_releaser.dart b/packages/shorebird_cli/lib/src/commands/release/ios_framework_releaser.dart index 6cd516e0..ad1c39cb 100644 --- a/packages/shorebird_cli/lib/src/commands/release/ios_framework_releaser.dart +++ b/packages/shorebird_cli/lib/src/commands/release/ios_framework_releaser.dart @@ -84,6 +84,15 @@ For more information see: ${supportedFlutterVersionsUrl.toLink()}''', Future buildReleaseArtifacts() async { final flutterVersionString = await shorebirdFlutter.getVersionAndRevision(); + // Delete the Shorebird supplement directory if it exists. + // This is to ensure that we don't accidentally upload stale artifacts + // when building with older versions of Flutter. + final shorebirdSupplementDir = + artifactManager.getIosReleaseSupplementDirectory(); + if (shorebirdSupplementDir?.existsSync() ?? false) { + shorebirdSupplementDir!.deleteSync(recursive: true); + } + final buildProgress = logger.progress( 'Building iOS framework with Flutter $flutterVersionString', ); 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 9d64a7b0..e12aedbf 100644 --- a/packages/shorebird_cli/lib/src/commands/release/ios_releaser.dart +++ b/packages/shorebird_cli/lib/src/commands/release/ios_releaser.dart @@ -106,6 +106,15 @@ For more information see: ${supportedFlutterVersionsUrl.toLink()}''', ); } + // Delete the Shorebird supplement directory if it exists. + // This is to ensure that we don't accidentally upload stale artifacts + // when building with older versions of Flutter. + final shorebirdSupplementDir = + artifactManager.getIosReleaseSupplementDirectory(); + if (shorebirdSupplementDir?.existsSync() ?? false) { + shorebirdSupplementDir!.deleteSync(recursive: true); + } + final flutterVersionString = await shorebirdFlutter.getVersionAndRevision(); final buildProgress = logger.detailProgress( 'Building app bundle with Flutter $flutterVersionString', diff --git a/packages/shorebird_cli/test/src/commands/release/ios_framework_releaser_test.dart b/packages/shorebird_cli/test/src/commands/release/ios_framework_releaser_test.dart index b81b537f..95ffdbfb 100644 --- a/packages/shorebird_cli/test/src/commands/release/ios_framework_releaser_test.dart +++ b/packages/shorebird_cli/test/src/commands/release/ios_framework_releaser_test.dart @@ -307,6 +307,27 @@ For more information see: ${supportedFlutterVersionsUrl.toLink()}''', }); group('when build succeeds', () { + group('when stale build/ios/shorebird directory exists', () { + late Directory shorebirdSupplementDir; + + setUp(() { + shorebirdSupplementDir = Directory( + p.join(projectRoot.path, 'build', 'ios', 'shorebird'), + )..createSync(recursive: true); + when( + () => artifactManager.getIosReleaseSupplementDirectory(), + ).thenReturn(shorebirdSupplementDir); + }); + + test('deletes the directory', () async { + expect(shorebirdSupplementDir.existsSync(), isTrue); + await runWithOverrides( + iosFrameworkReleaser.buildReleaseArtifacts, + ); + expect(shorebirdSupplementDir.existsSync(), isFalse); + }); + }); + group('when platform was specified via arg results rest', () { setUp(() { when(() => argResults.rest).thenReturn(['ios', '--verbose']); 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 e1ff3b58..d76ad672 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 @@ -348,14 +348,17 @@ To change the version of this release, change your app's version in your pubspec xcarchiveDirectory: any(named: 'xcarchiveDirectory'), ), ).thenReturn(iosAppDirectory); - when(() => artifactManager.getXcarchiveDirectory()) - .thenReturn(xcarchiveDirectory); + when( + () => artifactManager.getXcarchiveDirectory(), + ).thenReturn(xcarchiveDirectory); - when(() => codeSigner.base64PublicKey(any())) - .thenReturn(base64PublicKey); + when( + () => codeSigner.base64PublicKey(any()), + ).thenReturn(base64PublicKey); - when(() => shorebirdEnv.getShorebirdProjectRoot()) - .thenReturn(projectRoot); + when( + () => shorebirdEnv.getShorebirdProjectRoot(), + ).thenReturn(projectRoot); when( () => shorebirdFlutter.getVersionAndRevision(), ).thenAnswer((_) async => flutterVersionAndRevision); @@ -369,8 +372,9 @@ To change the version of this release, change your app's version in your pubspec 'patch-signing-public-key.pem', ), )..createSync(recursive: true); - when(() => argResults[CommonArguments.publicKeyArg.name]) - .thenReturn(patchSigningPublicKeyFile.path); + when( + () => argResults[CommonArguments.publicKeyArg.name], + ).thenReturn(patchSigningPublicKeyFile.path); when( () => artifactBuilder.buildIpa( @@ -456,6 +460,25 @@ To change the version of this release, change your app's version in your pubspec }); group('when build succeeds', () { + group('when stale build/ios/shorebird directory exists', () { + late Directory shorebirdSupplementDir; + + setUp(() { + shorebirdSupplementDir = Directory( + p.join(projectRoot.path, 'build', 'ios', 'shorebird'), + )..createSync(recursive: true); + when( + () => artifactManager.getIosReleaseSupplementDirectory(), + ).thenReturn(shorebirdSupplementDir); + }); + + test('deletes the directory', () async { + expect(shorebirdSupplementDir.existsSync(), isTrue); + await runWithOverrides(iosReleaser.buildReleaseArtifacts); + expect(shorebirdSupplementDir.existsSync(), isFalse); + }); + }); + group('when platform was specified via arg results rest', () { setUp(() { when(() => argResults.rest).thenReturn(['ios', '--verbose']);