feat(shorebird_cli): shorebird release android --artifact apk (#702)

This commit is contained in:
Felix Angelov
2023-06-23 10:06:21 -05:00
committed by GitHub
parent b511b09f77
commit de4c1a3cef
2 changed files with 40 additions and 2 deletions
@@ -41,6 +41,16 @@ class ReleaseAndroidCommand extends ShorebirdCommand
'flavor',
help: 'The product flavor to use when building the app.',
)
..addOption(
'artifact',
help: 'They type of artifact to generate.',
allowed: ['aab', 'apk'],
defaultsTo: 'aab',
allowedHelp: {
'aab': 'Android App Bundle',
'apk': 'Android Package Kit',
},
)
..addFlag(
'force',
abbr: 'f',
@@ -74,9 +84,11 @@ make smaller updates to your app.
const platformName = 'android';
final flavor = results['flavor'] as String?;
final target = results['target'] as String?;
final generateApk = results['artifact'] as String == 'apk';
final buildProgress = logger.progress('Building release');
try {
await buildAppBundle(flavor: flavor, target: target);
if (generateApk) await buildApk(flavor: flavor, target: target);
buildProgress.complete();
} on ProcessException catch (error) {
buildProgress.fail('Failed to build: ${error.message}');
@@ -92,6 +104,10 @@ make smaller updates to your app.
final bundlePath = flavor != null
? p.join(bundleDirPath, '${flavor}Release', 'app-$flavor-release.aab')
: p.join(bundleDirPath, 'release', 'app-release.aab');
final apkDirPath = p.join('build', 'app', 'outputs', 'apk');
final apkPath = flavor != null
? p.join(apkDirPath, flavor, 'release', 'app-$flavor-release.apk')
: p.join(apkDirPath, 'release', 'app-release.apk');
final String releaseVersion;
final detectReleaseVersionProgress = logger.progress(
@@ -176,8 +192,8 @@ ${summary.join('\n')}
..success('\n✅ Published Release!')
..info('''
Your next step is to upload the app bundle to the Play Store.
${lightCyan.wrap(bundlePath)}
Your next step is to upload the ${generateApk ? 'apk' : 'app bundle'} to the Play Store.
${lightCyan.wrap(generateApk ? apkPath : bundlePath)}
See the following link for more information:
${link(uri: Uri.parse('https://support.google.com/googleplay/android-developer/answer/9859152?hl=en'))}
@@ -172,6 +172,7 @@ flutter:
when(() => argResults.rest).thenReturn([]);
when(() => argResults['arch']).thenReturn(arch);
when(() => argResults['platform']).thenReturn(platformName);
when(() => argResults['artifact']).thenReturn('aab');
when(() => auth.isAuthenticated).thenReturn(true);
when(() => auth.client).thenReturn(httpClient);
when(() => cache.updateAll()).thenAnswer((_) async => {});
@@ -423,6 +424,27 @@ flutter:
expect(exitCode, ExitCode.success.code);
});
test('succeeds when release is successful (with apk)', () async {
when(() => argResults['artifact']).thenReturn('apk');
final tempDir = setUpTempDir();
final exitCode = await IOOverrides.runZoned(
() => runWithOverrides(command.run),
getCurrentDirectory: () => tempDir,
);
verify(() => logger.success('\n✅ Published Release!')).called(1);
verify(
() => codePushClientWrapper.createAndroidReleaseArtifacts(
releaseId: release.id,
platform: platformName,
aabPath: any(named: 'aabPath'),
architectures: any(named: 'architectures'),
),
).called(1);
expect(exitCode, ExitCode.success.code);
});
test(
'succeeds when release is successful '
'with flavors and target', () async {