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_code_push_protocol): add canSideload field to CreateReleaseArtifactRequest and add support to CLI #1274

Merged
merged 7 commits into from
Sep 18, 2023
8 changes: 8 additions & 0 deletions packages/shorebird_cli/lib/src/code_push_client_wrapper.dart
Original file line number Diff line number Diff line change
Expand Up @@ -386,6 +386,7 @@ Please create a release using "shorebird release" and try again.
arch: archMetadata.arch,
platform: platform,
hash: hash,
canSideload: false,
);
} on CodePushConflictException catch (_) {
// Newlines are due to how logger.info interacts with logger.progress.
Expand All @@ -412,6 +413,7 @@ ${archMetadata.arch} artifact already exists, continuing...''',
arch: 'aab',
platform: platform,
hash: sha256.convert(await File(aabPath).readAsBytes()).toString(),
canSideload: true,
);
} on CodePushConflictException catch (_) {
// Newlines are due to how logger.info interacts with logger.progress.
Expand Down Expand Up @@ -460,6 +462,7 @@ aab artifact already exists, continuing...''',
arch: archMetadata.arch,
platform: platform,
hash: hash,
canSideload: false,
);
} on CodePushConflictException catch (_) {
// Newlines are due to how logger.info interacts with logger.progress.
Expand All @@ -486,6 +489,7 @@ ${archMetadata.arch} artifact already exists, continuing...''',
arch: 'aar',
platform: platform,
hash: sha256.convert(await File(aarPath).readAsBytes()).toString(),
canSideload: false,
);
} on CodePushConflictException catch (_) {
// Newlines are due to how logger.info interacts with logger.progress.
Expand Down Expand Up @@ -527,6 +531,7 @@ aar artifact already exists, continuing...''',
required int releaseId,
required String xcarchivePath,
required String runnerPath,
required bool isCodesigned,
}) async {
final createArtifactProgress = logger.progress('Creating artifacts');
final thinnedArchiveDirectory =
Expand All @@ -540,6 +545,7 @@ aar artifact already exists, continuing...''',
arch: 'xcarchive',
platform: ReleasePlatform.ios,
hash: sha256.convert(await zippedArchive.readAsBytes()).toString(),
canSideload: false,
);
} catch (error) {
_handleErrorAndExit(
Expand All @@ -558,6 +564,7 @@ aar artifact already exists, continuing...''',
arch: 'runner',
platform: ReleasePlatform.ios,
hash: sha256.convert(await zippedRunner.readAsBytes()).toString(),
canSideload: isCodesigned,
);
} catch (error) {
_handleErrorAndExit(
Expand Down Expand Up @@ -593,6 +600,7 @@ aar artifact already exists, continuing...''',
hash: sha256
.convert(await zippedAppFrameworkFile.readAsBytes())
.toString(),
canSideload: false,
);
} catch (error) {
_handleErrorAndExit(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,7 @@ ${summary.join('\n')}
releaseId: release.id,
xcarchivePath: archivePath,
runnerPath: runnerPath,
isCodesigned: codesign,
);

await codePushClientWrapper.updateReleaseStatus(
Expand Down
27 changes: 27 additions & 0 deletions packages/shorebird_cli/test/src/code_push_client_wrapper_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -994,6 +994,7 @@ Please bump your version number and try again.''',
arch: any(named: 'arch'),
platform: any(named: 'platform'),
hash: any(named: 'hash'),
canSideload: any(named: 'canSideload'),
),
).thenAnswer((_) async => {});
});
Expand All @@ -1008,6 +1009,7 @@ Please bump your version number and try again.''',
arch: any(named: 'arch'),
platform: any(named: 'platform'),
hash: any(named: 'hash'),
canSideload: any(named: 'canSideload'),
),
).thenThrow(error);
final tempDir = setUpTempDir();
Expand Down Expand Up @@ -1041,6 +1043,7 @@ Please bump your version number and try again.''',
arch: any(named: 'arch'),
platform: any(named: 'platform'),
hash: any(named: 'hash'),
canSideload: any(named: 'canSideload'),
),
).thenThrow(error);
final tempDir = setUpTempDir();
Expand Down Expand Up @@ -1075,6 +1078,7 @@ Please bump your version number and try again.''',
arch: any(named: 'arch'),
platform: any(named: 'platform'),
hash: any(named: 'hash'),
canSideload: any(named: 'canSideload'),
),
).thenThrow(const CodePushConflictException(message: error));
final tempDir = setUpTempDir();
Expand Down Expand Up @@ -1111,6 +1115,7 @@ Please bump your version number and try again.''',
arch: any(named: 'arch'),
platform: any(named: 'platform'),
hash: any(named: 'hash'),
canSideload: any(named: 'canSideload'),
),
).thenThrow(const CodePushConflictException(message: error));
final tempDir = setUpTempDir();
Expand Down Expand Up @@ -1145,6 +1150,7 @@ Please bump your version number and try again.''',
arch: any(named: 'arch'),
platform: any(named: 'platform'),
hash: any(named: 'hash'),
canSideload: any(named: 'canSideload'),
),
).thenAnswer((_) async => {});
final tempDir = setUpTempDir();
Expand Down Expand Up @@ -1176,6 +1182,7 @@ Please bump your version number and try again.''',
arch: any(named: 'arch'),
platform: any(named: 'platform'),
hash: any(named: 'hash'),
canSideload: any(named: 'canSideload'),
),
).thenAnswer((_) async => {});
final tempDir = setUpTempDir(flavor: flavorName);
Expand Down Expand Up @@ -1205,6 +1212,7 @@ Please bump your version number and try again.''',
arch: any(named: 'arch'),
platform: releasePlatform,
hash: any(named: 'hash'),
canSideload: any(named: 'canSideload'),
),
).called(ShorebirdBuildMixin.allAndroidArchitectures.length);
verify(() => progress.complete()).called(1);
Expand Down Expand Up @@ -1255,6 +1263,7 @@ Please bump your version number and try again.''',
arch: any(named: 'arch'),
platform: any(named: 'platform'),
hash: any(named: 'hash'),
canSideload: any(named: 'canSideload'),
),
).thenAnswer((_) async => {});
});
Expand All @@ -1269,6 +1278,7 @@ Please bump your version number and try again.''',
arch: any(named: 'arch'),
platform: any(named: 'platform'),
hash: any(named: 'hash'),
canSideload: any(named: 'canSideload'),
),
).thenThrow(error);
final tempDir = setUpTempDir();
Expand Down Expand Up @@ -1304,6 +1314,7 @@ Please bump your version number and try again.''',
arch: any(named: 'arch'),
platform: any(named: 'platform'),
hash: any(named: 'hash'),
canSideload: any(named: 'canSideload'),
),
).thenThrow(error);
final tempDir = setUpTempDir();
Expand Down Expand Up @@ -1340,6 +1351,7 @@ Please bump your version number and try again.''',
arch: any(named: 'arch'),
platform: any(named: 'platform'),
hash: any(named: 'hash'),
canSideload: any(named: 'canSideload'),
),
).thenThrow(const CodePushConflictException(message: error));
final tempDir = setUpTempDir();
Expand Down Expand Up @@ -1378,6 +1390,7 @@ Please bump your version number and try again.''',
arch: any(named: 'arch'),
platform: any(named: 'platform'),
hash: any(named: 'hash'),
canSideload: any(named: 'canSideload'),
),
).thenThrow(const CodePushConflictException(message: error));
final tempDir = setUpTempDir();
Expand Down Expand Up @@ -1414,6 +1427,7 @@ Please bump your version number and try again.''',
arch: any(named: 'arch'),
platform: any(named: 'platform'),
hash: any(named: 'hash'),
canSideload: any(named: 'canSideload'),
),
).thenAnswer((_) async => {});
final tempDir = setUpTempDir();
Expand Down Expand Up @@ -1447,6 +1461,7 @@ Please bump your version number and try again.''',
arch: any(named: 'arch'),
platform: any(named: 'platform'),
hash: any(named: 'hash'),
canSideload: any(named: 'canSideload'),
),
).thenAnswer((_) async => {});
final tempDir = setUpTempDir(flavor: flavorName);
Expand Down Expand Up @@ -1474,6 +1489,7 @@ Please bump your version number and try again.''',
arch: any(named: 'arch'),
platform: releasePlatform,
hash: any(named: 'hash'),
canSideload: any(named: 'canSideload'),
),
).called(ShorebirdBuildMixin.allAndroidArchitectures.length + 1);
verify(() => progress.complete()).called(1);
Expand Down Expand Up @@ -1503,6 +1519,7 @@ Please bump your version number and try again.''',
arch: any(named: 'arch'),
platform: any(named: 'platform'),
hash: any(named: 'hash'),
canSideload: any(named: 'canSideload'),
),
).thenAnswer((_) async => {});
});
Expand All @@ -1519,6 +1536,7 @@ Please bump your version number and try again.''',
arch: any(named: 'arch'),
platform: any(named: 'platform'),
hash: any(named: 'hash'),
canSideload: any(named: 'canSideload'),
),
).thenThrow(error);
final tempDir = setUpTempDir();
Expand All @@ -1531,6 +1549,7 @@ Please bump your version number and try again.''',
releaseId: releaseId,
xcarchivePath: p.join(tempDir.path, xcarchivePath),
runnerPath: p.join(tempDir.path, runnerPath),
isCodesigned: true,
),
),
exitsWithCode(ExitCode.software),
Expand All @@ -1553,6 +1572,7 @@ Please bump your version number and try again.''',
arch: any(named: 'arch'),
platform: any(named: 'platform'),
hash: any(named: 'hash'),
canSideload: any(named: 'canSideload'),
),
).thenThrow(const CodePushConflictException(message: error));
final tempDir = setUpTempDir();
Expand All @@ -1565,6 +1585,7 @@ Please bump your version number and try again.''',
releaseId: releaseId,
xcarchivePath: p.join(tempDir.path, xcarchivePath),
runnerPath: p.join(tempDir.path, runnerPath),
isCodesigned: false,
),
),
exitsWithCode(ExitCode.software),
Expand All @@ -1589,6 +1610,7 @@ Please bump your version number and try again.''',
arch: any(named: 'arch'),
platform: any(named: 'platform'),
hash: any(named: 'hash'),
canSideload: any(named: 'canSideload'),
),
).thenThrow(error);
final tempDir = setUpTempDir();
Expand All @@ -1601,6 +1623,7 @@ Please bump your version number and try again.''',
releaseId: releaseId,
xcarchivePath: p.join(tempDir.path, xcarchivePath),
runnerPath: p.join(tempDir.path, runnerPath),
isCodesigned: false,
),
),
exitsWithCode(ExitCode.software),
Expand All @@ -1620,6 +1643,7 @@ Please bump your version number and try again.''',
arch: any(named: 'arch'),
platform: any(named: 'platform'),
hash: any(named: 'hash'),
canSideload: any(named: 'canSideload'),
),
).thenAnswer((_) async => {});
final tempDir = setUpTempDir();
Expand All @@ -1631,6 +1655,7 @@ Please bump your version number and try again.''',
releaseId: releaseId,
xcarchivePath: p.join(tempDir.path, xcarchivePath),
runnerPath: p.join(tempDir.path, runnerPath),
isCodesigned: true,
),
getCurrentDirectory: () => tempDir,
),
Expand Down Expand Up @@ -1661,6 +1686,7 @@ Please bump your version number and try again.''',
arch: any(named: 'arch'),
platform: any(named: 'platform'),
hash: any(named: 'hash'),
canSideload: any(named: 'canSideload'),
),
).thenThrow(
Exception('oh no'),
Expand Down Expand Up @@ -1689,6 +1715,7 @@ Please bump your version number and try again.''',
arch: any(named: 'arch'),
platform: any(named: 'platform'),
hash: any(named: 'hash'),
canSideload: any(named: 'canSideload'),
),
).thenAnswer((_) async => {});
final tempDir = setUpTempDir();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,7 @@ flutter:
releaseId: any(named: 'releaseId'),
xcarchivePath: any(named: 'xcarchivePath'),
runnerPath: any(named: 'runnerPath'),
isCodesigned: any(named: 'isCodesigned'),
),
).thenAnswer((_) async => release);
when(
Expand Down Expand Up @@ -393,6 +394,27 @@ flutter:
),
).called(1);
});

