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): shorebird patch supports flavors #443

Merged
merged 1 commit into from
May 5, 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
31 changes: 24 additions & 7 deletions packages/shorebird_cli/lib/src/commands/patch_command.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import 'package:mason_logger/mason_logger.dart';
import 'package:path/path.dart' as p;
import 'package:shorebird_cli/src/auth_logger_mixin.dart';
import 'package:shorebird_cli/src/command.dart';
import 'package:shorebird_cli/src/config/shorebird_yaml.dart';
import 'package:shorebird_cli/src/formatters/formatters.dart';
import 'package:shorebird_cli/src/shorebird_build_mixin.dart';
import 'package:shorebird_cli/src/shorebird_config_mixin.dart';
Expand Down Expand Up @@ -75,6 +76,15 @@ class PatchCommand extends ShorebirdCommand
},
defaultsTo: 'stable',
)
..addOption(
'target',
abbr: 't',
help: 'The main entrypoint file of the application.',
)
..addOption(
'flavor',
help: 'The product flavor to use when building the app.',
)
..addFlag(
'force',
abbr: 'f',
Expand Down Expand Up @@ -125,9 +135,11 @@ class PatchCommand extends ShorebirdCommand

await cache.updateAll();

final flavor = results['flavor'] as String?;
final target = results['target'] as String?;
final buildProgress = logger.progress('Building patch');
try {
await buildAppBundle();
await buildAppBundle(flavor: flavor, target: target);
buildProgress.complete();
} on ProcessException catch (error) {
buildProgress.fail('Failed to build: ${error.message}');
Expand Down Expand Up @@ -155,7 +167,7 @@ class PatchCommand extends ShorebirdCommand
return ExitCode.software.code;
}

final appId = shorebirdYaml.appId;
final appId = shorebirdYaml.getAppId(flavor: flavor);
final app = apps.firstWhereOrNull((a) => a.id == appId);
if (app == null) {
logger.err(
Expand Down Expand Up @@ -259,7 +271,7 @@ Please create a release using "shorebird release" and try again.
'app',
'intermediates',
'stripped_native_libs',
'release',
flavor != null ? '${flavor}Release' : 'release',
'out',
'lib',
archMetadata.path,
Expand Down Expand Up @@ -291,15 +303,20 @@ Please create a release using "shorebird release" and try again.
return '$name ($size)';
});

final summary = [
'''📱 App: ${lightCyan.wrap(app.displayName)} ${lightCyan.wrap('(${app.id})')}''',
if (flavor != null) '🍧 Flavor: ${lightCyan.wrap(flavor)}',
'📦 Release Version: ${lightCyan.wrap(releaseVersion)}',
'📺 Channel: ${lightCyan.wrap(channelArg)}',
'''🕹️ Platform: ${lightCyan.wrap(platform)} ${lightCyan.wrap('[${archMetadata.join(', ')}]')}''',
];

logger.info(
'''

${styleBold.wrap(lightGreen.wrap('🚀 Ready to publish a new patch!'))}

📱 App: ${lightCyan.wrap(app.displayName)} ${lightCyan.wrap('(${app.id})')}
📦 Release Version: ${lightCyan.wrap(releaseVersion)}
📺 Channel: ${lightCyan.wrap(channelArg)}
🕹️ Platform: ${lightCyan.wrap(platform)} ${lightCyan.wrap('[${archMetadata.join(', ')}]')}
${summary.join('\n')}
''',
);

Expand Down
10 changes: 7 additions & 3 deletions packages/shorebird_cli/lib/src/commands/release_command.dart
Original file line number Diff line number Diff line change
Expand Up @@ -157,14 +157,18 @@ Did you forget to run "shorebird init"?''',
final archNames = architectures.keys.map(
(arch) => arch.name,
);
final summary = [
'''📱 App: ${lightCyan.wrap(app.displayName)} ${lightCyan.wrap('(${app.id})')}''',
if (flavor != null) '🍧 Flavor: ${lightCyan.wrap(flavor)}',
'📦 Release Version: ${lightCyan.wrap(releaseVersion)}',
'''🕹️ Platform: ${lightCyan.wrap(platform)} ${lightCyan.wrap('(${archNames.join(', ')})')}''',
];

logger.info('''

${styleBold.wrap(lightGreen.wrap('🚀 Ready to create a new release!'))}

📱 App: ${lightCyan.wrap(app.displayName)} ${lightCyan.wrap('(${app.id})')}
📦 Release Version: ${lightCyan.wrap(releaseVersion)}
🕹️ Platform: ${lightCyan.wrap(platform)} ${lightCyan.wrap('(${archNames.join(', ')})')}
${summary.join('\n')}
''');

final confirm = logger.confirm('Would you like to continue?');
Expand Down
28 changes: 26 additions & 2 deletions packages/shorebird_cli/test/src/commands/patch_command_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ flutter:
return tempDir;
}

void setUpTempArtifacts(Directory dir) {
void setUpTempArtifacts(Directory dir, {String? flavor}) {
for (final archMetadata
in ShorebirdBuildMixin.allAndroidArchitectures.values) {
final artifactPath = p.join(
Expand All @@ -116,7 +116,7 @@ flutter:
'app',
'intermediates',
'stripped_native_libs',
'release',
flavor != null ? '${flavor}Release' : 'release',
'out',
'lib',
archMetadata.path,
Expand Down Expand Up @@ -585,6 +585,30 @@ Please create a release using "shorebird release" and try again.
expect(capturedHostedUri, isNull);
});

test(
'succeeds when patch is successful '
'with flavors and target', () async {
const flavor = 'development';
const target = './lib/main_development.dart';
when(() => argResults['flavor']).thenReturn(flavor);
when(() => argResults['target']).thenReturn(target);
final tempDir = setUpTempDir();
File(
p.join(tempDir.path, 'shorebird.yaml'),
).writeAsStringSync('''
app_id: productionAppId
flavors:
development: $appId''');
setUpTempArtifacts(tempDir, flavor: flavor);
final exitCode = await IOOverrides.runZoned(
command.run,
getCurrentDirectory: () => tempDir,
);
verify(() => logger.success('\n✅ Published Patch!')).called(1);
expect(exitCode, ExitCode.success.code);
expect(capturedHostedUri, isNull);
});

test('succeeds when patch is successful using custom base_url', () async {
final tempDir = setUpTempDir();
setUpTempArtifacts(tempDir);
Expand Down