Skip to content

Commit

Permalink
Extract logic to determine windows release path
Browse files Browse the repository at this point in the history
  • Loading branch information
bryanoltman committed Jan 8, 2025
1 parent a56f2ed commit 2bdda13
Show file tree
Hide file tree
Showing 6 changed files with 85 additions and 33 deletions.
15 changes: 15 additions & 0 deletions packages/shorebird_cli/lib/src/artifact_manager.dart
Original file line number Diff line number Diff line change
Expand Up @@ -347,6 +347,21 @@ class ArtifactManager {
.firstWhereOrNull((directory) => directory.path.endsWith('.app'));
}

/// Returns the build/ subdirectory contaning the compiled Windows exe.

Check warning on line 350 in packages/shorebird_cli/lib/src/artifact_manager.dart

View workflow job for this annotation

GitHub Actions / 🔤 Check Spelling / build

Unknown word (contaning)
Directory getWindowsReleaseDirectory() {
final projectRoot = shorebirdEnv.getShorebirdProjectRoot()!;
return Directory(
p.join(
projectRoot.path,
'build',
'windows',
'x64',
'runner',
'Release',
),
);
}

/// Returns the path to the .ipa file generated by `flutter build ipa`.
///
/// Returns null if:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,12 +102,7 @@ class WindowsPatcher extends Patcher {
}) async {
final createDiffProgress = logger.progress('Creating patch artifacts');
final patchArtifactPath = p.join(
projectRoot.path,
'build',
'windows',
'x64',
'runner',
'Release',
artifactManager.getWindowsReleaseDirectory().path,
'data',
'app.so',
);
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:platform/platform.dart';
import 'package:shorebird_cli/src/archive/archive.dart';
import 'package:shorebird_cli/src/artifact_builder.dart';
import 'package:shorebird_cli/src/artifact_manager.dart';
import 'package:shorebird_cli/src/code_push_client_wrapper.dart';
import 'package:shorebird_cli/src/commands/release/releaser.dart';
import 'package:shorebird_cli/src/doctor.dart';
Expand Down Expand Up @@ -120,16 +121,7 @@ For more information see: ${supportedFlutterVersionsUrl.toLink()}''',
required String appId,
}) async {
final projectRoot = shorebirdEnv.getShorebirdProjectRoot()!;
final releaseDir = Directory(
p.join(
projectRoot.path,
'build',
'windows',
'x64',
'runner',
'Release',
),
);
final releaseDir = artifactManager.getWindowsReleaseDirectory();

if (!releaseDir.existsSync()) {
logger.err('No release directory found at ${releaseDir.path}');
Expand All @@ -149,5 +141,6 @@ For more information see: ${supportedFlutterVersionsUrl.toLink()}''',
@override
String get postReleaseInstructions => '''
Windows executable created at TODO.''';
Windows executable created at ${artifactManager.getWindowsReleaseDirectory().path}.
''';
}
18 changes: 18 additions & 0 deletions packages/shorebird_cli/test/src/artifact_manager_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -803,6 +803,24 @@ void main() {
});
});

group('getWindowsReleaseDirectory', () {
test('returns correct path', () {
expect(
runWithOverrides(artifactManager.getWindowsReleaseDirectory).path,
equals(
p.join(
projectRoot.path,
'build',
'windows',
'x64',
'runner',
'Release',
),
),
);
});
});

group('getIpa', () {
group('when ipa build directory does not exist', () {
test('returns null', () {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -337,6 +337,7 @@ void main() {
const appId = 'app-id';
const releaseId = 42;

late Directory releaseDirectory;
late File releaseArtifact;
late File patchArtifact;
late File diffFile;
Expand All @@ -349,19 +350,28 @@ void main() {
diffFile = File(p.join(tempDir.path, 'diff.so'))
..createSync(recursive: true);

patchArtifact = File(
releaseDirectory = Directory(
p.join(
projectRoot.path,
'build',
'windows',
'x64',
'runner',
'Release',
),
)..createSync(recursive: true);

patchArtifact = File(
p.join(
releaseDirectory.path,
'data',
'app.so',
),
)..createSync(recursive: true);

when(
() => artifactManager.getWindowsReleaseDirectory(),
).thenReturn(releaseDirectory);
when(
() => artifactManager.extractZip(
zipFile: any(named: 'zipFile'),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ 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';
import 'package:shorebird_cli/src/code_push_client_wrapper.dart';
import 'package:shorebird_cli/src/commands/commands.dart';
import 'package:shorebird_cli/src/doctor.dart';
Expand All @@ -31,7 +32,9 @@ void main() {
group(WindowsReleaser, () {
late ArgResults argResults;
late ArtifactBuilder artifactBuilder;
late ArtifactManager artifactManager;
late CodePushClientWrapper codePushClientWrapper;
late Directory releaseDirectory;
late Doctor doctor;
late ShorebirdLogger logger;
late FlavorValidator flavorValidator;
Expand All @@ -49,6 +52,7 @@ void main() {
body,
values: {
artifactBuilderRef.overrideWith(() => artifactBuilder),
artifactManagerRef.overrideWith(() => artifactManager),
codePushClientWrapperRef.overrideWith(() => codePushClientWrapper),
doctorRef.overrideWith(() => doctor),
loggerRef.overrideWith(() => logger),
Expand All @@ -70,6 +74,7 @@ void main() {
setUp(() {
argResults = MockArgResults();
artifactBuilder = MockArtifactBuilder();
artifactManager = MockArtifactManager();
codePushClientWrapper = MockCodePushClientWrapper();
doctor = MockDoctor();
flavorValidator = MockFlavorValidator();
Expand All @@ -85,6 +90,21 @@ void main() {
when(() => argResults.rest).thenReturn([]);
when(() => argResults.wasParsed(any())).thenReturn(false);

releaseDirectory = Directory(
p.join(
projectRoot.path,
'build',
'windows',
'x63',
'runner',
'Release',
),
)..createSync(recursive: true);

when(
() => artifactManager.getWindowsReleaseDirectory(),
).thenReturn(releaseDirectory);

when(() => logger.progress(any())).thenReturn(progress);

when(
Expand Down Expand Up @@ -320,12 +340,16 @@ For more information see: ${supportedFlutterVersionsUrl.toLink()}''',
});

group('when release directory does not exist', () {
setUp(() {
releaseDirectory.deleteSync();
});

test('fails progress, exits', () async {
await expectLater(
() => runWithOverrides(
() => releaser.uploadReleaseArtifacts(
release: MockRelease(),
appId: 'appId',
release: release,
appId: appId,
),
),
exitsWithCode(ExitCode.software),
Expand All @@ -340,17 +364,6 @@ For more information see: ${supportedFlutterVersionsUrl.toLink()}''',

group('when release directory exists', () {
setUp(() {
Directory(
p.join(
projectRoot.path,
'build',
'windows',
'x64',
'runner',
'Release',
),
).createSync(recursive: true);

when(
() => codePushClientWrapper.createWindowsReleaseArtifacts(
appId: any(named: 'appId'),
Expand Down Expand Up @@ -382,8 +395,16 @@ For more information see: ${supportedFlutterVersionsUrl.toLink()}''',

group('postReleaseInstructions', () {
test('returns nonempty instructions', () {
final instructions = releaser.postReleaseInstructions;
expect(instructions, isNotEmpty);
final instructions = runWithOverrides(
() => releaser.postReleaseInstructions,
);
expect(
instructions,
equals('''
Windows executable created at ${artifactManager.getWindowsReleaseDirectory().path}.
'''),
);
});
});
});
Expand Down

0 comments on commit 2bdda13

Please sign in to comment.