Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(shorebird_cli): don't run flutter pub get after build if flutter is not installed #1447

Merged
merged 3 commits into from
Nov 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions packages/shorebird_cli/lib/src/shorebird_build_mixin.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import 'package:collection/collection.dart';
import 'package:mason_logger/mason_logger.dart';
import 'package:shorebird_cli/src/command.dart';
import 'package:shorebird_cli/src/logger.dart';
import 'package:shorebird_cli/src/os/operating_system_interface.dart';
import 'package:shorebird_cli/src/process.dart';
import 'package:shorebird_cli/src/shorebird_env.dart';

Expand Down Expand Up @@ -277,6 +278,12 @@ mixin ShorebirdBuildMixin on ShorebirdCommand {
/// https://github.com/shorebirdtech/shorebird/issues/1101 for more info.
Future<void> _systemFlutterPubGet() async {
const executable = 'flutter';
if (osInterface.which(executable) == null) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we really need to get rid of this mixin so we can avoid having to duplicate the tests 🤣

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, this PR is a case study re: why we shouldn't use mixins for any functionality we want to test :)

// If the user doesn't have Flutter on their PATH, then we can't run
// `flutter pub get` with the system Flutter.
return;
}

final arguments = ['--no-version-check', 'pub', 'get', '--offline'];

final result = await process.run(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import 'package:path/path.dart' as p;
import 'package:scoped/scoped.dart';
import 'package:shorebird_cli/src/commands/build/build.dart';
import 'package:shorebird_cli/src/logger.dart';
import 'package:shorebird_cli/src/os/operating_system_interface.dart';
import 'package:shorebird_cli/src/process.dart';
import 'package:shorebird_cli/src/shorebird_env.dart';
import 'package:shorebird_cli/src/shorebird_validator.dart';
Expand All @@ -19,6 +20,7 @@ void main() {

late ArgResults argResults;
late Logger logger;
late OperatingSystemInterface operatingSystemInterface;
late Progress progress;
late ShorebirdEnv shorebirdEnv;
late ShorebirdProcess shorebirdProcess;
Expand All @@ -32,6 +34,7 @@ void main() {
body,
values: {
loggerRef.overrideWith(() => logger),
osInterfaceRef.overrideWith(() => operatingSystemInterface),
processRef.overrideWith(() => shorebirdProcess),
shorebirdEnvRef.overrideWith(() => shorebirdEnv),
shorebirdValidatorRef.overrideWith(() => shorebirdValidator),
Expand All @@ -44,6 +47,7 @@ void main() {
logger = MockLogger();
flutterPubGetProcessResult = MockProcessResult();
buildProcessResult = MockProcessResult();
operatingSystemInterface = MockOperatingSystemInterface();
progress = MockProgress();
shorebirdEnv = MockShorebirdEnv();
shorebirdProcess = MockShorebirdProcess();
Expand Down Expand Up @@ -73,6 +77,8 @@ void main() {
return buildProcessResult;
});

when(() => operatingSystemInterface.which('flutter'))
.thenReturn('/path/to/flutter');
when(
() => shorebirdValidator.validatePreconditions(
checkUserIsAuthenticated: any(named: 'checkUserIsAuthenticated'),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import 'package:scoped/scoped.dart';
import 'package:shorebird_cli/src/commands/build/build.dart';
import 'package:shorebird_cli/src/doctor.dart';
import 'package:shorebird_cli/src/logger.dart';
import 'package:shorebird_cli/src/os/operating_system_interface.dart';
import 'package:shorebird_cli/src/process.dart';
import 'package:shorebird_cli/src/shorebird_validator.dart';
import 'package:shorebird_cli/src/validators/validators.dart';
Expand All @@ -21,6 +22,7 @@ void main() {
late ArgResults argResults;
late Doctor doctor;
late Logger logger;
late OperatingSystemInterface operatingSystemInterface;
late ShorebirdProcessResult flutterPubGetProcessResult;
late ShorebirdProcessResult buildProcessResult;
late BuildApkCommand command;
Expand All @@ -34,6 +36,7 @@ void main() {
values: {
doctorRef.overrideWith(() => doctor),
loggerRef.overrideWith(() => logger),
osInterfaceRef.overrideWith(() => operatingSystemInterface),
processRef.overrideWith(() => shorebirdProcess),
shorebirdValidatorRef.overrideWith(() => shorebirdValidator),
},
Expand All @@ -48,6 +51,7 @@ void main() {
argResults = MockArgResults();
doctor = MockDoctor();
logger = MockLogger();
operatingSystemInterface = MockOperatingSystemInterface();
shorebirdProcess = MockShorebirdProcess();
buildProcessResult = MockProcessResult();
flutterPubGetProcessResult = MockProcessResult();
Expand All @@ -74,6 +78,8 @@ void main() {
when(() => argResults.rest).thenReturn([]);
when(() => logger.progress(any())).thenReturn(MockProgress());
when(() => logger.info(any())).thenReturn(null);
when(() => operatingSystemInterface.which('flutter'))
.thenReturn('/path/to/flutter');
when(
() => shorebirdValidator.validatePreconditions(
checkUserIsAuthenticated: any(named: 'checkUserIsAuthenticated'),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import 'package:scoped/scoped.dart';
import 'package:shorebird_cli/src/commands/build/build.dart';
import 'package:shorebird_cli/src/doctor.dart';
import 'package:shorebird_cli/src/logger.dart';
import 'package:shorebird_cli/src/os/operating_system_interface.dart';
import 'package:shorebird_cli/src/process.dart';
import 'package:shorebird_cli/src/shorebird_validator.dart';
import 'package:shorebird_cli/src/validators/validators.dart';
Expand All @@ -21,6 +22,7 @@ void main() {
late ArgResults argResults;
late Doctor doctor;
late Logger logger;
late OperatingSystemInterface operatingSystemInterface;
late ShorebirdProcessResult flutterPubGetProcessResult;
late ShorebirdProcessResult buildProcessResult;
late BuildAppBundleCommand command;
Expand All @@ -35,6 +37,7 @@ void main() {
doctorRef.overrideWith(() => doctor),
engineConfigRef.overrideWith(() => const EngineConfig.empty()),
loggerRef.overrideWith(() => logger),
osInterfaceRef.overrideWith(() => operatingSystemInterface),
processRef.overrideWith(() => shorebirdProcess),
shorebirdValidatorRef.overrideWith(() => shorebirdValidator),
},
Expand All @@ -49,6 +52,7 @@ void main() {
argResults = MockArgResults();
doctor = MockDoctor();
logger = MockLogger();
operatingSystemInterface = MockOperatingSystemInterface();
buildProcessResult = MockProcessResult();
flutterPubGetProcessResult = MockProcessResult();
flutterValidator = MockShorebirdFlutterValidator();
Expand All @@ -75,6 +79,8 @@ void main() {
when(() => argResults.rest).thenReturn([]);
when(() => logger.progress(any())).thenReturn(MockProgress());
when(() => logger.info(any())).thenReturn(null);
when(() => operatingSystemInterface.which('flutter'))
.thenReturn('/path/to/flutter');
when(
() => doctor.androidCommandValidators,
).thenReturn([flutterValidator]);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import 'package:scoped/scoped.dart';
import 'package:shorebird_cli/src/commands/build/build.dart';
import 'package:shorebird_cli/src/doctor.dart';
import 'package:shorebird_cli/src/logger.dart';
import 'package:shorebird_cli/src/os/operating_system_interface.dart';
import 'package:shorebird_cli/src/process.dart';
import 'package:shorebird_cli/src/shorebird_validator.dart';
import 'package:shorebird_cli/src/validators/validators.dart';
Expand All @@ -21,6 +22,7 @@ void main() {
late ArgResults argResults;
late Doctor doctor;
late Logger logger;
late OperatingSystemInterface operatingSystemInterface;
late ShorebirdProcessResult buildProcessResult;
late ShorebirdProcessResult flutterPubGetProcessResult;
late BuildIpaCommand command;
Expand All @@ -34,6 +36,7 @@ void main() {
values: {
doctorRef.overrideWith(() => doctor),
loggerRef.overrideWith(() => logger),
osInterfaceRef.overrideWith(() => operatingSystemInterface),
processRef.overrideWith(() => shorebirdProcess),
shorebirdValidatorRef.overrideWith(() => shorebirdValidator),
},
Expand All @@ -48,6 +51,7 @@ void main() {
argResults = MockArgResults();
doctor = MockDoctor();
logger = MockLogger();
operatingSystemInterface = MockOperatingSystemInterface();
shorebirdProcess = MockShorebirdProcess();
buildProcessResult = MockProcessResult();
flutterPubGetProcessResult = MockProcessResult();
Expand Down Expand Up @@ -75,6 +79,8 @@ void main() {
when(() => argResults.rest).thenReturn([]);
when(() => logger.progress(any())).thenReturn(MockProgress());
when(() => logger.info(any())).thenReturn(null);
when(() => operatingSystemInterface.which('flutter'))
.thenReturn('/path/to/flutter');
when(() => doctor.iosCommandValidators).thenReturn([flutterValidator]);
when(
() => shorebirdValidator.validatePreconditions(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import 'package:shorebird_cli/src/commands/commands.dart';
import 'package:shorebird_cli/src/config/config.dart';
import 'package:shorebird_cli/src/deployment_track.dart';
import 'package:shorebird_cli/src/logger.dart';
import 'package:shorebird_cli/src/os/operating_system_interface.dart';
import 'package:shorebird_cli/src/patch_diff_checker.dart';
import 'package:shorebird_cli/src/platform.dart';
import 'package:shorebird_cli/src/process.dart';
Expand Down Expand Up @@ -85,6 +86,7 @@ void main() {
late CodePushClientWrapper codePushClientWrapper;
late Directory shorebirdRoot;
late Directory flutterDirectory;
late OperatingSystemInterface operatingSystemInterface;
late PatchDiffChecker patchDiffChecker;
late Platform platform;
late Progress progress;
Expand All @@ -109,6 +111,7 @@ void main() {
codePushClientWrapperRef.overrideWith(() => codePushClientWrapper),
engineConfigRef.overrideWith(() => const EngineConfig.empty()),
loggerRef.overrideWith(() => logger),
osInterfaceRef.overrideWith(() => operatingSystemInterface),
patchDiffCheckerRef.overrideWith(() => patchDiffChecker),
platformRef.overrideWith(() => platform),
processRef.overrideWith(() => shorebirdProcess),
Expand Down Expand Up @@ -170,6 +173,7 @@ void main() {
flutterDirectory = Directory(
p.join(shorebirdRoot.path, 'bin', 'cache', 'flutter'),
);
operatingSystemInterface = MockOperatingSystemInterface();
patchDiffChecker = MockPatchDiffChecker();
platform = MockPlatform();
progress = MockProgress();
Expand All @@ -183,6 +187,8 @@ void main() {
shorebirdProcess = MockShorebirdProcess();
shorebirdValidator = MockShorebirdValidator();

when(() => operatingSystemInterface.which('flutter'))
.thenReturn('/path/to/flutter');
when(() => platform.environment).thenReturn({});
when(() => shorebirdEnv.shorebirdRoot).thenReturn(shorebirdRoot);
when(() => shorebirdEnv.flutterDirectory).thenReturn(flutterDirectory);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import 'package:shorebird_cli/src/deployment_track.dart';
import 'package:shorebird_cli/src/doctor.dart';
import 'package:shorebird_cli/src/executables/executables.dart';
import 'package:shorebird_cli/src/logger.dart';
import 'package:shorebird_cli/src/os/operating_system_interface.dart';
import 'package:shorebird_cli/src/patch_diff_checker.dart';
import 'package:shorebird_cli/src/platform.dart';
import 'package:shorebird_cli/src/process.dart';
Expand Down Expand Up @@ -98,6 +99,7 @@ flutter:
late Directory shorebirdRoot;
late Doctor doctor;
late Java java;
late OperatingSystemInterface operatingSystemInterface;
late PatchDiffChecker patchDiffChecker;
late Platform platform;
late Progress progress;
Expand Down Expand Up @@ -126,6 +128,7 @@ flutter:
engineConfigRef.overrideWith(() => const EngineConfig.empty()),
javaRef.overrideWith(() => java),
loggerRef.overrideWith(() => logger),
osInterfaceRef.overrideWith(() => operatingSystemInterface),
patchDiffCheckerRef.overrideWith(() => patchDiffChecker),
shorebirdEnvRef.overrideWith(() => shorebirdEnv),
platformRef.overrideWith(() => platform),
Expand Down Expand Up @@ -199,6 +202,7 @@ flutter:
httpClient = MockHttpClient();
flutterValidator = MockShorebirdFlutterValidator();
cache = MockCache();
operatingSystemInterface = MockOperatingSystemInterface();
shorebirdEnv = MockShorebirdEnv();
shorebirdProcess = MockShorebirdProcess();
shorebirdFlutter = MockShorebirdFlutter();
Expand Down Expand Up @@ -347,6 +351,8 @@ flutter:
validators: any(named: 'validators'),
),
).thenAnswer((_) async {});
when(() => operatingSystemInterface.which('flutter'))
.thenReturn('/path/to/flutter');
when(
() => patchDiffChecker.confirmUnpatchableDiffsIfNecessary(
localArtifact: any(named: 'localArtifact'),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import 'package:shorebird_cli/src/config/config.dart';
import 'package:shorebird_cli/src/deployment_track.dart';
import 'package:shorebird_cli/src/doctor.dart';
import 'package:shorebird_cli/src/logger.dart';
import 'package:shorebird_cli/src/os/operating_system_interface.dart';
import 'package:shorebird_cli/src/patch_diff_checker.dart';
import 'package:shorebird_cli/src/platform.dart';
import 'package:shorebird_cli/src/process.dart';
Expand Down Expand Up @@ -130,6 +131,7 @@ flutter:
late IosArchiveDiffer archiveDiffer;
late Progress progress;
late Logger logger;
late OperatingSystemInterface operatingSystemInterface;
late PatchDiffChecker patchDiffChecker;
late Platform platform;
late ShorebirdProcessResult aotBuildProcessResult;
Expand All @@ -151,6 +153,7 @@ flutter:
codePushClientWrapperRef.overrideWith(() => codePushClientWrapper),
doctorRef.overrideWith(() => doctor),
loggerRef.overrideWith(() => logger),
osInterfaceRef.overrideWith(() => operatingSystemInterface),
patchDiffCheckerRef.overrideWith(() => patchDiffChecker),
platformRef.overrideWith(() => platform),
processRef.overrideWith(() => shorebirdProcess),
Expand Down Expand Up @@ -243,6 +246,7 @@ flutter:
flutterBuildProcessResult = MockProcessResult();
flutterPubGetProcessResult = MockProcessResult();
httpClient = MockHttpClient();
operatingSystemInterface = MockOperatingSystemInterface();
patchDiffChecker = MockPatchDiffChecker();
shorebirdEnv = MockShorebirdEnv();
shorebirdFlutter = MockShorebirdFlutter();
Expand Down Expand Up @@ -288,6 +292,8 @@ flutter:
when(flutterValidator.validate).thenAnswer((_) async => []);
when(() => logger.confirm(any())).thenReturn(true);
when(() => logger.progress(any())).thenReturn(progress);
when(() => operatingSystemInterface.which('flutter'))
.thenReturn('/path/to/flutter');
when(() => platform.operatingSystem).thenReturn(Platform.macOS);
when(() => platform.environment).thenReturn({});
when(() => platform.script).thenReturn(shorebirdRoot.uri);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import 'package:shorebird_cli/src/config/config.dart';
import 'package:shorebird_cli/src/deployment_track.dart';
import 'package:shorebird_cli/src/doctor.dart';
import 'package:shorebird_cli/src/logger.dart';
import 'package:shorebird_cli/src/os/operating_system_interface.dart';
import 'package:shorebird_cli/src/patch_diff_checker.dart';
import 'package:shorebird_cli/src/platform.dart';
import 'package:shorebird_cli/src/process.dart';
Expand Down Expand Up @@ -83,8 +84,9 @@ flutter:
late PatchDiffChecker patchDiffChecker;
late Platform platform;
late Auth auth;
late Progress progress;
late OperatingSystemInterface operatingSystemInterface;
late Logger logger;
late Progress progress;
late ShorebirdProcessResult aotBuildProcessResult;
late ShorebirdProcessResult flutterBuildProcessResult;
late ShorebirdProcessResult flutterPubGetProcessResult;
Expand All @@ -103,6 +105,7 @@ flutter:
codePushClientWrapperRef.overrideWith(() => codePushClientWrapper),
doctorRef.overrideWith(() => doctor),
loggerRef.overrideWith(() => logger),
osInterfaceRef.overrideWith(() => operatingSystemInterface),
patchDiffCheckerRef.overrideWith(() => patchDiffChecker),
platformRef.overrideWith(() => platform),
processRef.overrideWith(() => shorebirdProcess),
Expand Down Expand Up @@ -191,6 +194,7 @@ flutter:
aotBuildProcessResult = MockProcessResult();
flutterBuildProcessResult = MockProcessResult();
flutterPubGetProcessResult = MockProcessResult();
operatingSystemInterface = MockOperatingSystemInterface();
shorebirdEnv = MockShorebirdEnv();
shorebirdFlutter = MockShorebirdFlutter();
flutterValidator = MockShorebirdFlutterValidator();
Expand Down Expand Up @@ -228,6 +232,8 @@ flutter:
when(() => logger.level).thenReturn(Level.info);
when(() => logger.progress(any())).thenReturn(progress);
when(() => logger.confirm(any())).thenReturn(true);
when(() => operatingSystemInterface.which('flutter'))
.thenReturn('/path/to/flutter');
when(() => platform.operatingSystem).thenReturn(Platform.macOS);
when(() => shorebirdEnv.getShorebirdYaml()).thenReturn(shorebirdYaml);
when(() => shorebirdEnv.shorebirdRoot).thenReturn(shorebirdRoot);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import 'package:shorebird_cli/src/commands/commands.dart';
import 'package:shorebird_cli/src/config/config.dart';
import 'package:shorebird_cli/src/executables/executables.dart';
import 'package:shorebird_cli/src/logger.dart';
import 'package:shorebird_cli/src/os/operating_system_interface.dart';
import 'package:shorebird_cli/src/platform.dart';
import 'package:shorebird_cli/src/process.dart';
import 'package:shorebird_cli/src/shorebird_build_mixin.dart';
Expand Down Expand Up @@ -59,6 +60,7 @@ void main() {
late CodePushClientWrapper codePushClientWrapper;
late Directory shorebirdRoot;
late Java java;
late OperatingSystemInterface operatingSystemInterface;
late Platform platform;
late Progress progress;
late Logger logger;
Expand All @@ -78,6 +80,7 @@ void main() {
engineConfigRef.overrideWith(() => const EngineConfig.empty()),
javaRef.overrideWith(() => java),
loggerRef.overrideWith(() => logger),
osInterfaceRef.overrideWith(() => operatingSystemInterface),
platformRef.overrideWith(() => platform),
processRef.overrideWith(() => shorebirdProcess),
shorebirdEnvRef.overrideWith(() => shorebirdEnv),
Expand Down Expand Up @@ -129,6 +132,7 @@ void main() {
auth = MockAuth();
codePushClientWrapper = MockCodePushClientWrapper();
java = MockJava();
operatingSystemInterface = MockOperatingSystemInterface();
platform = MockPlatform();
progress = MockProgress();
logger = MockLogger();
Expand All @@ -146,6 +150,8 @@ void main() {
when(() => auth.isAuthenticated).thenReturn(true);
when(() => logger.confirm(any())).thenReturn(true);
when(() => logger.progress(any())).thenReturn(progress);
when(() => operatingSystemInterface.which('flutter'))
.thenReturn('/path/to/flutter');

when(() => shorebirdEnv.getShorebirdYaml()).thenReturn(shorebirdYaml);
when(() => shorebirdEnv.shorebirdRoot).thenReturn(shorebirdRoot);
Expand Down
Loading