test('creates unsigned release artifacts', () async {
final tempDir = setUpTempDir();
final result = await IOOverrides.runZoned(
() => runWithOverrides(command.run),
getCurrentDirectory: () => tempDir,
);

expect(result, equals(ExitCode.success.code));

verify(
() => codePushClientWrapper.createIosReleaseArtifacts(
appId: appId,
releaseId: release.id,
xcarchivePath:
any(named: 'xcarchivePath', that: endsWith('.xcarchive')),
runnerPath: any(named: 'runnerPath', that: endsWith('Runner.app')),
isCodesigned: false,
),
).called(1);
});
});

test('exits with code 70 when build fails with non-zero exit code',
Expand Down Expand Up @@ -495,6 +517,7 @@ error: exportArchive: No signing certificate "iOS Distribution" found
xcarchivePath:
any(named: 'xcarchivePath', that: endsWith('.xcarchive')),
runnerPath: any(named: 'runnerPath', that: endsWith('Runner.app')),
isCodesigned: any(named: 'isCodesigned'),
),
);
});
Expand Down Expand Up @@ -666,6 +689,7 @@ error: exportArchive: No signing certificate "iOS Distribution" found
xcarchivePath:
any(named: 'xcarchivePath', that: endsWith('.xcarchive')),
runnerPath: any(named: 'runnerPath', that: endsWith('Runner.app')),
isCodesigned: true,
),
).called(1);
verify(
Expand Down Expand Up @@ -738,6 +762,7 @@ flavors:
xcarchivePath:
any(named: 'xcarchivePath', that: endsWith('.xcarchive')),
runnerPath: any(named: 'runnerPath', that: endsWith('Runner.app')),
isCodesigned: true,
),
).called(1);
expect(exitCode, ExitCode.success.code);
Expand Down Expand Up @@ -774,6 +799,7 @@ flavors:
xcarchivePath:
any(named: 'xcarchivePath', that: endsWith('.xcarchive')),
runnerPath: any(named: 'runnerPath', that: endsWith('Runner.app')),
isCodesigned: true,
),
).called(1);
verify(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -313,6 +313,7 @@ flutter:
xcarchivePath:
any(named: 'xcarchivePath', that: endsWith('.xcarchive')),
runnerPath: any(named: 'runnerPath', that: endsWith('Runner.app')),
isCodesigned: any(named: 'isCodesigned'),
),
);
});
Expand Down
1 change: 1 addition & 0 deletions packages/shorebird_code_push_client/example/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ Future<void> main() async {
artifactPath: '<PATH TO ARTIFACT>', // e.g. 'libapp.so'
arch: '<ARCHITECTURE>', // e.g. 'aarch64'
hash: '<HASH>', // 'sha256 hash of the artifact'
canSideload: true,
);

// Create a new patch.
Expand Down
Loading