Skip to content

Commit

Permalink
fix: enforce minimum iOS version on iOS framework release (#2560)
Browse files Browse the repository at this point in the history
  • Loading branch information
bryanoltman authored Oct 21, 2024
1 parent b8d91f0 commit 49fb548
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@ import 'package:shorebird_cli/src/executables/xcodebuild.dart';
import 'package:shorebird_cli/src/extensions/arg_results.dart';
import 'package:shorebird_cli/src/logger.dart';
import 'package:shorebird_cli/src/metadata/metadata.dart';
import 'package:shorebird_cli/src/platform/ios.dart';
import 'package:shorebird_cli/src/release_type.dart';
import 'package:shorebird_cli/src/shorebird_documentation.dart';
import 'package:shorebird_cli/src/shorebird_env.dart';
import 'package:shorebird_cli/src/shorebird_flutter.dart';
import 'package:shorebird_cli/src/shorebird_validator.dart';
Expand Down Expand Up @@ -62,6 +64,20 @@ class IosFrameworkReleaser extends Releaser {
} on PreconditionFailedException catch (e) {
throw ProcessExit(e.exitCode.code);
}

final flutterVersionArg = argResults['flutter-version'] as String?;
if (flutterVersionArg != null) {
final version =
await shorebirdFlutter.resolveFlutterVersion(flutterVersionArg);
if (version != null && version < minimumSupportedIosFlutterVersion) {
logger.err(
'''
iOS releases are not supported with Flutter versions older than $minimumSupportedIosFlutterVersion.
For more information see: ${supportedFlutterVersionsUrl.toLink()}''',
);
throw ProcessExit(ExitCode.usage.code);
}
}
}

@override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import 'package:mason_logger/mason_logger.dart';
import 'package:mocktail/mocktail.dart';
import 'package:path/path.dart' as p;
import 'package:platform/platform.dart';
import 'package:pub_semver/pub_semver.dart';
import 'package:scoped_deps/scoped_deps.dart';
import 'package:shorebird_cli/src/artifact_builder.dart';
import 'package:shorebird_cli/src/artifact_manager.dart';
Expand All @@ -16,7 +17,9 @@ import 'package:shorebird_cli/src/executables/executables.dart';
import 'package:shorebird_cli/src/logger.dart';
import 'package:shorebird_cli/src/metadata/metadata.dart';
import 'package:shorebird_cli/src/os/operating_system_interface.dart';
import 'package:shorebird_cli/src/platform/ios.dart';
import 'package:shorebird_cli/src/release_type.dart';
import 'package:shorebird_cli/src/shorebird_documentation.dart';
import 'package:shorebird_cli/src/shorebird_env.dart';
import 'package:shorebird_cli/src/shorebird_flutter.dart';
import 'package:shorebird_cli/src/shorebird_process.dart';
Expand Down Expand Up @@ -151,10 +154,14 @@ void main() {
});

group('assertPreconditions', () {
final flutterVersion = Version(3, 0, 0);

setUp(() {
when(
() => doctor.iosCommandValidators,
).thenReturn([flutterValidator]);
when(() => shorebirdFlutter.resolveFlutterVersion(any()))
.thenAnswer((_) async => flutterVersion);
when(flutterValidator.validate).thenAnswer((_) async => []);
});

Expand Down Expand Up @@ -219,6 +226,38 @@ void main() {
).called(1);
});
});

group('when specified flutter version is less than minimum', () {
setUp(() {
when(
() => shorebirdValidator.validatePreconditions(
checkUserIsAuthenticated:
any(named: 'checkUserIsAuthenticated'),
checkShorebirdInitialized:
any(named: 'checkShorebirdInitialized'),
validators: any(named: 'validators'),
supportedOperatingSystems:
any(named: 'supportedOperatingSystems'),
),
).thenAnswer((_) async {});
when(() => argResults['flutter-version']).thenReturn('3.0.0');
});

test('logs error and exits with code 64', () async {
await expectLater(
() => runWithOverrides(iosFrameworkReleaser.assertPreconditions),
exitsWithCode(ExitCode.usage),
);

verify(
() => logger.err(
'''
iOS releases are not supported with Flutter versions older than $minimumSupportedIosFlutterVersion.
For more information see: ${supportedFlutterVersionsUrl.toLink()}''',
),
).called(1);
});
});
});

group('buildReleaseArtifacts', () {
Expand Down

0 comments on commit 49fb548

Please sign in to comment.