diff --git a/packages/shorebird_cli/lib/src/commands/patch/patch_command.dart b/packages/shorebird_cli/lib/src/commands/patch/patch_command.dart index 356c7264..66dd5468 100644 --- a/packages/shorebird_cli/lib/src/commands/patch/patch_command.dart +++ b/packages/shorebird_cli/lib/src/commands/patch/patch_command.dart @@ -93,7 +93,6 @@ To target the latest release (e.g. the release that was most recently updated) u ) ..addOption( 'track', - allowed: DeploymentTrack.values.map((v) => v.channel), help: 'The track to publish the patch to.', defaultsTo: DeploymentTrack.stable.channel, ) @@ -198,10 +197,7 @@ NOTE: this is ${styleBold.wrap('not')} recommended. Asset changes cannot be incl bool get useLatestRelease => results['release-version'] == 'latest'; /// The deployment track to publish the patch to. - DeploymentTrack get track { - final channel = results['track'] as String; - return DeploymentTrack.values.firstWhere((t) => t.channel == channel); - } + DeploymentTrack get track => DeploymentTrack(results['track'] as String); @override Future run() async { @@ -557,6 +553,7 @@ Please re-run the release command for this version or create a new release.'''); DeploymentTrack.staging => '🟠 Track: ${lightCyan.wrap('Staging')}', DeploymentTrack.beta => '🔵 Track: ${lightCyan.wrap('Beta')}', DeploymentTrack.stable => '🟢 Track: ${lightCyan.wrap('Stable')}', + final String trackName => '⚪️ Track: ${lightCyan.wrap(trackName)}', }; })(); diff --git a/packages/shorebird_cli/lib/src/commands/preview_command.dart b/packages/shorebird_cli/lib/src/commands/preview_command.dart index 91fa7f2c..4fac6d09 100644 --- a/packages/shorebird_cli/lib/src/commands/preview_command.dart +++ b/packages/shorebird_cli/lib/src/commands/preview_command.dart @@ -95,7 +95,6 @@ This is only applicable when previewing Android releases.''', ) ..addOption( 'track', - allowed: DeploymentTrack.values.map((v) => v.channel), help: 'The track to preview.', defaultsTo: DeploymentTrack.stable.channel, ); @@ -119,10 +118,7 @@ This is only applicable when previewing Android releases.''', String get description => 'Preview a specific release on a device.'; /// The deployment track to publish the patch to. - DeploymentTrack get track { - final channel = results['track'] as String; - return DeploymentTrack.values.firstWhere((t) => t.channel == channel); - } + DeploymentTrack get track => DeploymentTrack(results['track'] as String); @override Future run() async { @@ -382,10 +378,10 @@ This is only applicable when previewing Android releases.''', } } - final progress = logger.progress('Using ${track.name} track'); + final progress = logger.progress('Using $track track'); try { await setChannelOnLinuxApp( - channel: track.name, + channel: track.channel, bundleDirectory: appDirectory, ); progress.complete(); @@ -460,7 +456,7 @@ This is only applicable when previewing Android releases.''', await setChannelOnWindowsApp( appDirectory: appDirectory, - channel: track.name, + channel: track.channel, ); final exeFile = appDirectory.listSync().whereType().firstWhere( @@ -527,7 +523,10 @@ This is only applicable when previewing Android releases.''', } } - await setChannelOnMacosApp(appDirectory: appDirectory, channel: track.name); + await setChannelOnMacosApp( + appDirectory: appDirectory, + channel: track.channel, + ); final logs = await open.newApplication(path: appDirectory.path); final completer = Completer(); @@ -656,7 +655,7 @@ This is only applicable when previewing Android releases.''', ); if (File(apksPath).existsSync()) File(apksPath).deleteSync(); - final progress = logger.progress('Using ${track.name} track'); + final progress = logger.progress('Using $track track'); try { await setChannelOnAab(aabFile: aabFile, channel: track.channel); progress.complete(); @@ -779,7 +778,7 @@ This is only applicable when previewing Android releases.''', } } - final progress = logger.progress('Using ${track.name} track'); + final progress = logger.progress('Using $track track'); try { await setChannelOnRunner( runnerDirectory: runnerDirectory, diff --git a/packages/shorebird_cli/lib/src/deployment_track.dart b/packages/shorebird_cli/lib/src/deployment_track.dart index b78ca812..5445dcd2 100644 --- a/packages/shorebird_cli/lib/src/deployment_track.dart +++ b/packages/shorebird_cli/lib/src/deployment_track.dart @@ -1,16 +1,14 @@ /// The deployment track to use when deploying to Shorebird's servers -enum DeploymentTrack { +extension type const DeploymentTrack(String value) { /// An internal track for validating changes. - staging('staging'), + static const staging = DeploymentTrack('staging'); /// A public track for publishing changes to a limited audience. - beta('beta'), + static const beta = DeploymentTrack('beta'); /// A public track for publishing changes to production. - stable('stable'); - - const DeploymentTrack(this.channel); + static const stable = DeploymentTrack('stable'); /// The name of the channel associated with the track. - final String channel; + String get channel => value; } diff --git a/packages/shorebird_cli/test/src/commands/patch/patch_command_test.dart b/packages/shorebird_cli/test/src/commands/patch/patch_command_test.dart index 7a7ea61a..52b1b640 100644 --- a/packages/shorebird_cli/test/src/commands/patch/patch_command_test.dart +++ b/packages/shorebird_cli/test/src/commands/patch/patch_command_test.dart @@ -559,6 +559,35 @@ void main() { }); group('confirmCreatePatch', () { + group('when using a custom deployment track', () { + setUp(() { + when(() => argResults['track']).thenReturn('custom-track'); + }); + + test('logs correct summary', () async { + final expectedSummary = [ + '''📱 App: ${lightCyan.wrap(appDisplayName)} ${lightCyan.wrap('($appId)')}''', + '📦 Release Version: ${lightCyan.wrap(releaseVersion)}', + '''🕹️ Platform: ${lightCyan.wrap(patcher.releaseType.releasePlatform.displayName)} ${lightCyan.wrap('[arm32 (42 B)]')}''', + '⚪️ Track: ${lightCyan.wrap('custom-track')}', + ]; + await expectLater( + runWithOverrides( + () => command.confirmCreatePatch( + app: appMetadata, + releaseVersion: releaseVersion, + patcher: patcher, + patchArtifactBundles: patchArtifactBundles, + ), + ), + completes, + ); + verify( + () => logger.info(any(that: contains(expectedSummary.join('\n')))), + ).called(1); + }); + }); + group('when has flavors', () { const flavor = 'development'; setUp(() {