refactor(shorebird_cli): rename publish to patch (#189)
This commit is contained in:
@@ -51,7 +51,7 @@ class ShorebirdCliCommandRunner extends CompletionCommandRunner<int> {
|
||||
addCommand(InitCommand(logger: _logger));
|
||||
addCommand(LoginCommand(logger: _logger));
|
||||
addCommand(LogoutCommand(logger: _logger));
|
||||
addCommand(PublishCommand(logger: _logger));
|
||||
addCommand(PatchCommand(logger: _logger));
|
||||
addCommand(ReleaseCommand(logger: _logger));
|
||||
addCommand(RunCommand(logger: _logger));
|
||||
addCommand(UpgradeCommand(logger: _logger));
|
||||
|
||||
@@ -3,7 +3,7 @@ export 'build_command.dart';
|
||||
export 'init_command.dart';
|
||||
export 'login_command.dart';
|
||||
export 'logout_command.dart';
|
||||
export 'publish_command.dart';
|
||||
export 'patch.dart';
|
||||
export 'release_command.dart';
|
||||
export 'run_command.dart';
|
||||
export 'upgrade_command.dart';
|
||||
|
||||
+61
-21
@@ -11,36 +11,60 @@ import 'package:shorebird_cli/src/shorebird_create_app_mixin.dart';
|
||||
import 'package:shorebird_cli/src/shorebird_engine_mixin.dart';
|
||||
import 'package:shorebird_code_push_client/shorebird_code_push_client.dart';
|
||||
|
||||
/// {@template publish_command}
|
||||
///
|
||||
/// `shorebird publish <path/to/artifact>`
|
||||
/// Publish new releases to the Shorebird CodePush server.
|
||||
/// {@template patch_command}
|
||||
/// `shorebird patch`
|
||||
/// Publish new patches for a specific release to the Shorebird CodePush server.
|
||||
/// {@endtemplate}
|
||||
class PublishCommand extends ShorebirdCommand
|
||||
class PatchCommand extends ShorebirdCommand
|
||||
with
|
||||
ShorebirdConfigMixin,
|
||||
ShorebirdEngineMixin,
|
||||
ShorebirdBuildMixin,
|
||||
ShorebirdCreateAppMixin {
|
||||
/// {@macro publish_command}
|
||||
PublishCommand({
|
||||
/// {@macro patch_command}
|
||||
PatchCommand({
|
||||
required super.logger,
|
||||
super.auth,
|
||||
super.buildCodePushClient,
|
||||
super.runProcess,
|
||||
HashFunction? hashFn,
|
||||
}) : _hashFn = hashFn ?? ((m) => sha256.convert(m).toString());
|
||||
}) : _hashFn = hashFn ?? ((m) => sha256.convert(m).toString()) {
|
||||
argParser
|
||||
..addOption(
|
||||
'release-version',
|
||||
help: 'The version of the release (e.g. "1.0.0").',
|
||||
)
|
||||
..addOption(
|
||||
'platform',
|
||||
help: 'The platform of the release (e.g. "android").',
|
||||
allowed: ['android'],
|
||||
allowedHelp: {'android': 'The Android platform.'},
|
||||
defaultsTo: 'android',
|
||||
)
|
||||
..addOption(
|
||||
'arch',
|
||||
help: 'The architecture of the release (e.g. "aarch64").',
|
||||
allowed: ['aarch64'],
|
||||
allowedHelp: {'aarch64': 'The 64-bit ARM architecture.'},
|
||||
defaultsTo: 'aarch64',
|
||||
)
|
||||
..addOption(
|
||||
'channel',
|
||||
help: 'The channel the patch should be promoted to (e.g. "stable").',
|
||||
allowed: ['stable'],
|
||||
allowedHelp: {
|
||||
'stable': 'The stable channel which is consumed by production apps.'
|
||||
},
|
||||
defaultsTo: 'stable',
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
String get description => 'Publish an update.';
|
||||
String get description =>
|
||||
'Publish new patches for a specific release to Shorebird.';
|
||||
|
||||
@override
|
||||
String get name => 'publish';
|
||||
|
||||
// TODO(felangel): make these configurable.
|
||||
static const String _arch = 'aarch64';
|
||||
static const String _platform = 'android';
|
||||
static const String _channel = 'stable';
|
||||
String get name => 'patch';
|
||||
|
||||
final HashFunction _hashFn;
|
||||
|
||||
@@ -127,13 +151,29 @@ Did you forget to run "shorebird init"?''',
|
||||
return ExitCode.software.code;
|
||||
}
|
||||
|
||||
final releaseVersionArg = results['release-version'] as String?;
|
||||
final pubspecVersion = pubspecYaml.version!;
|
||||
final pubspecVersionString =
|
||||
'''${pubspecVersion.major}.${pubspecVersion.minor}.${pubspecVersion.patch}''';
|
||||
final releaseVersion = releaseVersionArg ??
|
||||
logger.prompt(
|
||||
'\nWhich release is this patch for?',
|
||||
defaultValue: pubspecVersionString,
|
||||
);
|
||||
final arch = results['arch'] as String;
|
||||
final platform = results['platform'] as String;
|
||||
final channelArg = results['channel'] as String;
|
||||
|
||||
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(versionString)}
|
||||
📦 Release Version: ${lightCyan.wrap(releaseVersion)}
|
||||
⚙️ Architecture: ${lightCyan.wrap(arch)}
|
||||
🕹️ Platform: ${lightCyan.wrap(platform)}
|
||||
📺 Channel: ${lightCyan.wrap(channelArg)}
|
||||
#️⃣ Hash: ${lightCyan.wrap(hash)}
|
||||
''',
|
||||
);
|
||||
@@ -188,8 +228,8 @@ Please create a release using "shorebird release" and try again.
|
||||
await codePushClient.createPatchArtifact(
|
||||
patchId: patch.id,
|
||||
artifactPath: artifact.path,
|
||||
arch: _arch,
|
||||
platform: _platform,
|
||||
arch: arch,
|
||||
platform: platform,
|
||||
hash: hash,
|
||||
);
|
||||
createArtifactProgress.complete();
|
||||
@@ -203,7 +243,7 @@ Please create a release using "shorebird release" and try again.
|
||||
try {
|
||||
final channels = await codePushClient.getChannels(appId: app.id);
|
||||
channel = channels.firstWhereOrNull(
|
||||
(channel) => channel.name == _channel,
|
||||
(channel) => channel.name == channelArg,
|
||||
);
|
||||
fetchChannelsProgress.complete();
|
||||
} catch (error) {
|
||||
@@ -216,7 +256,7 @@ Please create a release using "shorebird release" and try again.
|
||||
try {
|
||||
channel = await codePushClient.createChannel(
|
||||
appId: app.id,
|
||||
channel: _channel,
|
||||
channel: channelArg,
|
||||
);
|
||||
createChannelProgress.complete();
|
||||
} catch (error) {
|
||||
@@ -237,7 +277,7 @@ Please create a release using "shorebird release" and try again.
|
||||
return ExitCode.software.code;
|
||||
}
|
||||
|
||||
logger.success('\n✅ Published Successfully!');
|
||||
logger.success('\n✅ Published Patch!');
|
||||
return ExitCode.success.code;
|
||||
}
|
||||
}
|
||||
@@ -223,7 +223,7 @@ ${link(uri: Uri.parse('https://support.google.com/googleplay/android-developer/a
|
||||
return ExitCode.software.code;
|
||||
}
|
||||
|
||||
logger.success('\n✅ Released Successfully!');
|
||||
logger.success('\n✅ Published Release!');
|
||||
return ExitCode.success.code;
|
||||
}
|
||||
}
|
||||
|
||||
+19
-10
@@ -8,7 +8,7 @@ import 'package:mocktail/mocktail.dart';
|
||||
import 'package:path/path.dart' as p;
|
||||
import 'package:shorebird_cli/src/auth/auth.dart';
|
||||
import 'package:shorebird_cli/src/auth/session.dart';
|
||||
import 'package:shorebird_cli/src/commands/publish_command.dart';
|
||||
import 'package:shorebird_cli/src/commands/patch.dart';
|
||||
import 'package:shorebird_cli/src/config/config.dart';
|
||||
import 'package:shorebird_code_push_client/shorebird_code_push_client.dart';
|
||||
import 'package:test/test.dart';
|
||||
@@ -26,17 +26,20 @@ class _MockProcessResult extends Mock implements ProcessResult {}
|
||||
class _MockCodePushClient extends Mock implements CodePushClient {}
|
||||
|
||||
void main() {
|
||||
group('publish', () {
|
||||
group('patch', () {
|
||||
const session = Session(apiKey: 'test-api-key');
|
||||
const appId = 'test-app-id';
|
||||
const version = '1.2.3';
|
||||
const arch = 'aarch64';
|
||||
const platform = 'android';
|
||||
const channelName = 'stable';
|
||||
const appDisplayName = 'Test App';
|
||||
const appMetadata = AppMetadata(appId: appId, displayName: appDisplayName);
|
||||
const patchArtifact = PatchArtifact(
|
||||
id: 0,
|
||||
patchId: 0,
|
||||
arch: 'aarch64',
|
||||
platform: 'android',
|
||||
arch: arch,
|
||||
platform: platform,
|
||||
hash: '#',
|
||||
size: 42,
|
||||
url: 'https://example.com',
|
||||
@@ -48,7 +51,7 @@ void main() {
|
||||
displayName: '1.2.3',
|
||||
);
|
||||
const patch = Patch(id: 0, number: 1);
|
||||
const channel = Channel(id: 0, appId: appId, name: 'stable');
|
||||
const channel = Channel(id: 0, appId: appId, name: channelName);
|
||||
const pubspecYamlContent = '''
|
||||
name: example
|
||||
version: $version
|
||||
@@ -66,7 +69,7 @@ flutter:
|
||||
late Logger logger;
|
||||
late ProcessResult processResult;
|
||||
late CodePushClient codePushClient;
|
||||
late PublishCommand command;
|
||||
late PatchCommand command;
|
||||
late Uri? capturedHostedUri;
|
||||
|
||||
Directory setUpTempDir() {
|
||||
@@ -88,7 +91,7 @@ flutter:
|
||||
logger = _MockLogger();
|
||||
processResult = _MockProcessResult();
|
||||
codePushClient = _MockCodePushClient();
|
||||
command = PublishCommand(
|
||||
command = PatchCommand(
|
||||
auth: auth,
|
||||
buildCodePushClient: ({required String apiKey, Uri? hostedUri}) {
|
||||
capturedHostedUri = hostedUri;
|
||||
@@ -107,8 +110,14 @@ flutter:
|
||||
testApplicationConfigHome = (_) => applicationConfigHome.path;
|
||||
|
||||
when(() => argResults.rest).thenReturn([]);
|
||||
when(() => argResults['arch']).thenReturn(arch);
|
||||
when(() => argResults['platform']).thenReturn(platform);
|
||||
when(() => argResults['channel']).thenReturn(channelName);
|
||||
when(() => auth.currentSession).thenReturn(session);
|
||||
when(() => logger.progress(any())).thenReturn(progress);
|
||||
when(
|
||||
() => logger.prompt(any(), defaultValue: any(named: 'defaultValue')),
|
||||
).thenReturn(version);
|
||||
when(() => logger.confirm(any())).thenReturn(true);
|
||||
when(() => processResult.exitCode).thenReturn(ExitCode.success.code);
|
||||
when(
|
||||
@@ -552,7 +561,7 @@ Please create a release using "shorebird release" and try again.
|
||||
expect(exitCode, ExitCode.software.code);
|
||||
});
|
||||
|
||||
test('succeeds when publish is successful', () async {
|
||||
test('succeeds when patch is successful', () async {
|
||||
final tempDir = setUpTempDir();
|
||||
Directory(
|
||||
p.join(command.shorebirdEnginePath, 'engine'),
|
||||
@@ -574,12 +583,12 @@ Please create a release using "shorebird release" and try again.
|
||||
command.run,
|
||||
getCurrentDirectory: () => tempDir,
|
||||
);
|
||||
verify(() => logger.success('\n✅ Published Successfully!')).called(1);
|
||||
verify(() => logger.success('\n✅ Published Patch!')).called(1);
|
||||
expect(exitCode, ExitCode.success.code);
|
||||
expect(capturedHostedUri, isNull);
|
||||
});
|
||||
|
||||
test('succeeds when publish is successful using custom base_url', () async {
|
||||
test('succeeds when patch is successful using custom base_url', () async {
|
||||
final tempDir = setUpTempDir();
|
||||
const baseUrl = 'https://example.com';
|
||||
File(
|
||||
@@ -438,7 +438,7 @@ Did you forget to run "shorebird init"?''',
|
||||
command.run,
|
||||
getCurrentDirectory: () => tempDir,
|
||||
);
|
||||
verify(() => logger.success('\n✅ Released Successfully!')).called(1);
|
||||
verify(() => logger.success('\n✅ Published Release!')).called(1);
|
||||
expect(exitCode, ExitCode.success.code);
|
||||
expect(capturedHostedUri, isNull);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user