Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(shorebird_cli): add ability to release with --no-codesign #1267

Merged
merged 18 commits into from
Sep 15, 2023
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
1 change: 1 addition & 0 deletions packages/shorebird_cli/lib/src/archive/archive.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export 'directory_archive.dart';
19 changes: 19 additions & 0 deletions packages/shorebird_cli/lib/src/archive/directory_archive.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import 'dart:isolate';

import 'package:archive/archive_io.dart';
import 'package:io/io.dart';
import 'package:path/path.dart' as p;
import 'package:shorebird_cli/src/third_party/flutter_tools/lib/flutter_tools.dart';

extension DirectoryArchive on Directory {
/// Copies this directory to a temporary directory and zips it.
Future<File> zipToTempFile() async {
final tempDir = await Directory.systemTemp.createTemp();
final outFile = File(p.join(tempDir.path, '${p.basename(path)}.zip'));
await Isolate.run(() {
copyPathSync(path, tempDir.path);
ZipFileEncoder().zipDirectory(tempDir, filename: outFile.path);
});
return outFile;
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export 'android_archive_differ.dart';
export 'file_set_diff.dart';
export 'ios_archive_differ.dart';
export 'ipa.dart';
export 'plist.dart';
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,13 @@ import 'package:shorebird_cli/src/archive_analysis/file_set_diff.dart';
class IosArchiveDiffer extends ArchiveDiffer {
String _hash(List<int> bytes) => sha256.convert(bytes).toString();

static const binaryFiles = {
'App.framework/App',
'Flutter.framework/Flutter',
static final binaryFilePatterns = {
RegExp(r'App.framework/App$'),
RegExp(r'Flutter.framework/Flutter$'),
};
static RegExp appRegex = RegExp(r'^Payload/[\w\-. ]+.app/[\w\- ]+$');
static RegExp appRegex = RegExp(
r'^Products/Applications/[\w\-. ]+.app/[\w\- ]+$',
);

/// Files that have been added, removed, or that have changed between the
/// archives at the two provided paths. This method will also unisgn mach-o
Expand Down Expand Up @@ -73,8 +75,8 @@ class IosArchiveDiffer extends ArchiveDiffer {
.where((file) => file.isFile)
.where(
(file) =>
file.name.endsWith('App.framework/App') ||
file.name.endsWith('Flutter.framework/Flutter') ||
binaryFilePatterns
.any((pattern) => pattern.hasMatch(file.name)) ||
appRegex.hasMatch(file.name),
)
.toList();
Expand All @@ -84,7 +86,7 @@ class IosArchiveDiffer extends ArchiveDiffer {
return ZipDecoder()
.decodeBuffer(InputFileStream(archivePath))
.files
.where((file) => file.isFile && p.extension(file.name) == '.car')
.where((file) => file.isFile && p.basename(file.name) == 'Assets.car')
.toList();
}

Expand All @@ -102,8 +104,7 @@ class IosArchiveDiffer extends ArchiveDiffer {
}

final outFile = File(outPath);
final hash = _hash(outFile.readAsBytesSync());
return hash;
return _hash(outFile.readAsBytesSync());
Copy link
Contributor

Choose a reason for hiding this comment

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

💯

}

/// Uses assetutil to write a json description of a .car file to disk and
Expand Down Expand Up @@ -148,7 +149,7 @@ class IosArchiveDiffer extends ArchiveDiffer {
/// The flutter_assets directory contains the assets listed in the assets
/// section of the pubspec.yaml file.
/// Assets.car is the compiled asset catalog(s) (.xcassets files).
return p.extension(filePath) == '.car' ||
return p.basename(filePath) == 'Assets.car' ||
p.split(filePath).contains('flutter_assets');
}

Expand Down
74 changes: 0 additions & 74 deletions packages/shorebird_cli/lib/src/archive_analysis/ipa.dart

This file was deleted.

47 changes: 47 additions & 0 deletions packages/shorebird_cli/lib/src/archive_analysis/plist.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import 'dart:io';

import 'package:propertylistserialization/propertylistserialization.dart';

class Plist {
Plist({required File file}) {
properties = PropertyListSerialization.propertyListWithString(
file.readAsStringSync(),
) as Map<String, Object>;
}

/// This key is a user-visible string for the version of the bundle. The
/// required format is three period-separated integers, such as 10.14.1. The
/// string can only contain numeric characters (0-9) and periods.
///
/// See https://developer.apple.com/documentation/bundleresources/information_property_list/cfbundleshortversionstring
static const releaseVersionKey = 'CFBundleShortVersionString';

/// The version of the build that identifies an iteration of the bundle.
///
/// See https://developer.apple.com/documentation/bundleresources/information_property_list/cfbundleversion
static const buildNumberKey = 'CFBundleVersion';

/// The Info.plist contained in .xcarchives has the following structure:
/// {
/// ApplicationProperties: {
/// CFBundleShortVersionString: "1.0.0",
/// CFBundleVersion: "1",
/// },
static const applicationPropertiesKey = 'ApplicationProperties';

late final Map<String, Object> properties;

String get versionNumber {
final applicationProperties =
properties[applicationPropertiesKey]! as Map<String, Object>;
final releaseVersion = applicationProperties[releaseVersionKey] as String?;
final buildNumber = applicationProperties[buildNumberKey] as String?;
if (releaseVersion == null) {
throw Exception('Could not determine release version');
}

return buildNumber == null
? releaseVersion
: '$releaseVersion+$buildNumber';
}
}
38 changes: 28 additions & 10 deletions packages/shorebird_cli/lib/src/code_push_client_wrapper.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,12 @@ import 'dart:isolate';
import 'package:archive/archive_io.dart';
import 'package:collection/collection.dart';
import 'package:crypto/crypto.dart';
import 'package:io/io.dart' as io;
import 'package:mason_logger/mason_logger.dart';
import 'package:meta/meta.dart';
import 'package:path/path.dart' as p;
import 'package:scoped/scoped.dart';
import 'package:shorebird_cli/src/archive/directory_archive.dart';
import 'package:shorebird_cli/src/auth/auth.dart';
import 'package:shorebird_cli/src/logger.dart';
import 'package:shorebird_cli/src/shorebird_build_mixin.dart';
Expand Down Expand Up @@ -503,35 +505,51 @@ aar artifact already exists, continuing...''',
createArtifactProgress.complete();
}

/// Uploads a release ipa to the Shorebird server.
/// Removes all .dylib files from the given .xcarchive to reduce the size of
/// the uploaded artifact.
Future<Directory> _thinXcarchive({required String xcarchivePath}) async {
final xcarchiveDirectoryName = p.basename(xcarchivePath);
final tempDir = Directory.systemTemp.createTempSync();
final thinnedArchiveDirectory =
Directory(p.join(tempDir.path, xcarchiveDirectoryName));
await io.copyPath(xcarchivePath, thinnedArchiveDirectory.path);
thinnedArchiveDirectory
.listSync(recursive: true)
.whereType<File>()
.where((file) => p.extension(file.path) == '.dylib')
.forEach((file) => file.deleteSync());
return thinnedArchiveDirectory;
}

/// Uploads a release .xcarchive and .app to the Shorebird server.
Future<void> createIosReleaseArtifacts({
required String appId,
required int releaseId,
required String ipaPath,
required String xcarchivePath,
required String runnerPath,
}) async {
final createArtifactProgress = logger.progress('Creating artifacts');
final ipaFile = File(ipaPath);
final thinnedArchiveDirectory =
await _thinXcarchive(xcarchivePath: xcarchivePath);
final zippedArchive = await thinnedArchiveDirectory.zipToTempFile();
try {
await codePushClient.createReleaseArtifact(
appId: appId,
releaseId: releaseId,
artifactPath: ipaPath,
arch: 'ipa',
artifactPath: zippedArchive.path,
arch: 'xcarchive',
platform: ReleasePlatform.ios,
hash: sha256.convert(await ipaFile.readAsBytes()).toString(),
hash: sha256.convert(await zippedArchive.readAsBytes()).toString(),
);
} catch (error) {
_handleErrorAndExit(
error,
progress: createArtifactProgress,
message: 'Error uploading ipa: $error',
message: 'Error uploading xcarchive: $error',
);
}

final runnerDirectory = Directory(runnerPath);
await Isolate.run(() => ZipFileEncoder().zipDirectory(runnerDirectory));
final zippedRunner = File('$runnerPath.zip');
final zippedRunner = await Directory(runnerPath).zipToTempFile();
try {
await codePushClient.createReleaseArtifact(
appId: appId,
Expand Down
Loading