From 5f71c0d6b37f6c8708e638994b0ca8d0d0467d31 Mon Sep 17 00:00:00 2001 From: Felix Angelov Date: Thu, 3 Aug 2023 16:11:55 -0500 Subject: [PATCH] fix(shorebird_cli): flutter revision detection in `shorebird patch` (#1016) --- .../commands/patch/patch_android_command.dart | 15 +-------- .../src/commands/patch/patch_ios_command.dart | 15 +-------- .../patch/patch_ios_framework_command.dart | 15 +-------- .../patch/patch_aar_command_test.dart | 2 +- .../patch/patch_android_command_test.dart | 32 ++----------------- .../patch/patch_ios_command_test.dart | 32 ++----------------- .../patch_ios_framework_command_test.dart | 32 ++----------------- 7 files changed, 10 insertions(+), 133 deletions(-) diff --git a/packages/shorebird_cli/lib/src/commands/patch/patch_android_command.dart b/packages/shorebird_cli/lib/src/commands/patch/patch_android_command.dart index 7676e4d60..f2bd24558 100644 --- a/packages/shorebird_cli/lib/src/commands/patch/patch_android_command.dart +++ b/packages/shorebird_cli/lib/src/commands/patch/patch_android_command.dart @@ -17,7 +17,6 @@ import 'package:shorebird_cli/src/shorebird_build_mixin.dart'; import 'package:shorebird_cli/src/shorebird_env.dart'; import 'package:shorebird_cli/src/shorebird_release_version_mixin.dart'; import 'package:shorebird_cli/src/shorebird_validator.dart'; -import 'package:shorebird_cli/src/shorebird_version_manager.dart'; import 'package:shorebird_code_push_client/shorebird_code_push_client.dart'; /// {@template patch_android_command} @@ -148,19 +147,7 @@ Please re-run the release command for this version or create a new release.'''); return ExitCode.software.code; } - final flutterRevisionProgress = logger.progress( - 'Fetching Flutter revision', - ); - final String shorebirdFlutterRevision; - try { - shorebirdFlutterRevision = - await shorebirdVersionManager.fetchCurrentGitHash(); - flutterRevisionProgress.complete(); - } catch (error) { - flutterRevisionProgress.fail('$error'); - return ExitCode.software.code; - } - + final shorebirdFlutterRevision = shorebirdEnv.flutterRevision; if (release.flutterRevision != shorebirdFlutterRevision) { logger ..err(''' 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 806390294..fe8c00c25 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 @@ -16,7 +16,6 @@ import 'package:shorebird_cli/src/shorebird_artifact_mixin.dart'; import 'package:shorebird_cli/src/shorebird_build_mixin.dart'; import 'package:shorebird_cli/src/shorebird_env.dart'; import 'package:shorebird_cli/src/shorebird_validator.dart'; -import 'package:shorebird_cli/src/shorebird_version_manager.dart'; import 'package:shorebird_code_push_client/shorebird_code_push_client.dart'; /// {@template patch_ios_command} @@ -153,19 +152,7 @@ Please re-run the release command for this version or create a new release.'''); return ExitCode.software.code; } - final flutterRevisionProgress = logger.progress( - 'Fetching Flutter revision', - ); - final String shorebirdFlutterRevision; - try { - shorebirdFlutterRevision = - await shorebirdVersionManager.fetchCurrentGitHash(); - flutterRevisionProgress.complete(); - } catch (error) { - flutterRevisionProgress.fail('$error'); - return ExitCode.software.code; - } - + final shorebirdFlutterRevision = shorebirdEnv.flutterRevision; if (release.flutterRevision != shorebirdFlutterRevision) { logger ..err(''' diff --git a/packages/shorebird_cli/lib/src/commands/patch/patch_ios_framework_command.dart b/packages/shorebird_cli/lib/src/commands/patch/patch_ios_framework_command.dart index 94a8d84b5..a5bfd3918 100644 --- a/packages/shorebird_cli/lib/src/commands/patch/patch_ios_framework_command.dart +++ b/packages/shorebird_cli/lib/src/commands/patch/patch_ios_framework_command.dart @@ -14,7 +14,6 @@ import 'package:shorebird_cli/src/shorebird_artifact_mixin.dart'; import 'package:shorebird_cli/src/shorebird_build_mixin.dart'; import 'package:shorebird_cli/src/shorebird_env.dart'; import 'package:shorebird_cli/src/shorebird_validator.dart'; -import 'package:shorebird_cli/src/shorebird_version_manager.dart'; import 'package:shorebird_code_push_client/shorebird_code_push_client.dart'; class PatchIosFrameworkCommand extends ShorebirdCommand @@ -110,19 +109,7 @@ Please re-run the release command for this version or create a new release.'''); buildProgress.complete(); - final flutterRevisionProgress = logger.progress( - 'Fetching Flutter revision', - ); - final String shorebirdFlutterRevision; - try { - shorebirdFlutterRevision = - await shorebirdVersionManager.fetchCurrentGitHash(); - flutterRevisionProgress.complete(); - } catch (error) { - flutterRevisionProgress.fail('$error'); - return ExitCode.software.code; - } - + final shorebirdFlutterRevision = shorebirdEnv.flutterRevision; if (release.flutterRevision != shorebirdFlutterRevision) { logger ..err(''' diff --git a/packages/shorebird_cli/test/src/commands/patch/patch_aar_command_test.dart b/packages/shorebird_cli/test/src/commands/patch/patch_aar_command_test.dart index 45ee2fdc4..e62ab6be0 100644 --- a/packages/shorebird_cli/test/src/commands/patch/patch_aar_command_test.dart +++ b/packages/shorebird_cli/test/src/commands/patch/patch_aar_command_test.dart @@ -206,6 +206,7 @@ void main() { () => shorebirdEnv.androidPackageName, ).thenReturn(androidPackageName); when(() => shorebirdEnv.getShorebirdYaml()).thenReturn(shorebirdYaml); + when(() => shorebirdEnv.flutterRevision).thenReturn(flutterRevision); when( () => shorebirdProcess.run( 'flutter', @@ -298,7 +299,6 @@ void main() { when( () => cache.getArtifactDirectory(any()), ).thenReturn(Directory.systemTemp.createTempSync()); - when(() => shorebirdEnv.flutterRevision).thenReturn(flutterRevision); when( () => shorebirdFlutterManager.installRevision( revision: any(named: 'revision'), diff --git a/packages/shorebird_cli/test/src/commands/patch/patch_android_command_test.dart b/packages/shorebird_cli/test/src/commands/patch/patch_android_command_test.dart index 65248dc23..9987dc502 100644 --- a/packages/shorebird_cli/test/src/commands/patch/patch_android_command_test.dart +++ b/packages/shorebird_cli/test/src/commands/patch/patch_android_command_test.dart @@ -23,7 +23,6 @@ import 'package:shorebird_cli/src/process.dart'; import 'package:shorebird_cli/src/shorebird_build_mixin.dart'; import 'package:shorebird_cli/src/shorebird_env.dart'; import 'package:shorebird_cli/src/shorebird_validator.dart'; -import 'package:shorebird_cli/src/shorebird_version_manager.dart'; import 'package:shorebird_cli/src/validators/validators.dart'; import 'package:shorebird_code_push_client/shorebird_code_push_client.dart'; import 'package:test/test.dart'; @@ -66,9 +65,6 @@ class _MockShorebirdProcess extends Mock implements ShorebirdProcess {} class _MockShorebirdValidator extends Mock implements ShorebirdValidator {} -class _MockShorebirdVersionManager extends Mock - implements ShorebirdVersionManager {} - class _FakeShorebirdProcess extends Fake implements ShorebirdProcess {} void main() { @@ -140,7 +136,6 @@ flutter: late ShorebirdFlutterValidator flutterValidator; late ShorebirdProcess shorebirdProcess; late ShorebirdValidator shorebirdValidator; - late ShorebirdVersionManager shorebirdVersionManager; late PatchAndroidCommand command; R runWithOverrides(R Function() body) { @@ -159,9 +154,6 @@ flutter: platformRef.overrideWith(() => platform), processRef.overrideWith(() => shorebirdProcess), shorebirdValidatorRef.overrideWith(() => shorebirdValidator), - shorebirdVersionManagerRef.overrideWith( - () => shorebirdVersionManager, - ), }, ); } @@ -226,7 +218,6 @@ flutter: shorebirdEnv = _MockShorebirdEnv(); shorebirdProcess = _MockShorebirdProcess(); shorebirdValidator = _MockShorebirdValidator(); - shorebirdVersionManager = _MockShorebirdVersionManager(); command = runWithOverrides( () => PatchAndroidCommand( archiveDiffer: archiveDiffer, @@ -237,6 +228,7 @@ flutter: when(() => shorebirdEnv.getShorebirdYaml()).thenReturn(shorebirdYaml); when(() => shorebirdEnv.shorebirdRoot).thenReturn(shorebirdRoot); when(() => shorebirdEnv.flutterDirectory).thenReturn(flutterDirectory); + when(() => shorebirdEnv.flutterRevision).thenReturn(flutterRevision); when( () => shorebirdProcess.run( 'flutter', @@ -356,9 +348,6 @@ flutter: validators: any(named: 'validators'), ), ).thenAnswer((_) async {}); - when( - () => shorebirdVersionManager.fetchCurrentGitHash(), - ).thenAnswer((_) async => flutterRevision); }); test('has a description', () { @@ -487,28 +476,11 @@ Please re-run the release command for this version or create a new release.'''), }, ); - test('errors when unable to detect flutter revision', () async { - final exception = Exception('oops'); - when( - () => shorebirdVersionManager.fetchCurrentGitHash(), - ).thenThrow(exception); - final tempDir = setUpTempDir(); - setUpTempArtifacts(tempDir); - final exitCode = await IOOverrides.runZoned( - () => runWithOverrides(command.run), - getCurrentDirectory: () => tempDir, - ); - expect(exitCode, ExitCode.software.code); - verify(() => progress.fail('$exception')).called(1); - }); - test( 'errors when shorebird flutter revision ' 'does not match release revision', () async { const otherRevision = 'other-revision'; - when( - () => shorebirdVersionManager.fetchCurrentGitHash(), - ).thenAnswer((_) async => otherRevision); + when(() => shorebirdEnv.flutterRevision).thenReturn(otherRevision); final tempDir = setUpTempDir(); setUpTempArtifacts(tempDir); 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 cb5b70839..946f1c894 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 @@ -19,7 +19,6 @@ import 'package:shorebird_cli/src/platform.dart'; import 'package:shorebird_cli/src/process.dart'; import 'package:shorebird_cli/src/shorebird_env.dart'; import 'package:shorebird_cli/src/shorebird_validator.dart'; -import 'package:shorebird_cli/src/shorebird_version_manager.dart'; import 'package:shorebird_cli/src/third_party/flutter_tools/lib/flutter_tools.dart'; import 'package:shorebird_cli/src/validators/validators.dart'; import 'package:shorebird_code_push_client/shorebird_code_push_client.dart'; @@ -59,9 +58,6 @@ class _MockShorebirdProcess extends Mock implements ShorebirdProcess {} class _MockShorebirdValidator extends Mock implements ShorebirdValidator {} -class _MockShorebirdVersionManager extends Mock - implements ShorebirdVersionManager {} - class _FakeShorebirdProcess extends Fake implements ShorebirdProcess {} void main() { @@ -125,7 +121,6 @@ flutter: late ShorebirdFlutterValidator flutterValidator; late ShorebirdProcess shorebirdProcess; late ShorebirdValidator shorebirdValidator; - late ShorebirdVersionManager shorebirdVersionManager; late PatchIosCommand command; R runWithOverrides(R Function() body) { @@ -140,9 +135,6 @@ flutter: processRef.overrideWith(() => shorebirdProcess), shorebirdEnvRef.overrideWith(() => shorebirdEnv), shorebirdValidatorRef.overrideWith(() => shorebirdValidator), - shorebirdVersionManagerRef.overrideWith( - () => shorebirdVersionManager, - ), }, ); } @@ -221,7 +213,6 @@ flutter: flutterValidator = _MockShorebirdFlutterValidator(); shorebirdProcess = _MockShorebirdProcess(); shorebirdValidator = _MockShorebirdValidator(); - shorebirdVersionManager = _MockShorebirdVersionManager(); when(() => argResults['arch']).thenReturn(arch); when(() => argResults['dry-run']).thenReturn(false); @@ -259,6 +250,7 @@ flutter: when(() => shorebirdEnv.shorebirdRoot).thenReturn(shorebirdRoot); when(() => shorebirdEnv.flutterDirectory).thenReturn(flutterDirectory); when(() => shorebirdEnv.genSnapshotFile).thenReturn(genSnapshotFile); + when(() => shorebirdEnv.flutterRevision).thenReturn(flutterRevision); when( () => aotBuildProcessResult.exitCode, ).thenReturn(ExitCode.success.code); @@ -287,9 +279,6 @@ flutter: supportedOperatingSystems: any(named: 'supportedOperatingSystems'), ), ).thenAnswer((_) async {}); - when( - () => shorebirdVersionManager.fetchCurrentGitHash(), - ).thenAnswer((_) async => flutterRevision); command = runWithOverrides(() => PatchIosCommand(ipaReader: ipaReader)) ..testArgResults = argResults; @@ -495,28 +484,11 @@ Please re-run the release command for this version or create a new release.'''), }, ); - test('errors when unable to detect flutter revision', () async { - final exception = Exception('oops'); - when( - () => shorebirdVersionManager.fetchCurrentGitHash(), - ).thenThrow(exception); - final tempDir = setUpTempDir(); - setUpTempArtifacts(tempDir); - final exitCode = await IOOverrides.runZoned( - () => runWithOverrides(command.run), - getCurrentDirectory: () => tempDir, - ); - expect(exitCode, ExitCode.software.code); - verify(() => progress.fail('$exception')).called(1); - }); - test( 'errors when shorebird flutter revision ' 'does not match release revision', () async { const otherRevision = 'other-revision'; - when( - () => shorebirdVersionManager.fetchCurrentGitHash(), - ).thenAnswer((_) async => otherRevision); + when(() => shorebirdEnv.flutterRevision).thenReturn(otherRevision); final tempDir = setUpTempDir(); setUpTempArtifacts(tempDir); diff --git a/packages/shorebird_cli/test/src/commands/patch/patch_ios_framework_command_test.dart b/packages/shorebird_cli/test/src/commands/patch/patch_ios_framework_command_test.dart index 8f24088cd..9f4e024d8 100644 --- a/packages/shorebird_cli/test/src/commands/patch/patch_ios_framework_command_test.dart +++ b/packages/shorebird_cli/test/src/commands/patch/patch_ios_framework_command_test.dart @@ -16,7 +16,6 @@ import 'package:shorebird_cli/src/platform.dart'; import 'package:shorebird_cli/src/process.dart'; import 'package:shorebird_cli/src/shorebird_env.dart'; import 'package:shorebird_cli/src/shorebird_validator.dart'; -import 'package:shorebird_cli/src/shorebird_version_manager.dart'; import 'package:shorebird_cli/src/validators/validators.dart'; import 'package:shorebird_code_push_client/shorebird_code_push_client.dart'; import 'package:test/test.dart'; @@ -47,9 +46,6 @@ class _MockShorebirdProcess extends Mock implements ShorebirdProcess {} class _MockShorebirdValidator extends Mock implements ShorebirdValidator {} -class _MockShorebirdVersionManager extends Mock - implements ShorebirdVersionManager {} - void main() { group(PatchIosFrameworkCommand, () { const appDisplayName = 'Test App'; @@ -95,7 +91,6 @@ flutter: late ShorebirdFlutterValidator flutterValidator; late ShorebirdProcess shorebirdProcess; late ShorebirdValidator shorebirdValidator; - late ShorebirdVersionManager shorebirdVersionManager; late PatchIosFrameworkCommand command; R runWithOverrides(R Function() body) { @@ -110,9 +105,6 @@ flutter: processRef.overrideWith(() => shorebirdProcess), shorebirdEnvRef.overrideWith(() => shorebirdEnv), shorebirdValidatorRef.overrideWith(() => shorebirdValidator), - shorebirdVersionManagerRef.overrideWith( - () => shorebirdVersionManager, - ), }, ); } @@ -180,7 +172,6 @@ flutter: flutterValidator = _MockShorebirdFlutterValidator(); shorebirdProcess = _MockShorebirdProcess(); shorebirdValidator = _MockShorebirdValidator(); - shorebirdVersionManager = _MockShorebirdVersionManager(); when( () => shorebirdProcess.run( @@ -209,6 +200,7 @@ flutter: when(() => shorebirdEnv.shorebirdRoot).thenReturn(shorebirdRoot); when(() => shorebirdEnv.flutterDirectory).thenReturn(flutterDirectory); when(() => shorebirdEnv.genSnapshotFile).thenReturn(genSnapshotFile); + when(() => shorebirdEnv.flutterRevision).thenReturn(flutterRevision); when( () => aotBuildProcessResult.exitCode, ).thenReturn(ExitCode.success.code); @@ -241,9 +233,6 @@ flutter: supportedOperatingSystems: any(named: 'supportedOperatingSystems'), ), ).thenAnswer((_) async {}); - when( - () => shorebirdVersionManager.fetchCurrentGitHash(), - ).thenAnswer((_) async => flutterRevision); command = runWithOverrides(PatchIosFrameworkCommand.new) ..testArgResults = argResults; @@ -365,28 +354,11 @@ Please re-run the release command for this version or create a new release.'''), verify(() => progress.fail('Failed to build: oh no')).called(1); }); - test('errors when unable to detect flutter revision', () async { - final exception = Exception('oops'); - when( - () => shorebirdVersionManager.fetchCurrentGitHash(), - ).thenThrow(exception); - final tempDir = setUpTempDir(); - setUpTempArtifacts(tempDir); - final exitCode = await IOOverrides.runZoned( - () => runWithOverrides(command.run), - getCurrentDirectory: () => tempDir, - ); - expect(exitCode, ExitCode.software.code); - verify(() => progress.fail('$exception')).called(1); - }); - test( 'errors when shorebird flutter revision ' 'does not match release revision', () async { const otherRevision = 'other-revision'; - when( - () => shorebirdVersionManager.fetchCurrentGitHash(), - ).thenAnswer((_) async => otherRevision); + when(() => shorebirdEnv.flutterRevision).thenReturn(otherRevision); final tempDir = setUpTempDir(); setUpTempArtifacts(tempDir);