Skip to content

Commit

Permalink
fix(shorebird_cli): flutter revision detection in shorebird patch (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
felangel authored Aug 3, 2023
1 parent d88ab07 commit 5f71c0d
Show file tree
Hide file tree
Showing 7 changed files with 10 additions and 133 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand Down Expand Up @@ -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('''
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand Down Expand Up @@ -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('''
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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('''
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,7 @@ void main() {
() => shorebirdEnv.androidPackageName,
).thenReturn(androidPackageName);
when(() => shorebirdEnv.getShorebirdYaml()).thenReturn(shorebirdYaml);
when(() => shorebirdEnv.flutterRevision).thenReturn(flutterRevision);
when(
() => shorebirdProcess.run(
'flutter',
Expand Down Expand Up @@ -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'),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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() {
Expand Down Expand Up @@ -140,7 +136,6 @@ flutter:
late ShorebirdFlutterValidator flutterValidator;
late ShorebirdProcess shorebirdProcess;
late ShorebirdValidator shorebirdValidator;
late ShorebirdVersionManager shorebirdVersionManager;
late PatchAndroidCommand command;

R runWithOverrides<R>(R Function() body) {
Expand All @@ -159,9 +154,6 @@ flutter:
platformRef.overrideWith(() => platform),
processRef.overrideWith(() => shorebirdProcess),
shorebirdValidatorRef.overrideWith(() => shorebirdValidator),
shorebirdVersionManagerRef.overrideWith(
() => shorebirdVersionManager,
),
},
);
}
Expand Down Expand Up @@ -226,7 +218,6 @@ flutter:
shorebirdEnv = _MockShorebirdEnv();
shorebirdProcess = _MockShorebirdProcess();
shorebirdValidator = _MockShorebirdValidator();
shorebirdVersionManager = _MockShorebirdVersionManager();
command = runWithOverrides(
() => PatchAndroidCommand(
archiveDiffer: archiveDiffer,
Expand All @@ -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',
Expand Down Expand Up @@ -356,9 +348,6 @@ flutter:
validators: any(named: 'validators'),
),
).thenAnswer((_) async {});
when(
() => shorebirdVersionManager.fetchCurrentGitHash(),
).thenAnswer((_) async => flutterRevision);
});

test('has a description', () {
Expand Down Expand Up @@ -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);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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() {
Expand Down Expand Up @@ -125,7 +121,6 @@ flutter:
late ShorebirdFlutterValidator flutterValidator;
late ShorebirdProcess shorebirdProcess;
late ShorebirdValidator shorebirdValidator;
late ShorebirdVersionManager shorebirdVersionManager;
late PatchIosCommand command;

R runWithOverrides<R>(R Function() body) {
Expand All @@ -140,9 +135,6 @@ flutter:
processRef.overrideWith(() => shorebirdProcess),
shorebirdEnvRef.overrideWith(() => shorebirdEnv),
shorebirdValidatorRef.overrideWith(() => shorebirdValidator),
shorebirdVersionManagerRef.overrideWith(
() => shorebirdVersionManager,
),
},
);
}
Expand Down Expand Up @@ -221,7 +213,6 @@ flutter:
flutterValidator = _MockShorebirdFlutterValidator();
shorebirdProcess = _MockShorebirdProcess();
shorebirdValidator = _MockShorebirdValidator();
shorebirdVersionManager = _MockShorebirdVersionManager();

when(() => argResults['arch']).thenReturn(arch);
when(() => argResults['dry-run']).thenReturn(false);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -287,9 +279,6 @@ flutter:
supportedOperatingSystems: any(named: 'supportedOperatingSystems'),
),
).thenAnswer((_) async {});
when(
() => shorebirdVersionManager.fetchCurrentGitHash(),
).thenAnswer((_) async => flutterRevision);

command = runWithOverrides(() => PatchIosCommand(ipaReader: ipaReader))
..testArgResults = argResults;
Expand Down Expand Up @@ -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);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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';
Expand Down Expand Up @@ -95,7 +91,6 @@ flutter:
late ShorebirdFlutterValidator flutterValidator;
late ShorebirdProcess shorebirdProcess;
late ShorebirdValidator shorebirdValidator;
late ShorebirdVersionManager shorebirdVersionManager;
late PatchIosFrameworkCommand command;

R runWithOverrides<R>(R Function() body) {
Expand All @@ -110,9 +105,6 @@ flutter:
processRef.overrideWith(() => shorebirdProcess),
shorebirdEnvRef.overrideWith(() => shorebirdEnv),
shorebirdValidatorRef.overrideWith(() => shorebirdValidator),
shorebirdVersionManagerRef.overrideWith(
() => shorebirdVersionManager,
),
},
);
}
Expand Down Expand Up @@ -180,7 +172,6 @@ flutter:
flutterValidator = _MockShorebirdFlutterValidator();
shorebirdProcess = _MockShorebirdProcess();
shorebirdValidator = _MockShorebirdValidator();
shorebirdVersionManager = _MockShorebirdVersionManager();

when(
() => shorebirdProcess.run(
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -241,9 +233,6 @@ flutter:
supportedOperatingSystems: any(named: 'supportedOperatingSystems'),
),
).thenAnswer((_) async {});
when(
() => shorebirdVersionManager.fetchCurrentGitHash(),
).thenAnswer((_) async => flutterRevision);

command = runWithOverrides(PatchIosFrameworkCommand.new)
..testArgResults = argResults;
Expand Down Expand Up @@ -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);

Expand Down

0 comments on commit 5f71c0d

Please sign in to comment.