Skip to content
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
6 changes: 6 additions & 0 deletions packages/flutter_tools/lib/src/ios/mac.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
// found in the LICENSE file.

import 'dart:async';
import 'dart:io';

import 'package:meta/meta.dart';
import 'package:process/process.dart';
Expand Down Expand Up @@ -589,6 +590,11 @@ Please file an issue at: https://github.com/shorebirdtech/shorebird/issues/new
if (autoUpdate != null) {
yamlContent.writeln('auto_update: $autoUpdate');
}

final String? shorebirdPublicKeyEnvVar = Platform.environment['SHOREBIRD_PUBLIC_KEY'];
Copy link
Author

Choose a reason for hiding this comment

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

There is probably an easier way to pass the key to ios since we edit the yaml in a dart context. But in order to keep it simple and consistent to android, I thought it would make since to do the same thing here too.

if (shorebirdPublicKeyEnvVar != null) {
yamlContent.writeln('patch_public_key: $shorebirdPublicKeyEnvVar');
}
shorebirdYaml.writeAsStringSync(yamlContent.toString(), flush: true);
}

Expand Down
7 changes: 4 additions & 3 deletions packages/shorebird_tests/test/android_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ void main() {

expect(projectDirectory.apkFile().existsSync(), isTrue);
expect(projectDirectory.shorebirdFile.existsSync(), isTrue);
expect(projectDirectory.getGeneratedAndroidShorebirdYaml(), completes);
});

group('when passing the public key through the environment variable', () {
Expand All @@ -25,7 +26,7 @@ void main() {
);

final generatedYaml =
await projectDirectory.getGeneratedShorebirdYaml();
await projectDirectory.getGeneratedAndroidShorebirdYaml();

expect(
generatedYaml.keys,
Expand All @@ -50,7 +51,7 @@ void main() {
await projectDirectory.runFlutterBuildApk(flavor: 'internal');

final generatedYaml =
await projectDirectory.getGeneratedShorebirdYaml(
await projectDirectory.getGeneratedAndroidShorebirdYaml(
flavor: 'internal',
);

Expand All @@ -74,7 +75,7 @@ void main() {
);

final generatedYaml =
await projectDirectory.getGeneratedShorebirdYaml(
await projectDirectory.getGeneratedAndroidShorebirdYaml(
flavor: 'internal',
);

Expand Down
50 changes: 50 additions & 0 deletions packages/shorebird_tests/test/ios_test.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
import 'package:test/test.dart';

import 'shorebird_tests.dart';

void main() {
group(
'shorebird ios projects',
() {
testWithShorebirdProject('can build', (projectDirectory) async {
await projectDirectory.runFlutterBuildIos();

expect(projectDirectory.iosArchiveFile().existsSync(), isTrue);
expect(projectDirectory.getGeneratedIoShorebirdYaml(), completes);
});

group('when passing the public key through the environment variable', () {
testWithShorebirdProject(
'adds the public key on top of the original file',
(projectDirectory) async {
final originalYaml = projectDirectory.shorebirdYaml;

const base64PublicKey = 'public_123';
await projectDirectory.runFlutterBuildIos(
environment: {
'SHOREBIRD_PUBLIC_KEY': base64PublicKey,
},
);

final generatedYaml =
await projectDirectory.getGeneratedIoShorebirdYaml();

expect(
generatedYaml.keys,
containsAll(originalYaml.keys),
);

print(generatedYaml);
expect(
generatedYaml['patch_public_key'],
equals(base64PublicKey),
);
},
);
});

// TODO(erickzanardo): Add tests for flavors.
},
testOn: 'mac-os',
);
}
64 changes: 53 additions & 11 deletions packages/shorebird_tests/test/shorebird_tests.dart
Original file line number Diff line number Diff line change
Expand Up @@ -63,24 +63,24 @@ Future<void> testWithShorebirdProject(String name,
),
)..createSync();

File(
path.join(
projectDirectory.path,
'shorebird.yaml',
),
).writeAsStringSync('''
app_id: 123
''');

try {
await _createFlutterProject(projectDirectory);

projectDirectory.pubspecFile.writeAsStringSync('''
${projectDirectory.pubspecFile.readAsStringSync()}

assets:
- shorebird.yaml
''');

File(
path.join(
projectDirectory.path,
'shorebird.yaml',
),
).writeAsStringSync('''
app_id: "123"
''');

await testFn(projectDirectory);
} finally {
projectDirectory.deleteSync(recursive: true);
Expand Down Expand Up @@ -177,6 +177,22 @@ $flavors
}
}

Future<void> runFlutterBuildIos({
Map<String, String>? environment,
}) async {
final result = await _runFlutterCommand(
// The projects used to test are generated on spot, to make it simpler we don't
// configure any apple accounts on it, so we skip code signing here.
['build', 'ipa', '--no-codesign'],
workingDirectory: this,
environment: environment,
);

if (result.exitCode != 0) {
throw Exception('Failed to run `flutter build ios`: ${result.stderr}');
}
}

File apkFile({String? flavor}) => File(
path.join(
this.path,
Expand All @@ -188,7 +204,17 @@ $flavors
),
);

Future<YamlMap> getGeneratedShorebirdYaml({String? flavor}) async {
Directory iosArchiveFile() => Directory(
path.join(
this.path,
'build',
'ios',
'archive',
'Runner.xcarchive',
),
);

Future<YamlMap> getGeneratedAndroidShorebirdYaml({String? flavor}) async {
final decodedBytes =
ZipDecoder().decodeBytes(apkFile(flavor: flavor).readAsBytesSync());

Expand All @@ -206,4 +232,20 @@ $flavors
).readAsStringSync();
return loadYaml(yamlString) as YamlMap;
}

Future<YamlMap> getGeneratedIoShorebirdYaml() async {
final yamlString = File(
path.join(
iosArchiveFile().path,
'Products',
'Applications',
'Runner.app',
'Frameworks',
'App.framework',
'flutter_assets',
'shorebird.yaml',
),
).readAsStringSync();
return loadYaml(yamlString) as YamlMap;
}
}