Skip to content

Commit

Permalink
feat: support codesigning for macos apps (#2771)
Browse files Browse the repository at this point in the history
  • Loading branch information
bryanoltman authored Jan 15, 2025
1 parent 9242b9e commit cae0c0f
Show file tree
Hide file tree
Showing 8 changed files with 24 additions and 98 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,6 @@ class AndroidReleaser extends Releaser {

@override
Future<void> assertArgsAreValid() async {
argResults.assertAbsentOrValidPublicKey();

if (argResults.wasParsed('release-version')) {
logger.err(
'''
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,6 @@ class IosReleaser extends Releaser {

@override
Future<void> assertArgsAreValid() async {
argResults.assertAbsentOrValidPublicKey();

if (argResults.wasParsed('release-version')) {
logger.err(
'''
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,7 @@ of the iOS app that is using this module. (aar and ios-framework only)''',
@visibleForTesting
Future<void> createRelease(Releaser releaser) async {
await releaser.assertPreconditions();
await assertArgsAreValid();
await releaser.assertArgsAreValid();

await shorebirdValidator.validateFlavors(flavorArg: flavor);
Expand Down Expand Up @@ -327,6 +328,11 @@ of the iOS app that is using this module. (aar and ios-framework only)''',
);
}

/// Validates arguments that are common to all release types.
Future<void> assertArgsAreValid() async {
results.assertAbsentOrValidPublicKey();
}

/// Determines which Flutter version to use for the release. This will be
/// either the version specified by the user or the version provided by
/// [shorebirdEnv]. Will exit with [ExitCode.software] if the version
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,6 @@ class WindowsReleaser extends Releaser {

@override
Future<void> assertArgsAreValid() async {
argResults.assertAbsentOrValidPublicKey();

if (argResults.wasParsed('release-version')) {
logger.err(
'''
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -235,45 +235,6 @@ To change the version of this release, change your app's version in your pubspec
);
});
});

group('when a public key is provided and it exists', () {
setUp(() {
when(() => argResults['artifact']).thenReturn('apk');
final publicKeyFile = File(
p.join(
Directory.systemTemp.createTempSync().path,
'public-key.pem',
),
)..writeAsStringSync('public key');
when(() => argResults[CommonArguments.publicKeyArg.name])
.thenReturn(publicKeyFile.path);
});

test('returns normally', () async {
expect(
() => runWithOverrides(androidReleaser.assertArgsAreValid),
returnsNormally,
);
});
});

group('when a public key is provided but does not exist', () {
setUp(() {
when(() => argResults['artifact']).thenReturn('apk');
when(() => argResults[CommonArguments.publicKeyArg.name])
.thenReturn('non-existing-key.pem');
});

test('logs and exits with usage err', () async {
await expectLater(
() => runWithOverrides(androidReleaser.assertArgsAreValid),
exitsWithCode(ExitCode.usage),
);

verify(() => logger.err('No file found at non-existing-key.pem'))
.called(1);
});
});
});

group('buildReleaseArtifacts', () {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -278,43 +278,6 @@ To change the version of this release, change your app's version in your pubspec
);
});
});

group('when a public key is provided and it exists', () {
setUp(() {
final publicKeyFile = File(
p.join(
Directory.systemTemp.createTempSync().path,
'public-key.pem',
),
)..writeAsStringSync('public key');
when(() => argResults[CommonArguments.publicKeyArg.name])
.thenReturn(publicKeyFile.path);
});

test('returns normally', () async {
expect(
() => runWithOverrides(iosReleaser.assertArgsAreValid),
returnsNormally,
);
});
});

group('when the provided public key is a nonexistent file', () {
setUp(() {
when(() => argResults[CommonArguments.publicKeyArg.name])
.thenReturn('non-existing-key.pem');
});

test('logs and exits with usage err', () async {
await expectLater(
() => runWithOverrides(iosReleaser.assertArgsAreValid),
exitsWithCode(ExitCode.usage),
);

verify(() => logger.err('No file found at non-existing-key.pem'))
.called(1);
});
});
});

group('buildReleaseArtifacts', () {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,24 @@ void main() {
});
});

group('when public key path is provided but no key exists', () {
setUp(() {
when(() => argResults[CommonArguments.publicKeyArg.name])
.thenReturn('/path/to/nonexistent/file');
});

test('exits with usage code', () async {
await expectLater(
runWithOverrides(command.run),
exitsWithCode(ExitCode.usage),
);

verifyNever(
() => codePushClientWrapper.getApp(appId: any(named: 'appId')),
);
});
});

test('executes commands in order, completes successfully', () async {
final exitCode = await runWithOverrides(command.run);
expect(exitCode, equals(ExitCode.success.code));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -151,22 +151,6 @@ To change the version of this release, change your app's version in your pubspec
).called(1);
});
});

group('when public key is provided but file does not exist', () {
setUp(() {
when(() => argResults.wasParsed(CommonArguments.publicKeyArg.name))
.thenReturn(true);
when(() => argResults[CommonArguments.publicKeyArg.name])
.thenReturn('nonexistent');
});

test('fails progress, exits', () async {
await expectLater(
() => runWithOverrides(releaser.assertArgsAreValid),
exitsWithCode(ExitCode.usage),
);
});
});
});

group('assertPreconditions', () {
Expand Down

0 comments on commit cae0c0f

Please sign in to comment.