Skip to content

Commit

Permalink
refactor: use ReleasePlatform type instead of String (#867)
Browse files Browse the repository at this point in the history
  • Loading branch information
bryanoltman authored Jul 18, 2023
1 parent 79da63f commit d5477db
Show file tree
Hide file tree
Showing 48 changed files with 248 additions and 177 deletions.
20 changes: 10 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 @@ -134,7 +134,7 @@ This app may not exist or you may not have permission to view it.''',
Future<void> ensureReleaseHasNoArtifacts({
required String appId,
required Release existingRelease,
required String platform,
required ReleasePlatform platform,
}) async {
logger.detail('Verifying ability to release');

Expand Down Expand Up @@ -228,7 +228,7 @@ Please create a release using "shorebird release" and try again.
required String appId,
required int releaseId,
required Map<Arch, ArchMetadata> architectures,
required String platform,
required ReleasePlatform platform,
}) async {
// TODO(bryanoltman): update this function to only make one call to
// getReleaseArtifacts.
Expand Down Expand Up @@ -265,7 +265,7 @@ Please create a release using "shorebird release" and try again.
required String appId,
required int releaseId,
required String arch,
required String platform,
required ReleasePlatform platform,
}) async {
final fetchReleaseArtifactProgress = logger.progress(
'Fetching $arch artifact',
Expand Down Expand Up @@ -295,7 +295,7 @@ Please create a release using "shorebird release" and try again.
required String appId,
required int releaseId,
required String arch,
required String platform,
required ReleasePlatform platform,
}) async {
final fetchReleaseArtifactProgress = logger.progress(
'Fetching $arch artifact',
Expand Down Expand Up @@ -327,7 +327,7 @@ Please create a release using "shorebird release" and try again.
Future<void> createAndroidReleaseArtifacts({
required String appId,
required int releaseId,
required String platform,
required ReleasePlatform platform,
required String aabPath,
required Map<Arch, ArchMetadata> architectures,
String? flavor,
Expand Down Expand Up @@ -400,7 +400,7 @@ aab artifact already exists, continuing...''',
Future<void> createAndroidArchiveReleaseArtifacts({
required String appId,
required int releaseId,
required String platform,
required ReleasePlatform platform,
required String aarPath,
required String extractedAarDir,
required Map<Arch, ArchMetadata> architectures,
Expand Down Expand Up @@ -479,7 +479,7 @@ aar artifact already exists, continuing...''',
releaseId: releaseId,
artifactPath: ipaPath,
arch: 'ipa',
platform: 'ios',
platform: ReleasePlatform.ios,
hash: sha256.convert(await ipaFile.readAsBytes()).toString(),
);
} catch (error) {
Expand All @@ -495,7 +495,7 @@ aar artifact already exists, continuing...''',
Future<void> completeRelease({
required String appId,
required int releaseId,
required String platform,
required ReleasePlatform platform,
}) async {
final completeReleaseProgress = logger.progress('Completing release');
try {
Expand Down Expand Up @@ -535,7 +535,7 @@ aar artifact already exists, continuing...''',
Future<void> createPatchArtifacts({
required String appId,
required Patch patch,
required String platform,
required ReleasePlatform platform,
required Map<Arch, PatchArtifactBundle> patchArtifactBundles,
}) async {
final createArtifactProgress = logger.progress('Uploading artifacts');
Expand Down Expand Up @@ -582,7 +582,7 @@ aar artifact already exists, continuing...''',
Future<void> publishPatch({
required String appId,
required int releaseId,
required String platform,
required ReleasePlatform platform,
required String channelName,
required Map<Arch, PatchArtifactBundle> patchArtifactBundles,
}) async {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ of the Android app that is using this module.''',
return ExitCode.success.code;
}

const platformName = 'android';
const platform = ReleasePlatform.android;
final channelName = results['channel'] as String;

final release = await codePushClientWrapper.getRelease(
Expand Down Expand Up @@ -194,14 +194,14 @@ https://github.com/shorebirdtech/shorebird/issues/472
appId: appId,
releaseId: release.id,
architectures: architectures,
platform: platformName,
platform: platform,
);

final releaseAarArtifact = await codePushClientWrapper.getReleaseArtifact(
appId: appId,
releaseId: release.id,
arch: 'aar',
platform: platformName,
platform: platform,
);

final downloadReleaseAarProgress = logger.progress(
Expand Down Expand Up @@ -280,7 +280,7 @@ https://github.com/shorebirdtech/shorebird/issues/472
if (flavor != null) '🍧 Flavor: ${lightCyan.wrap(flavor)}',
'📦 Release Version: ${lightCyan.wrap(releaseVersion)}',
'📺 Channel: ${lightCyan.wrap(channelName)}',
'''🕹️ Platform: ${lightCyan.wrap(platformName)} ${lightCyan.wrap('[${archMetadata.join(', ')}]')}''',
'''🕹️ Platform: ${lightCyan.wrap(platform.name)} ${lightCyan.wrap('[${archMetadata.join(', ')}]')}''',
];

logger.info(
Expand All @@ -305,7 +305,7 @@ ${summary.join('\n')}
await codePushClientWrapper.publishPatch(
appId: appId,
releaseId: release.id,
platform: platformName,
platform: platform,
channelName: channelName,
patchArtifactBundles: patchArtifactBundles,
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import 'package:shorebird_cli/src/shorebird_config_mixin.dart';
import 'package:shorebird_cli/src/shorebird_environment.dart';
import 'package:shorebird_cli/src/shorebird_release_version_mixin.dart';
import 'package:shorebird_cli/src/shorebird_validation_mixin.dart';
import 'package:shorebird_code_push_client/shorebird_code_push_client.dart';

/// {@template patch_android_command}
/// `shorebird patch android`
Expand Down Expand Up @@ -107,7 +108,7 @@ class PatchAndroidCommand extends ShorebirdCommand

await cache.updateAll();

const platformName = 'android';
const platform = ReleasePlatform.android;
final channelName = results['channel'] as String;
final flavor = results['flavor'] as String?;
final target = results['target'] as String?;
Expand Down Expand Up @@ -199,14 +200,14 @@ https://github.com/shorebirdtech/shorebird/issues/472
appId: app.appId,
releaseId: release.id,
architectures: architectures,
platform: platformName,
platform: platform,
);

final releaseAabArtifact = await codePushClientWrapper.getReleaseArtifact(
appId: app.appId,
releaseId: release.id,
arch: 'aab',
platform: platformName,
platform: platform,
);

final releaseArtifactPaths = <Arch, String>{};
Expand Down Expand Up @@ -321,7 +322,7 @@ https://github.com/shorebirdtech/shorebird/issues/472
if (flavor != null) '🍧 Flavor: ${lightCyan.wrap(flavor)}',
'📦 Release Version: ${lightCyan.wrap(releaseVersion)}',
'📺 Channel: ${lightCyan.wrap(channelName)}',
'''🕹️ Platform: ${lightCyan.wrap(platformName)} ${lightCyan.wrap('[${archMetadata.join(', ')}]')}''',
'''🕹️ Platform: ${lightCyan.wrap(platform.name)} ${lightCyan.wrap('[${archMetadata.join(', ')}]')}''',
];

logger.info(
Expand All @@ -346,7 +347,7 @@ ${summary.join('\n')}
await codePushClientWrapper.publishPatch(
appId: appId,
releaseId: release.id,
platform: platformName,
platform: platform,
channelName: channelName,
patchArtifactBundles: patchArtifactBundles,
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import 'package:shorebird_cli/src/shorebird_build_mixin.dart';
import 'package:shorebird_cli/src/shorebird_config_mixin.dart';
import 'package:shorebird_cli/src/shorebird_environment.dart';
import 'package:shorebird_cli/src/shorebird_validation_mixin.dart';
import 'package:shorebird_code_push_client/shorebird_code_push_client.dart';

/// {@template patch_ios_command}
/// `shorebird patch ios` command.
Expand Down Expand Up @@ -87,7 +88,7 @@ class PatchIosCommand extends ShorebirdCommand

const arch = 'aarch64';
const channelName = 'stable';
const platformName = 'ios';
const platform = ReleasePlatform.ios;
final force = results['force'] == true;
final dryRun = results['dry-run'] == true;
final flavor = results['flavor'] as String?;
Expand Down Expand Up @@ -204,7 +205,7 @@ https://github.com/shorebirdtech/shorebird/issues/472
if (flavor != null) '🍧 Flavor: ${lightCyan.wrap(flavor)}',
'📦 Release Version: ${lightCyan.wrap(releaseVersion)}',
'📺 Channel: ${lightCyan.wrap(channelName)}',
'''🕹️ Platform: ${lightCyan.wrap(platformName)} ${lightCyan.wrap('[$arch (${formatBytes(aotFileSize)})]')}''',
'''🕹️ Platform: ${lightCyan.wrap(platform.name)} ${lightCyan.wrap('[$arch (${formatBytes(aotFileSize)})]')}''',
];

logger.info(
Expand All @@ -231,7 +232,7 @@ ${summary.join('\n')}
await codePushClientWrapper.publishPatch(
appId: appId,
releaseId: release.id,
platform: platformName,
platform: platform,
channelName: channelName,
patchArtifactBundles: {
Arch.arm64: PatchArtifactBundle(
Expand Down
3 changes: 2 additions & 1 deletion packages/shorebird_cli/lib/src/commands/preview_command.dart
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import 'package:shorebird_cli/src/logger.dart';
import 'package:shorebird_cli/src/shorebird_config_mixin.dart';
import 'package:shorebird_cli/src/shorebird_validation_mixin.dart';
import 'package:shorebird_cli/src/third_party/flutter_tools/lib/flutter_tools.dart';
import 'package:shorebird_code_push_client/shorebird_code_push_client.dart';

/// {@template preview_command}
/// `shorebird preview` command.
Expand Down Expand Up @@ -49,7 +50,7 @@ class PreviewCommand extends ShorebirdCommand
return error.exitCode.code;
}

const platform = 'android';
const platform = ReleasePlatform.android;
final appId = results['app-id'] as String? ?? await promptForApp();

if (appId == null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import 'package:shorebird_cli/src/shorebird_config_mixin.dart';
import 'package:shorebird_cli/src/shorebird_environment.dart';
import 'package:shorebird_cli/src/shorebird_release_version_mixin.dart';
import 'package:shorebird_cli/src/shorebird_validation_mixin.dart';
import 'package:shorebird_code_push_client/shorebird_code_push_client.dart';

/// {@template release_aar_command}
/// `shorebird release aar`
Expand Down Expand Up @@ -86,7 +87,7 @@ make smaller updates to your app.
return ExitCode.config.code;
}

const platformName = 'android';
const platform = ReleasePlatform.android;
final flavor = results['flavor'] as String?;
final buildNumber = results['build-number'] as String;
final releaseVersion = results['release-version'] as String;
Expand All @@ -104,7 +105,7 @@ make smaller updates to your app.
await codePushClientWrapper.ensureReleaseHasNoArtifacts(
appId: app.appId,
existingRelease: existingRelease,
platform: platformName,
platform: platform,
);
}

Expand All @@ -124,7 +125,7 @@ make smaller updates to your app.
'''📱 App: ${lightCyan.wrap(app.displayName)} ${lightCyan.wrap('(${app.appId})')}''',
if (flavor != null) '🍧 Flavor: ${lightCyan.wrap(flavor)}',
'📦 Release Version: ${lightCyan.wrap(releaseVersion)}',
'''🕹️ Platform: ${lightCyan.wrap(platformName)} ${lightCyan.wrap('(${archNames.join(', ')})')}''',
'''🕹️ Platform: ${lightCyan.wrap(platform.name)} ${lightCyan.wrap('(${archNames.join(', ')})')}''',
];

logger.info('''
Expand Down Expand Up @@ -175,7 +176,7 @@ ${summary.join('\n')}
await codePushClientWrapper.createAndroidArchiveReleaseArtifacts(
appId: app.appId,
releaseId: release.id,
platform: platformName,
platform: platform,
aarPath: aarArtifactPath(
packageName: androidPackageName!,
buildNumber: buildNumber,
Expand All @@ -187,7 +188,7 @@ ${summary.join('\n')}
await codePushClientWrapper.completeRelease(
appId: app.appId,
releaseId: release.id,
platform: platformName,
platform: platform,
);

logger
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import 'package:shorebird_cli/src/shorebird_config_mixin.dart';
import 'package:shorebird_cli/src/shorebird_environment.dart';
import 'package:shorebird_cli/src/shorebird_release_version_mixin.dart';
import 'package:shorebird_cli/src/shorebird_validation_mixin.dart';
import 'package:shorebird_code_push_client/shorebird_code_push_client.dart';

/// {@template release_android_command}
/// `shorebird release android`
Expand Down Expand Up @@ -74,7 +75,7 @@ make smaller updates to your app.
return e.exitCode.code;
}

const platformName = 'android';
const platform = ReleasePlatform.android;
final flavor = results['flavor'] as String?;
final target = results['target'] as String?;
final generateApk = results['artifact'] as String == 'apk';
Expand Down Expand Up @@ -123,7 +124,7 @@ make smaller updates to your app.
await codePushClientWrapper.ensureReleaseHasNoArtifacts(
appId: app.appId,
existingRelease: existingRelease,
platform: platformName,
platform: platform,
);
}

Expand All @@ -132,7 +133,7 @@ make smaller updates to your app.
'''📱 App: ${lightCyan.wrap(app.displayName)} ${lightCyan.wrap('(${app.appId})')}''',
if (flavor != null) '🍧 Flavor: ${lightCyan.wrap(flavor)}',
'📦 Release Version: ${lightCyan.wrap(releaseVersion)}',
'''🕹️ Platform: ${lightCyan.wrap(platformName)} ${lightCyan.wrap('(${archNames.join(', ')})')}''',
'''🕹️ Platform: ${lightCyan.wrap(platform.name)} ${lightCyan.wrap('(${archNames.join(', ')})')}''',
];

logger.info('''
Expand Down Expand Up @@ -176,15 +177,15 @@ ${summary.join('\n')}
appId: app.appId,
releaseId: release.id,
aabPath: bundlePath,
platform: platformName,
platform: platform,
architectures: architectures,
flavor: flavor,
);

await codePushClientWrapper.completeRelease(
appId: app.appId,
releaseId: release.id,
platform: platformName,
platform: platform,
);

logger
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import 'package:shorebird_cli/src/shorebird_build_mixin.dart';
import 'package:shorebird_cli/src/shorebird_config_mixin.dart';
import 'package:shorebird_cli/src/shorebird_environment.dart';
import 'package:shorebird_cli/src/shorebird_validation_mixin.dart';
import 'package:shorebird_code_push_client/shorebird_code_push_client.dart';

/// {@template release_ios_command}
/// `shorebird release ios-preview`
Expand Down Expand Up @@ -72,7 +73,7 @@ make smaller updates to your app.
'''iOS support is in an experimental state and will not work without Flutter engine changes that have not yet been published.''',
);

const platformName = 'ios';
const platform = ReleasePlatform.ios;
final flavor = results['flavor'] as String?;
final shorebirdYaml = ShorebirdEnvironment.getShorebirdYaml()!;
final appId = shorebirdYaml.getAppId(flavor: flavor);
Expand Down Expand Up @@ -121,15 +122,15 @@ make smaller updates to your app.
await codePushClientWrapper.ensureReleaseHasNoArtifacts(
appId: app.appId,
existingRelease: existingRelease,
platform: platformName,
platform: platform,
);
}

final summary = [
'''📱 App: ${lightCyan.wrap(app.displayName)} ${lightCyan.wrap('($appId)')}''',
if (flavor != null) '🍧 Flavor: ${lightCyan.wrap(flavor)}',
'📦 Release Version: ${lightCyan.wrap(releaseVersion)}',
'''🕹️ Platform: ${lightCyan.wrap(platformName)}''',
'''🕹️ Platform: ${lightCyan.wrap(platform.name)}''',
];

logger.info('''
Expand Down Expand Up @@ -178,7 +179,7 @@ ${summary.join('\n')}
await codePushClientWrapper.completeRelease(
appId: app.appId,
releaseId: release.id,
platform: platformName,
platform: platform,
);

logger
Expand Down
Loading

0 comments on commit d5477db

Please sign in to comment.