Skip to content

Commit

Permalink
Add public key to windows shorebird.yaml if found (#71)
Browse files Browse the repository at this point in the history
* Add public key to windows shorebird.yaml if found

* Tests
  • Loading branch information
bryanoltman authored Jan 15, 2025
1 parent a0e228f commit 39dff68
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 0 deletions.
16 changes: 16 additions & 0 deletions packages/flutter_tools/lib/src/windows/build_windows.dart
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import '../flutter_plugins.dart';
import '../globals.dart' as globals;
import '../migrations/cmake_custom_command_migration.dart';
import '../migrations/cmake_native_assets_migration.dart';
import '../shorebird/shorebird_yaml.dart';
import 'migrations/build_architecture_migration.dart';
import 'migrations/show_window_migration.dart';
import 'migrations/version_migration.dart';
Expand Down Expand Up @@ -127,6 +128,21 @@ Future<void> buildWindows(
'Built ${globals.fs.path.relative(buildOutput.path)}',
color: TerminalColor.green,
);
final File shorebirdYamlFile = buildDirectory
.childDirectory('runner')
.childDirectory(sentenceCase(buildModeName))
.childDirectory('data')
.childDirectory('flutter_assets')
.childFile('shorebird.yaml');

if (shorebirdYamlFile.existsSync()) {
try {
updateShorebirdYaml(buildInfo, shorebirdYamlFile.path, environment: globals.platform.environment);
} on Exception catch (error) {
globals.printError('[shorebird] failed to generate shorebird configuration.\n$error');
throw Exception('Failed to generate shorebird configuration');
}
}

if (buildInfo.codeSizeDirectory != null && sizeAnalyzer != null) {
final String arch = getNameForTargetPlatform(targetPlatform);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,15 @@ final Platform windowsPlatform = FakePlatform(
'USERPROFILE': '/',
}
);
final Platform windowsPlatformWithPublicKey = FakePlatform(
operatingSystem: 'windows',
environment: <String, String>{
'PROGRAMFILES(X86)': r'C:\Program Files (x86)\',
'FLUTTER_ROOT': flutterRoot,
'USERPROFILE': '/',
'SHOREBIRD_PUBLIC_KEY': 'my_public_key',
}
);
final Platform notWindowsPlatform = FakePlatform(
environment: <String, String>{
'FLUTTER_ROOT': flutterRoot,
Expand Down Expand Up @@ -1069,6 +1078,39 @@ No file or variants found for asset: images/a_dot_burr.jpeg.
Platform: () => windowsPlatform,
FeatureFlags: () => TestFeatureFlags(isWindowsEnabled: true),
});

testUsingContext(
'shorebird.yaml is updated when SHOREBIRD_PUBLIC_KEY env var is set',
() async {
final FakeVisualStudio fakeVisualStudio = FakeVisualStudio();
final BuildWindowsCommand command = BuildWindowsCommand(
logger: BufferLogger.test(),
operatingSystemUtils: FakeOperatingSystemUtils())
..visualStudioOverride = fakeVisualStudio;
setUpMockProjectFilesForBuild();
final File shorebirdYamlFile = fileSystem.file(
r'build\windows\x64\runner\Release\data\flutter_assets\shorebird.yaml',
)
..createSync(recursive: true)
..writeAsStringSync('app_id: my-app-id');

processManager = FakeProcessManager.list(<FakeCommand>[
cmakeGenerationCommand(),
buildCommand('Release'),
]);

await createTestCommandRunner(command)
.run(const <String>['windows', '--release', '--no-pub']);

final String updatedYaml = shorebirdYamlFile.readAsStringSync();
expect(updatedYaml, contains('app_id: my-app-id'));
expect(updatedYaml, contains('patch_public_key: my_public_key'));
}, overrides: <Type, Generator>{
FileSystem: () => fileSystem,
ProcessManager: () => processManager,
Platform: () => windowsPlatformWithPublicKey,
FeatureFlags: () => TestFeatureFlags(isWindowsEnabled: true),
});
}

class FakeVisualStudio extends Fake implements VisualStudio {
Expand Down

0 comments on commit 39dff68

Please sign in to comment.