refactor(shorebird_cli): introduce uploadPatchArtifacts in Patcher for consistency (#2530)
This commit is contained in:
@@ -321,14 +321,13 @@ NOTE: this is ${styleBold.wrap('not')} recommended. Asset changes cannot be incl
|
||||
baseMetadata,
|
||||
);
|
||||
|
||||
await codePushClientWrapper.publishPatch(
|
||||
await patcher.uploadPatchArtifacts(
|
||||
appId: appId,
|
||||
releaseId: release.id,
|
||||
metadata: updateMetadata.toJson(),
|
||||
platform: patcher.releaseType.releasePlatform,
|
||||
track:
|
||||
isStaging ? DeploymentTrack.staging : DeploymentTrack.production,
|
||||
patchArtifactBundles: patchArtifactBundles,
|
||||
artifacts: patchArtifactBundles,
|
||||
);
|
||||
},
|
||||
values: {
|
||||
|
||||
@@ -7,6 +7,7 @@ import 'package:mason_logger/mason_logger.dart';
|
||||
import 'package:path/path.dart' as p;
|
||||
import 'package:shorebird_cli/src/code_push_client_wrapper.dart';
|
||||
import 'package:shorebird_cli/src/common_arguments.dart';
|
||||
import 'package:shorebird_cli/src/deployment_track.dart';
|
||||
import 'package:shorebird_cli/src/extensions/iterable.dart';
|
||||
import 'package:shorebird_cli/src/metadata/metadata.dart';
|
||||
import 'package:shorebird_cli/src/patch_diff_checker.dart';
|
||||
@@ -73,7 +74,7 @@ ${iOSLinkPercentageUrl.toLink()}
|
||||
required File patchArchive,
|
||||
});
|
||||
|
||||
/// Builds the release artifacts for the given platform. Returns the "primary"
|
||||
/// Builds the patch artifacts for the given platform. Returns the "primary"
|
||||
/// artifact for the platform (e.g. the AAB for Android, the IPA for iOS).
|
||||
Future<File> buildPatchArtifact({String? releaseVersion});
|
||||
|
||||
@@ -94,6 +95,24 @@ ${iOSLinkPercentageUrl.toLink()}
|
||||
return metadata;
|
||||
}
|
||||
|
||||
/// Uploads the patch artifacts to the CodePush server.
|
||||
Future<void> uploadPatchArtifacts({
|
||||
required String appId,
|
||||
required int releaseId,
|
||||
required Map<String, dynamic> metadata,
|
||||
required Map<Arch, PatchArtifactBundle> artifacts,
|
||||
required DeploymentTrack track,
|
||||
}) async {
|
||||
await codePushClientWrapper.publishPatch(
|
||||
appId: appId,
|
||||
releaseId: releaseId,
|
||||
metadata: metadata,
|
||||
platform: releaseType.releasePlatform,
|
||||
track: track,
|
||||
patchArtifactBundles: artifacts,
|
||||
);
|
||||
}
|
||||
|
||||
/// Whether to allow changes in assets (--allow-asset-diffs).
|
||||
bool get allowAssetDiffs => argResults['allow-asset-diffs'] == true;
|
||||
|
||||
|
||||
@@ -159,10 +159,12 @@ void main() {
|
||||
when(() => argResults['platforms']).thenReturn(['android']);
|
||||
when(() => argResults['release-version']).thenReturn(releaseVersion);
|
||||
when(() => argResults.wasParsed(any())).thenReturn(true);
|
||||
when(() => argResults.wasParsed(CommonArguments.privateKeyArg.name))
|
||||
.thenReturn(false);
|
||||
when(() => argResults.wasParsed(CommonArguments.publicKeyArg.name))
|
||||
.thenReturn(false);
|
||||
when(
|
||||
() => argResults.wasParsed(CommonArguments.privateKeyArg.name),
|
||||
).thenReturn(false);
|
||||
when(
|
||||
() => argResults.wasParsed(CommonArguments.publicKeyArg.name),
|
||||
).thenReturn(false);
|
||||
|
||||
when(aotTools.isLinkDebugInfoSupported).thenAnswer((_) async => true);
|
||||
|
||||
@@ -172,23 +174,24 @@ void main() {
|
||||
|
||||
when(() => cache.updateAll()).thenAnswer((_) async => {});
|
||||
|
||||
when(() => codePushClientWrapper.getApp(appId: any(named: 'appId')))
|
||||
.thenAnswer((_) async => appMetadata);
|
||||
when(
|
||||
() => codePushClientWrapper.getApp(appId: any(named: 'appId')),
|
||||
).thenAnswer((_) async => appMetadata);
|
||||
when(
|
||||
() => codePushClientWrapper.getRelease(
|
||||
appId: any(named: 'appId'),
|
||||
releaseVersion: any(named: 'releaseVersion'),
|
||||
),
|
||||
).thenAnswer((_) async => release);
|
||||
when(() => codePushClientWrapper.getReleases(appId: any(named: 'appId')))
|
||||
.thenAnswer((_) async => [release]);
|
||||
when(
|
||||
() => codePushClientWrapper.publishPatch(
|
||||
() => codePushClientWrapper.getReleases(appId: any(named: 'appId')),
|
||||
).thenAnswer((_) async => [release]);
|
||||
when(
|
||||
() => patcher.uploadPatchArtifacts(
|
||||
appId: any(named: 'appId'),
|
||||
releaseId: any(named: 'releaseId'),
|
||||
platform: any(named: 'platform'),
|
||||
track: any(named: 'track'),
|
||||
patchArtifactBundles: any(named: 'patchArtifactBundles'),
|
||||
artifacts: any(named: 'artifacts'),
|
||||
metadata: any(named: 'metadata'),
|
||||
),
|
||||
).thenAnswer((_) async {});
|
||||
@@ -298,13 +301,12 @@ void main() {
|
||||
await runWithOverrides(() => command.createPatch(patcher));
|
||||
|
||||
verify(
|
||||
() => codePushClientWrapper.publishPatch(
|
||||
() => patcher.uploadPatchArtifacts(
|
||||
appId: appId,
|
||||
releaseId: any(named: 'releaseId'),
|
||||
metadata: any(named: 'metadata'),
|
||||
platform: any(named: 'platform'),
|
||||
track: any(named: 'track'),
|
||||
patchArtifactBundles: patchArtifactBundles,
|
||||
artifacts: patchArtifactBundles,
|
||||
),
|
||||
).called(1);
|
||||
});
|
||||
@@ -601,12 +603,11 @@ void main() {
|
||||
),
|
||||
() => logger.confirm('Would you like to continue?'),
|
||||
() => patcher.updatedCreatePatchMetadata(any()),
|
||||
() => codePushClientWrapper.publishPatch(
|
||||
() => patcher.uploadPatchArtifacts(
|
||||
appId: appId,
|
||||
releaseId: release.id,
|
||||
metadata: patchMetadata.toJson(),
|
||||
platform: releasePlatform,
|
||||
patchArtifactBundles: any(named: 'patchArtifactBundles'),
|
||||
artifacts: any(named: 'artifacts'),
|
||||
track: DeploymentTrack.production,
|
||||
),
|
||||
]);
|
||||
@@ -652,12 +653,11 @@ void main() {
|
||||
releaseArtifact: any(named: 'releaseArtifact'),
|
||||
),
|
||||
() => logger.confirm('Would you like to continue?'),
|
||||
() => codePushClientWrapper.publishPatch(
|
||||
() => patcher.uploadPatchArtifacts(
|
||||
appId: appId,
|
||||
releaseId: release.id,
|
||||
metadata: any(named: 'metadata'),
|
||||
platform: releasePlatform,
|
||||
patchArtifactBundles: any(named: 'patchArtifactBundles'),
|
||||
artifacts: any(named: 'artifacts'),
|
||||
track: DeploymentTrack.production,
|
||||
),
|
||||
]);
|
||||
@@ -774,12 +774,11 @@ void main() {
|
||||
|
||||
verifyNever(() => logger.confirm(any()));
|
||||
verifyNever(
|
||||
() => codePushClientWrapper.publishPatch(
|
||||
() => patcher.uploadPatchArtifacts(
|
||||
appId: appId,
|
||||
releaseId: release.id,
|
||||
metadata: any(named: 'metadata'),
|
||||
platform: releasePlatform,
|
||||
patchArtifactBundles: any(named: 'patchArtifactBundles'),
|
||||
artifacts: any(named: 'artifacts'),
|
||||
track: DeploymentTrack.production,
|
||||
),
|
||||
);
|
||||
@@ -958,12 +957,11 @@ Please re-run the release command for this version or create a new release.''',
|
||||
expect(exitCode, equals(ExitCode.success.code));
|
||||
|
||||
verify(
|
||||
() => codePushClientWrapper.publishPatch(
|
||||
() => patcher.uploadPatchArtifacts(
|
||||
appId: appId,
|
||||
releaseId: release.id,
|
||||
metadata: any(named: 'metadata'),
|
||||
platform: releasePlatform,
|
||||
patchArtifactBundles: any(named: 'patchArtifactBundles'),
|
||||
artifacts: any(named: 'artifacts'),
|
||||
track: DeploymentTrack.staging,
|
||||
),
|
||||
).called(1);
|
||||
|
||||
@@ -2,19 +2,26 @@ import 'dart:io';
|
||||
|
||||
import 'package:args/args.dart';
|
||||
import 'package:mocktail/mocktail.dart';
|
||||
import 'package:scoped_deps/scoped_deps.dart';
|
||||
import 'package:shorebird_cli/src/code_push_client_wrapper.dart';
|
||||
import 'package:shorebird_cli/src/commands/commands.dart';
|
||||
import 'package:shorebird_cli/src/common_arguments.dart';
|
||||
import 'package:shorebird_cli/src/deployment_track.dart';
|
||||
import 'package:shorebird_cli/src/patch_diff_checker.dart';
|
||||
import 'package:shorebird_cli/src/platform/platform.dart';
|
||||
import 'package:shorebird_cli/src/release_type.dart';
|
||||
import 'package:shorebird_code_push_protocol/src/models/release_artifact.dart';
|
||||
import 'package:shorebird_code_push_client/shorebird_code_push_client.dart';
|
||||
import 'package:test/test.dart';
|
||||
|
||||
import '../../mocks.dart';
|
||||
|
||||
void main() {
|
||||
group(Patcher, () {
|
||||
setUpAll(() {
|
||||
registerFallbackValue(ReleasePlatform.android);
|
||||
registerFallbackValue(DeploymentTrack.production);
|
||||
});
|
||||
|
||||
group('linkPercentage', () {
|
||||
test('defaults to null', () {
|
||||
expect(
|
||||
@@ -153,6 +160,60 @@ void main() {
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
group('uploadPatchArtifacts', () {
|
||||
test(
|
||||
'calls codePushClientWrapper.publishPatch '
|
||||
'with correct args', () async {
|
||||
final args = MockArgResults();
|
||||
final patcher = _TestPatcher(
|
||||
argResults: args,
|
||||
flavor: null,
|
||||
target: null,
|
||||
releaseType: ReleaseType.android,
|
||||
);
|
||||
const appId = 'test_app_id';
|
||||
const releaseId = 42;
|
||||
const metadata = <String, String>{};
|
||||
const artifacts = <Arch, PatchArtifactBundle>{};
|
||||
const track = DeploymentTrack.production;
|
||||
final codePushClientWrapper = MockCodePushClientWrapper();
|
||||
when(
|
||||
() => codePushClientWrapper.publishPatch(
|
||||
appId: any(named: 'appId'),
|
||||
releaseId: any(named: 'releaseId'),
|
||||
metadata: any(named: 'metadata'),
|
||||
platform: any(named: 'platform'),
|
||||
track: any(named: 'track'),
|
||||
patchArtifactBundles: any(named: 'patchArtifactBundles'),
|
||||
),
|
||||
).thenAnswer((_) async {});
|
||||
await runScoped(
|
||||
() async {
|
||||
await patcher.uploadPatchArtifacts(
|
||||
appId: appId,
|
||||
releaseId: releaseId,
|
||||
metadata: metadata,
|
||||
artifacts: artifacts,
|
||||
track: track,
|
||||
);
|
||||
},
|
||||
values: {
|
||||
codePushClientWrapperRef.overrideWith(() => codePushClientWrapper),
|
||||
},
|
||||
);
|
||||
verify(
|
||||
() => codePushClientWrapper.publishPatch(
|
||||
appId: appId,
|
||||
releaseId: releaseId,
|
||||
metadata: metadata,
|
||||
platform: ReleaseType.android.releasePlatform,
|
||||
track: track,
|
||||
patchArtifactBundles: artifacts,
|
||||
),
|
||||
).called(1);
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
@@ -161,7 +222,10 @@ class _TestPatcher extends Patcher {
|
||||
required super.argResults,
|
||||
required super.flavor,
|
||||
required super.target,
|
||||
});
|
||||
ReleaseType? releaseType,
|
||||
}) : _releaseType = releaseType;
|
||||
|
||||
final ReleaseType? _releaseType;
|
||||
|
||||
@override
|
||||
Future<void> assertPreconditions() {
|
||||
@@ -200,5 +264,8 @@ class _TestPatcher extends Patcher {
|
||||
String get primaryReleaseArtifactArch => throw UnimplementedError();
|
||||
|
||||
@override
|
||||
ReleaseType get releaseType => throw UnimplementedError();
|
||||
ReleaseType get releaseType {
|
||||
if (_releaseType != null) return _releaseType;
|
||||
throw UnimplementedError();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user