From fa715eadc8c7282f6309dbe61f0f6e7335b336e6 Mon Sep 17 00:00:00 2001 From: Bryan Oltman Date: Fri, 22 Mar 2024 12:14:14 -0400 Subject: [PATCH 01/13] chore(shorebird_code_push_protocol): Add metadata messages --- .../lib/src/code_push_client.dart | 4 ++ .../create_patch/create_patch_request.dart | 5 ++ .../create_patch/create_patch_request.g.dart | 6 +++ .../update_release_request.dart | 4 ++ .../update_release_request.g.dart | 6 +++ .../models/build_environment_metadata.dart | 33 +++++++++++++ .../models/build_environment_metadata.g.dart | 39 +++++++++++++++ .../lib/src/models/create_patch_metadata.dart | 41 ++++++++++++++++ .../src/models/create_patch_metadata.g.dart | 48 +++++++++++++++++++ .../lib/src/models/models.dart | 3 ++ .../src/models/update_release_metadata.dart | 30 ++++++++++++ .../src/models/update_release_metadata.g.dart | 34 +++++++++++++ .../create_patch_request_test.dart | 25 ++++++++++ .../update_release_request_test.dart | 20 ++++++++ 14 files changed, 298 insertions(+) create mode 100644 packages/shorebird_code_push_protocol/lib/src/models/build_environment_metadata.dart create mode 100644 packages/shorebird_code_push_protocol/lib/src/models/build_environment_metadata.g.dart create mode 100644 packages/shorebird_code_push_protocol/lib/src/models/create_patch_metadata.dart create mode 100644 packages/shorebird_code_push_protocol/lib/src/models/create_patch_metadata.g.dart create mode 100644 packages/shorebird_code_push_protocol/lib/src/models/update_release_metadata.dart create mode 100644 packages/shorebird_code_push_protocol/lib/src/models/update_release_metadata.g.dart diff --git a/packages/shorebird_code_push_client/lib/src/code_push_client.dart b/packages/shorebird_code_push_client/lib/src/code_push_client.dart index 078ffb213..e7fc4ded3 100644 --- a/packages/shorebird_code_push_client/lib/src/code_push_client.dart +++ b/packages/shorebird_code_push_client/lib/src/code_push_client.dart @@ -253,6 +253,8 @@ class CodePushClient { wasForced: false, hasAssetChanges: hasAssetChanges, hasNativeChanges: hasNativeChanges, + // TODO(bryanoltman): add metadata + metadata: null, ); final response = await _httpClient.post( Uri.parse('$_v1/apps/$appId/patches'), @@ -304,6 +306,8 @@ class CodePushClient { UpdateReleaseRequest( status: status, platform: platform, + // TODO(bryanoltman): add metadata + metadata: null, ).toJson(), ), ); diff --git a/packages/shorebird_code_push_protocol/lib/src/messages/create_patch/create_patch_request.dart b/packages/shorebird_code_push_protocol/lib/src/messages/create_patch/create_patch_request.dart index 00fda9368..4ccdb1e26 100644 --- a/packages/shorebird_code_push_protocol/lib/src/messages/create_patch/create_patch_request.dart +++ b/packages/shorebird_code_push_protocol/lib/src/messages/create_patch/create_patch_request.dart @@ -1,4 +1,5 @@ import 'package:json_annotation/json_annotation.dart'; +import 'package:shorebird_code_push_protocol/src/models/create_patch_metadata.dart'; part 'create_patch_request.g.dart'; @@ -13,6 +14,7 @@ class CreatePatchRequest { required this.wasForced, required this.hasAssetChanges, required this.hasNativeChanges, + required this.metadata, }); /// Converts a Map to a [CreatePatchRequest] @@ -33,4 +35,7 @@ class CreatePatchRequest { /// Whether the patch's native code is different than that of the release. final bool? hasNativeChanges; + + /// Additional information about the creation of the patch. + final CreatePatchMetadata? metadata; } diff --git a/packages/shorebird_code_push_protocol/lib/src/messages/create_patch/create_patch_request.g.dart b/packages/shorebird_code_push_protocol/lib/src/messages/create_patch/create_patch_request.g.dart index 99005e597..23fe70b60 100644 --- a/packages/shorebird_code_push_protocol/lib/src/messages/create_patch/create_patch_request.g.dart +++ b/packages/shorebird_code_push_protocol/lib/src/messages/create_patch/create_patch_request.g.dart @@ -20,6 +20,11 @@ CreatePatchRequest _$CreatePatchRequestFromJson(Map json) => $checkedConvert('has_asset_changes', (v) => v as bool?), hasNativeChanges: $checkedConvert('has_native_changes', (v) => v as bool?), + metadata: $checkedConvert( + 'metadata', + (v) => v == null + ? null + : CreatePatchMetadata.fromJson(v as Map)), ); return val; }, @@ -37,4 +42,5 @@ Map _$CreatePatchRequestToJson(CreatePatchRequest instance) => 'was_forced': instance.wasForced, 'has_asset_changes': instance.hasAssetChanges, 'has_native_changes': instance.hasNativeChanges, + 'metadata': instance.metadata?.toJson(), }; diff --git a/packages/shorebird_code_push_protocol/lib/src/messages/update_release/update_release_request.dart b/packages/shorebird_code_push_protocol/lib/src/messages/update_release/update_release_request.dart index 334baf8e0..801c8bfcb 100644 --- a/packages/shorebird_code_push_protocol/lib/src/messages/update_release/update_release_request.dart +++ b/packages/shorebird_code_push_protocol/lib/src/messages/update_release/update_release_request.dart @@ -12,6 +12,7 @@ class UpdateReleaseRequest { const UpdateReleaseRequest({ required this.status, required this.platform, + required this.metadata, }); /// Converts a Map to a [UpdateReleaseRequest]. @@ -26,4 +27,7 @@ class UpdateReleaseRequest { /// The platform of the release. final ReleasePlatform platform; + + /// Additional information about the release. + final UpdateReleaseMetadata? metadata; } diff --git a/packages/shorebird_code_push_protocol/lib/src/messages/update_release/update_release_request.g.dart b/packages/shorebird_code_push_protocol/lib/src/messages/update_release/update_release_request.g.dart index 220a0ec31..c2244c7df 100644 --- a/packages/shorebird_code_push_protocol/lib/src/messages/update_release/update_release_request.g.dart +++ b/packages/shorebird_code_push_protocol/lib/src/messages/update_release/update_release_request.g.dart @@ -19,6 +19,11 @@ UpdateReleaseRequest _$UpdateReleaseRequestFromJson( 'status', (v) => $enumDecode(_$ReleaseStatusEnumMap, v)), platform: $checkedConvert( 'platform', (v) => $enumDecode(_$ReleasePlatformEnumMap, v)), + metadata: $checkedConvert( + 'metadata', + (v) => v == null + ? null + : UpdateReleaseMetadata.fromJson(v as Map)), ); return val; }, @@ -29,6 +34,7 @@ Map _$UpdateReleaseRequestToJson( { 'status': _$ReleaseStatusEnumMap[instance.status]!, 'platform': _$ReleasePlatformEnumMap[instance.platform]!, + 'metadata': instance.metadata?.toJson(), }; const _$ReleaseStatusEnumMap = { diff --git a/packages/shorebird_code_push_protocol/lib/src/models/build_environment_metadata.dart b/packages/shorebird_code_push_protocol/lib/src/models/build_environment_metadata.dart new file mode 100644 index 000000000..99b0f71b2 --- /dev/null +++ b/packages/shorebird_code_push_protocol/lib/src/models/build_environment_metadata.dart @@ -0,0 +1,33 @@ +import 'package:json_annotation/json_annotation.dart'; + +part 'build_environment_metadata.g.dart'; + +/// {@template build_environment_metadata} +/// Information about the environment used to build a release or patch. +/// {@endtemplate} +@JsonSerializable() +class BuildEnvironmentMetadata { + /// {@macro build_environment_metadata} + const BuildEnvironmentMetadata({ + required this.operatingSystem, + required this.operatingSystemVersion, + required this.xcodeVersion, + }); + + /// Converts a Map to a [BuildEnvironmentMetadata] + factory BuildEnvironmentMetadata.fromJson(Map json) => + _$BuildEnvironmentMetadataFromJson(json); + + /// Converts a [BuildEnvironmentMetadata] to a Map + Map toJson() => _$BuildEnvironmentMetadataToJson(this); + + /// The operating system used to run the release command. + final String operatingSystem; + + /// The version of [operatingSystem]. + final String operatingSystemVersion; + + /// The version of Xcode used to build the patch. Only provided for iOS + /// patches. + final String? xcodeVersion; +} diff --git a/packages/shorebird_code_push_protocol/lib/src/models/build_environment_metadata.g.dart b/packages/shorebird_code_push_protocol/lib/src/models/build_environment_metadata.g.dart new file mode 100644 index 000000000..61a8e1e4c --- /dev/null +++ b/packages/shorebird_code_push_protocol/lib/src/models/build_environment_metadata.g.dart @@ -0,0 +1,39 @@ +// GENERATED CODE - DO NOT MODIFY BY HAND + +// ignore_for_file: implicit_dynamic_parameter, require_trailing_commas, cast_nullable_to_non_nullable, lines_longer_than_80_chars + +part of 'build_environment_metadata.dart'; + +// ************************************************************************** +// JsonSerializableGenerator +// ************************************************************************** + +BuildEnvironmentMetadata _$BuildEnvironmentMetadataFromJson( + Map json) => + $checkedCreate( + 'BuildEnvironmentMetadata', + json, + ($checkedConvert) { + final val = BuildEnvironmentMetadata( + operatingSystem: + $checkedConvert('operating_system', (v) => v as String), + operatingSystemVersion: + $checkedConvert('operating_system_version', (v) => v as String), + xcodeVersion: $checkedConvert('xcode_version', (v) => v as String?), + ); + return val; + }, + fieldKeyMap: const { + 'operatingSystem': 'operating_system', + 'operatingSystemVersion': 'operating_system_version', + 'xcodeVersion': 'xcode_version' + }, + ); + +Map _$BuildEnvironmentMetadataToJson( + BuildEnvironmentMetadata instance) => + { + 'operating_system': instance.operatingSystem, + 'operating_system_version': instance.operatingSystemVersion, + 'xcode_version': instance.xcodeVersion, + }; diff --git a/packages/shorebird_code_push_protocol/lib/src/models/create_patch_metadata.dart b/packages/shorebird_code_push_protocol/lib/src/models/create_patch_metadata.dart new file mode 100644 index 000000000..67ff0aa81 --- /dev/null +++ b/packages/shorebird_code_push_protocol/lib/src/models/create_patch_metadata.dart @@ -0,0 +1,41 @@ +import 'package:json_annotation/json_annotation.dart'; +import 'package:shorebird_code_push_protocol/src/models/models.dart'; + +part 'create_patch_metadata.g.dart'; + +/// {@template create_patch_metadata} +/// Information about a patch, used for debugging purposes. +/// {@endtemplate} +@JsonSerializable() +class CreatePatchMetadata { + /// {@macro create_patch_metadata} + const CreatePatchMetadata({ + required this.usedIgnoreAssetChangesFlag, + required this.hasAssetChanges, + required this.usedIgnoreNativeChangesFlag, + required this.hasNativeChanges, + required this.environment, + }); + + /// Converts a Map to a [CreatePatchMetadata] + factory CreatePatchMetadata.fromJson(Map json) => + _$CreatePatchMetadataFromJson(json); + + /// Converts a [CreatePatchMetadata] to a Map + Map toJson() => _$CreatePatchMetadataToJson(this); + + /// Whether the `--allow-asset-diffs` flag was used. + final bool usedIgnoreAssetChangesFlag; + + /// Whether asset changes were detected in the patch. + final bool hasAssetChanges; + + /// Whether the `--allow-native-diffs` flag was used. + final bool usedIgnoreNativeChangesFlag; + + /// Whether native code changes were detected in the patch. + final bool hasNativeChanges; + + /// Properties about the environment in which the patch was created. + final BuildEnvironmentMetadata environment; +} diff --git a/packages/shorebird_code_push_protocol/lib/src/models/create_patch_metadata.g.dart b/packages/shorebird_code_push_protocol/lib/src/models/create_patch_metadata.g.dart new file mode 100644 index 000000000..86ed9bb95 --- /dev/null +++ b/packages/shorebird_code_push_protocol/lib/src/models/create_patch_metadata.g.dart @@ -0,0 +1,48 @@ +// GENERATED CODE - DO NOT MODIFY BY HAND + +// ignore_for_file: implicit_dynamic_parameter, require_trailing_commas, cast_nullable_to_non_nullable, lines_longer_than_80_chars + +part of 'create_patch_metadata.dart'; + +// ************************************************************************** +// JsonSerializableGenerator +// ************************************************************************** + +CreatePatchMetadata _$CreatePatchMetadataFromJson(Map json) => + $checkedCreate( + 'CreatePatchMetadata', + json, + ($checkedConvert) { + final val = CreatePatchMetadata( + usedIgnoreAssetChangesFlag: $checkedConvert( + 'used_ignore_asset_changes_flag', (v) => v as bool), + hasAssetChanges: + $checkedConvert('has_asset_changes', (v) => v as bool), + usedIgnoreNativeChangesFlag: $checkedConvert( + 'used_ignore_native_changes_flag', (v) => v as bool), + hasNativeChanges: + $checkedConvert('has_native_changes', (v) => v as bool), + environment: $checkedConvert( + 'environment', + (v) => + BuildEnvironmentMetadata.fromJson(v as Map)), + ); + return val; + }, + fieldKeyMap: const { + 'usedIgnoreAssetChangesFlag': 'used_ignore_asset_changes_flag', + 'hasAssetChanges': 'has_asset_changes', + 'usedIgnoreNativeChangesFlag': 'used_ignore_native_changes_flag', + 'hasNativeChanges': 'has_native_changes' + }, + ); + +Map _$CreatePatchMetadataToJson( + CreatePatchMetadata instance) => + { + 'used_ignore_asset_changes_flag': instance.usedIgnoreAssetChangesFlag, + 'has_asset_changes': instance.hasAssetChanges, + 'used_ignore_native_changes_flag': instance.usedIgnoreNativeChangesFlag, + 'has_native_changes': instance.hasNativeChanges, + 'environment': instance.environment.toJson(), + }; diff --git a/packages/shorebird_code_push_protocol/lib/src/models/models.dart b/packages/shorebird_code_push_protocol/lib/src/models/models.dart index 5a8129899..9992e99c2 100644 --- a/packages/shorebird_code_push_protocol/lib/src/models/models.dart +++ b/packages/shorebird_code_push_protocol/lib/src/models/models.dart @@ -1,11 +1,14 @@ export 'app.dart'; export 'app_metadata.dart'; export 'auth_provider.dart'; +export 'build_environment_metadata.dart'; export 'channel.dart'; +export 'create_patch_metadata.dart'; export 'error_response.dart'; export 'patch.dart'; export 'release.dart'; export 'release_artifact.dart'; export 'release_platform.dart'; export 'release_status.dart'; +export 'update_release_metadata.dart'; export 'user.dart'; diff --git a/packages/shorebird_code_push_protocol/lib/src/models/update_release_metadata.dart b/packages/shorebird_code_push_protocol/lib/src/models/update_release_metadata.dart new file mode 100644 index 000000000..54e525ad0 --- /dev/null +++ b/packages/shorebird_code_push_protocol/lib/src/models/update_release_metadata.dart @@ -0,0 +1,30 @@ +import 'package:json_annotation/json_annotation.dart'; +import 'package:shorebird_code_push_protocol/src/models/models.dart'; + +part 'update_release_metadata.g.dart'; + +/// {@template release_metadata} +/// Information about the creation of patch, used for debugging purposes. +/// {@endtemplate} +@JsonSerializable() +class UpdateReleaseMetadata { + /// {@macro release_metadata} + const UpdateReleaseMetadata({ + required this.generatedApks, + required this.environment, + }); + + /// Converts a Map to a [UpdateReleaseMetadata]. + factory UpdateReleaseMetadata.fromJson(Map json) => + _$UpdateReleaseMetadataFromJson(json); + + /// Converts a [UpdateReleaseMetadata] to a Map. + Map toJson() => _$UpdateReleaseMetadataToJson(this); + + /// Whether the user opted to generate an APK for the release (android-only). + final bool? generatedApks; + + /// Properties about the environment in which the update to the release was + /// performed. + final BuildEnvironmentMetadata environment; +} diff --git a/packages/shorebird_code_push_protocol/lib/src/models/update_release_metadata.g.dart b/packages/shorebird_code_push_protocol/lib/src/models/update_release_metadata.g.dart new file mode 100644 index 000000000..d0dcdb7df --- /dev/null +++ b/packages/shorebird_code_push_protocol/lib/src/models/update_release_metadata.g.dart @@ -0,0 +1,34 @@ +// GENERATED CODE - DO NOT MODIFY BY HAND + +// ignore_for_file: implicit_dynamic_parameter, require_trailing_commas, cast_nullable_to_non_nullable, lines_longer_than_80_chars + +part of 'update_release_metadata.dart'; + +// ************************************************************************** +// JsonSerializableGenerator +// ************************************************************************** + +UpdateReleaseMetadata _$UpdateReleaseMetadataFromJson( + Map json) => + $checkedCreate( + 'UpdateReleaseMetadata', + json, + ($checkedConvert) { + final val = UpdateReleaseMetadata( + generatedApks: $checkedConvert('generated_apks', (v) => v as bool?), + environment: $checkedConvert( + 'environment', + (v) => + BuildEnvironmentMetadata.fromJson(v as Map)), + ); + return val; + }, + fieldKeyMap: const {'generatedApks': 'generated_apks'}, + ); + +Map _$UpdateReleaseMetadataToJson( + UpdateReleaseMetadata instance) => + { + 'generated_apks': instance.generatedApks, + 'environment': instance.environment.toJson(), + }; diff --git a/packages/shorebird_code_push_protocol/test/src/messages/create_patch/create_patch_request_test.dart b/packages/shorebird_code_push_protocol/test/src/messages/create_patch/create_patch_request_test.dart index b4f12ce68..1b897d05d 100644 --- a/packages/shorebird_code_push_protocol/test/src/messages/create_patch/create_patch_request_test.dart +++ b/packages/shorebird_code_push_protocol/test/src/messages/create_patch/create_patch_request_test.dart @@ -9,6 +9,31 @@ void main() { wasForced: true, hasAssetChanges: true, hasNativeChanges: false, + metadata: CreatePatchMetadata( + usedIgnoreAssetChangesFlag: true, + usedIgnoreNativeChangesFlag: false, + hasAssetChanges: true, + hasNativeChanges: false, + environment: BuildEnvironmentMetadata( + operatingSystem: 'linux', + operatingSystemVersion: '1.0.0', + xcodeVersion: null, + ), + ), + ); + expect( + CreatePatchRequest.fromJson(request.toJson()).toJson(), + equals(request.toJson()), + ); + }); + + test('can be (de)serialized without metadata', () { + const request = CreatePatchRequest( + releaseId: 1234, + wasForced: true, + hasAssetChanges: true, + hasNativeChanges: false, + metadata: null, ); expect( CreatePatchRequest.fromJson(request.toJson()).toJson(), diff --git a/packages/shorebird_code_push_protocol/test/src/messages/update_release/update_release_request_test.dart b/packages/shorebird_code_push_protocol/test/src/messages/update_release/update_release_request_test.dart index 11b210da3..6104df75d 100644 --- a/packages/shorebird_code_push_protocol/test/src/messages/update_release/update_release_request_test.dart +++ b/packages/shorebird_code_push_protocol/test/src/messages/update_release/update_release_request_test.dart @@ -7,6 +7,26 @@ void main() { const request = UpdateReleaseRequest( platform: ReleasePlatform.android, status: ReleaseStatus.active, + metadata: UpdateReleaseMetadata( + generatedApks: null, + environment: BuildEnvironmentMetadata( + operatingSystem: 'macos', + operatingSystemVersion: '11.1', + xcodeVersion: '15.3', + ), + ), + ); + expect( + UpdateReleaseRequest.fromJson(request.toJson()).toJson(), + equals(request.toJson()), + ); + }); + + test('can be (de)serialized without metadata', () { + const request = UpdateReleaseRequest( + platform: ReleasePlatform.ios, + status: ReleaseStatus.active, + metadata: null, ); expect( UpdateReleaseRequest.fromJson(request.toJson()).toJson(), From b2f38bd238b964a0781d9bec7748db26972b489f Mon Sep 17 00:00:00 2001 From: Bryan Oltman Date: Tue, 26 Mar 2024 16:30:49 -0400 Subject: [PATCH 02/13] Update protocol models --- .../create_patch/create_patch_request.dart | 2 ++ .../src/models/build_environment_metadata.dart | 4 ++++ .../models/build_environment_metadata.g.dart | 4 ++++ .../lib/src/models/create_patch_metadata.dart | 4 ++++ .../lib/src/models/create_patch_metadata.g.dart | 9 +++++++++ .../lib/src/models/update_release_metadata.dart | 8 ++++++++ .../src/models/update_release_metadata.g.dart | 17 ++++++++++++++++- .../create_patch/create_patch_request_test.dart | 2 ++ .../update_release_request_test.dart | 3 +++ 9 files changed, 52 insertions(+), 1 deletion(-) diff --git a/packages/shorebird_code_push_protocol/lib/src/messages/create_patch/create_patch_request.dart b/packages/shorebird_code_push_protocol/lib/src/messages/create_patch/create_patch_request.dart index 4ccdb1e26..ea461b2d7 100644 --- a/packages/shorebird_code_push_protocol/lib/src/messages/create_patch/create_patch_request.dart +++ b/packages/shorebird_code_push_protocol/lib/src/messages/create_patch/create_patch_request.dart @@ -31,9 +31,11 @@ class CreatePatchRequest { final bool? wasForced; /// Whether the patch's assets were not the same as those of the release + // TODO(bryanoltman): remove this after metadata change is fully rolled out. final bool? hasAssetChanges; /// Whether the patch's native code is different than that of the release. + // TODO(bryanoltman): remove this after metadata change is fully rolled out. final bool? hasNativeChanges; /// Additional information about the creation of the patch. diff --git a/packages/shorebird_code_push_protocol/lib/src/models/build_environment_metadata.dart b/packages/shorebird_code_push_protocol/lib/src/models/build_environment_metadata.dart index 99b0f71b2..c659da4c5 100644 --- a/packages/shorebird_code_push_protocol/lib/src/models/build_environment_metadata.dart +++ b/packages/shorebird_code_push_protocol/lib/src/models/build_environment_metadata.dart @@ -9,6 +9,7 @@ part 'build_environment_metadata.g.dart'; class BuildEnvironmentMetadata { /// {@macro build_environment_metadata} const BuildEnvironmentMetadata({ + required this.shorebirdVersion, required this.operatingSystem, required this.operatingSystemVersion, required this.xcodeVersion, @@ -21,6 +22,9 @@ class BuildEnvironmentMetadata { /// Converts a [BuildEnvironmentMetadata] to a Map Map toJson() => _$BuildEnvironmentMetadataToJson(this); + /// The version of Shorebird used to run the command. + final String shorebirdVersion; + /// The operating system used to run the release command. final String operatingSystem; diff --git a/packages/shorebird_code_push_protocol/lib/src/models/build_environment_metadata.g.dart b/packages/shorebird_code_push_protocol/lib/src/models/build_environment_metadata.g.dart index 61a8e1e4c..5f2614111 100644 --- a/packages/shorebird_code_push_protocol/lib/src/models/build_environment_metadata.g.dart +++ b/packages/shorebird_code_push_protocol/lib/src/models/build_environment_metadata.g.dart @@ -15,6 +15,8 @@ BuildEnvironmentMetadata _$BuildEnvironmentMetadataFromJson( json, ($checkedConvert) { final val = BuildEnvironmentMetadata( + shorebirdVersion: + $checkedConvert('shorebird_version', (v) => v as String), operatingSystem: $checkedConvert('operating_system', (v) => v as String), operatingSystemVersion: @@ -24,6 +26,7 @@ BuildEnvironmentMetadata _$BuildEnvironmentMetadataFromJson( return val; }, fieldKeyMap: const { + 'shorebirdVersion': 'shorebird_version', 'operatingSystem': 'operating_system', 'operatingSystemVersion': 'operating_system_version', 'xcodeVersion': 'xcode_version' @@ -33,6 +36,7 @@ BuildEnvironmentMetadata _$BuildEnvironmentMetadataFromJson( Map _$BuildEnvironmentMetadataToJson( BuildEnvironmentMetadata instance) => { + 'shorebird_version': instance.shorebirdVersion, 'operating_system': instance.operatingSystem, 'operating_system_version': instance.operatingSystemVersion, 'xcode_version': instance.xcodeVersion, diff --git a/packages/shorebird_code_push_protocol/lib/src/models/create_patch_metadata.dart b/packages/shorebird_code_push_protocol/lib/src/models/create_patch_metadata.dart index 67ff0aa81..3a141c4a7 100644 --- a/packages/shorebird_code_push_protocol/lib/src/models/create_patch_metadata.dart +++ b/packages/shorebird_code_push_protocol/lib/src/models/create_patch_metadata.dart @@ -10,6 +10,7 @@ part 'create_patch_metadata.g.dart'; class CreatePatchMetadata { /// {@macro create_patch_metadata} const CreatePatchMetadata({ + required this.releasePlatform, required this.usedIgnoreAssetChangesFlag, required this.hasAssetChanges, required this.usedIgnoreNativeChangesFlag, @@ -24,6 +25,9 @@ class CreatePatchMetadata { /// Converts a [CreatePatchMetadata] to a Map Map toJson() => _$CreatePatchMetadataToJson(this); + /// The platform for which the patch was created. + final ReleasePlatform releasePlatform; + /// Whether the `--allow-asset-diffs` flag was used. final bool usedIgnoreAssetChangesFlag; diff --git a/packages/shorebird_code_push_protocol/lib/src/models/create_patch_metadata.g.dart b/packages/shorebird_code_push_protocol/lib/src/models/create_patch_metadata.g.dart index 86ed9bb95..e9e00d87f 100644 --- a/packages/shorebird_code_push_protocol/lib/src/models/create_patch_metadata.g.dart +++ b/packages/shorebird_code_push_protocol/lib/src/models/create_patch_metadata.g.dart @@ -14,6 +14,8 @@ CreatePatchMetadata _$CreatePatchMetadataFromJson(Map json) => json, ($checkedConvert) { final val = CreatePatchMetadata( + releasePlatform: $checkedConvert('release_platform', + (v) => $enumDecode(_$ReleasePlatformEnumMap, v)), usedIgnoreAssetChangesFlag: $checkedConvert( 'used_ignore_asset_changes_flag', (v) => v as bool), hasAssetChanges: @@ -30,6 +32,7 @@ CreatePatchMetadata _$CreatePatchMetadataFromJson(Map json) => return val; }, fieldKeyMap: const { + 'releasePlatform': 'release_platform', 'usedIgnoreAssetChangesFlag': 'used_ignore_asset_changes_flag', 'hasAssetChanges': 'has_asset_changes', 'usedIgnoreNativeChangesFlag': 'used_ignore_native_changes_flag', @@ -40,9 +43,15 @@ CreatePatchMetadata _$CreatePatchMetadataFromJson(Map json) => Map _$CreatePatchMetadataToJson( CreatePatchMetadata instance) => { + 'release_platform': _$ReleasePlatformEnumMap[instance.releasePlatform]!, 'used_ignore_asset_changes_flag': instance.usedIgnoreAssetChangesFlag, 'has_asset_changes': instance.hasAssetChanges, 'used_ignore_native_changes_flag': instance.usedIgnoreNativeChangesFlag, 'has_native_changes': instance.hasNativeChanges, 'environment': instance.environment.toJson(), }; + +const _$ReleasePlatformEnumMap = { + ReleasePlatform.android: 'android', + ReleasePlatform.ios: 'ios', +}; diff --git a/packages/shorebird_code_push_protocol/lib/src/models/update_release_metadata.dart b/packages/shorebird_code_push_protocol/lib/src/models/update_release_metadata.dart index 54e525ad0..6ef384d46 100644 --- a/packages/shorebird_code_push_protocol/lib/src/models/update_release_metadata.dart +++ b/packages/shorebird_code_push_protocol/lib/src/models/update_release_metadata.dart @@ -10,6 +10,8 @@ part 'update_release_metadata.g.dart'; class UpdateReleaseMetadata { /// {@macro release_metadata} const UpdateReleaseMetadata({ + required this.releasePlatform, + required this.flutterVersionOverride, required this.generatedApks, required this.environment, }); @@ -21,6 +23,12 @@ class UpdateReleaseMetadata { /// Converts a [UpdateReleaseMetadata] to a Map. Map toJson() => _$UpdateReleaseMetadataToJson(this); + /// The platform for which the patch was created. + final ReleasePlatform releasePlatform; + + /// The Flutter version specified by the user, if any. + final String? flutterVersionOverride; + /// Whether the user opted to generate an APK for the release (android-only). final bool? generatedApks; diff --git a/packages/shorebird_code_push_protocol/lib/src/models/update_release_metadata.g.dart b/packages/shorebird_code_push_protocol/lib/src/models/update_release_metadata.g.dart index d0dcdb7df..e15205d11 100644 --- a/packages/shorebird_code_push_protocol/lib/src/models/update_release_metadata.g.dart +++ b/packages/shorebird_code_push_protocol/lib/src/models/update_release_metadata.g.dart @@ -15,6 +15,10 @@ UpdateReleaseMetadata _$UpdateReleaseMetadataFromJson( json, ($checkedConvert) { final val = UpdateReleaseMetadata( + releasePlatform: $checkedConvert('release_platform', + (v) => $enumDecode(_$ReleasePlatformEnumMap, v)), + flutterVersionOverride: + $checkedConvert('flutter_version_override', (v) => v as String?), generatedApks: $checkedConvert('generated_apks', (v) => v as bool?), environment: $checkedConvert( 'environment', @@ -23,12 +27,23 @@ UpdateReleaseMetadata _$UpdateReleaseMetadataFromJson( ); return val; }, - fieldKeyMap: const {'generatedApks': 'generated_apks'}, + fieldKeyMap: const { + 'releasePlatform': 'release_platform', + 'flutterVersionOverride': 'flutter_version_override', + 'generatedApks': 'generated_apks' + }, ); Map _$UpdateReleaseMetadataToJson( UpdateReleaseMetadata instance) => { + 'release_platform': _$ReleasePlatformEnumMap[instance.releasePlatform]!, + 'flutter_version_override': instance.flutterVersionOverride, 'generated_apks': instance.generatedApks, 'environment': instance.environment.toJson(), }; + +const _$ReleasePlatformEnumMap = { + ReleasePlatform.android: 'android', + ReleasePlatform.ios: 'ios', +}; diff --git a/packages/shorebird_code_push_protocol/test/src/messages/create_patch/create_patch_request_test.dart b/packages/shorebird_code_push_protocol/test/src/messages/create_patch/create_patch_request_test.dart index 1b897d05d..e2f3ba1c8 100644 --- a/packages/shorebird_code_push_protocol/test/src/messages/create_patch/create_patch_request_test.dart +++ b/packages/shorebird_code_push_protocol/test/src/messages/create_patch/create_patch_request_test.dart @@ -10,6 +10,7 @@ void main() { hasAssetChanges: true, hasNativeChanges: false, metadata: CreatePatchMetadata( + releasePlatform: ReleasePlatform.android, usedIgnoreAssetChangesFlag: true, usedIgnoreNativeChangesFlag: false, hasAssetChanges: true, @@ -17,6 +18,7 @@ void main() { environment: BuildEnvironmentMetadata( operatingSystem: 'linux', operatingSystemVersion: '1.0.0', + shorebirdVersion: '1.2.3', xcodeVersion: null, ), ), diff --git a/packages/shorebird_code_push_protocol/test/src/messages/update_release/update_release_request_test.dart b/packages/shorebird_code_push_protocol/test/src/messages/update_release/update_release_request_test.dart index 6104df75d..4cdc626bf 100644 --- a/packages/shorebird_code_push_protocol/test/src/messages/update_release/update_release_request_test.dart +++ b/packages/shorebird_code_push_protocol/test/src/messages/update_release/update_release_request_test.dart @@ -8,10 +8,13 @@ void main() { platform: ReleasePlatform.android, status: ReleaseStatus.active, metadata: UpdateReleaseMetadata( + releasePlatform: ReleasePlatform.ios, + flutterVersionOverride: null, generatedApks: null, environment: BuildEnvironmentMetadata( operatingSystem: 'macos', operatingSystemVersion: '11.1', + shorebirdVersion: '1.2.3', xcodeVersion: '15.3', ), ), From bcb769bf2e9c26e413bebf64db75fc991d7b0682 Mon Sep 17 00:00:00 2001 From: Bryan Oltman Date: Tue, 26 Mar 2024 17:42:50 -0400 Subject: [PATCH 03/13] Support equatable for metadata types --- .../lib/src/models/build_environment_metadata.dart | 11 ++++++++++- .../lib/src/models/create_patch_metadata.dart | 13 ++++++++++++- packages/shorebird_code_push_protocol/pubspec.yaml | 3 ++- 3 files changed, 24 insertions(+), 3 deletions(-) diff --git a/packages/shorebird_code_push_protocol/lib/src/models/build_environment_metadata.dart b/packages/shorebird_code_push_protocol/lib/src/models/build_environment_metadata.dart index c659da4c5..49f37a0b6 100644 --- a/packages/shorebird_code_push_protocol/lib/src/models/build_environment_metadata.dart +++ b/packages/shorebird_code_push_protocol/lib/src/models/build_environment_metadata.dart @@ -1,3 +1,4 @@ +import 'package:equatable/equatable.dart'; import 'package:json_annotation/json_annotation.dart'; part 'build_environment_metadata.g.dart'; @@ -6,7 +7,7 @@ part 'build_environment_metadata.g.dart'; /// Information about the environment used to build a release or patch. /// {@endtemplate} @JsonSerializable() -class BuildEnvironmentMetadata { +class BuildEnvironmentMetadata extends Equatable { /// {@macro build_environment_metadata} const BuildEnvironmentMetadata({ required this.shorebirdVersion, @@ -34,4 +35,12 @@ class BuildEnvironmentMetadata { /// The version of Xcode used to build the patch. Only provided for iOS /// patches. final String? xcodeVersion; + + @override + List get props => [ + shorebirdVersion, + operatingSystem, + operatingSystemVersion, + xcodeVersion, + ]; } diff --git a/packages/shorebird_code_push_protocol/lib/src/models/create_patch_metadata.dart b/packages/shorebird_code_push_protocol/lib/src/models/create_patch_metadata.dart index 3a141c4a7..97065d0ec 100644 --- a/packages/shorebird_code_push_protocol/lib/src/models/create_patch_metadata.dart +++ b/packages/shorebird_code_push_protocol/lib/src/models/create_patch_metadata.dart @@ -1,3 +1,4 @@ +import 'package:equatable/equatable.dart'; import 'package:json_annotation/json_annotation.dart'; import 'package:shorebird_code_push_protocol/src/models/models.dart'; @@ -7,7 +8,7 @@ part 'create_patch_metadata.g.dart'; /// Information about a patch, used for debugging purposes. /// {@endtemplate} @JsonSerializable() -class CreatePatchMetadata { +class CreatePatchMetadata extends Equatable { /// {@macro create_patch_metadata} const CreatePatchMetadata({ required this.releasePlatform, @@ -42,4 +43,14 @@ class CreatePatchMetadata { /// Properties about the environment in which the patch was created. final BuildEnvironmentMetadata environment; + + @override + List get props => [ + releasePlatform, + usedIgnoreAssetChangesFlag, + hasAssetChanges, + usedIgnoreNativeChangesFlag, + hasNativeChanges, + environment, + ]; } diff --git a/packages/shorebird_code_push_protocol/pubspec.yaml b/packages/shorebird_code_push_protocol/pubspec.yaml index 421845947..0c56d47a5 100644 --- a/packages/shorebird_code_push_protocol/pubspec.yaml +++ b/packages/shorebird_code_push_protocol/pubspec.yaml @@ -9,7 +9,8 @@ environment: sdk: ">=3.0.0 <4.0.0" dependencies: - json_annotation: ^4.8.1 + equatable: ^2.0.5 + json_annotation: ^4.8.1 dev_dependencies: build_runner: ^2.0.0 From b0a4e87de1797cc1a079b49926ad1ca12c8ff7ba Mon Sep 17 00:00:00 2001 From: Bryan Oltman Date: Tue, 26 Mar 2024 17:47:13 -0400 Subject: [PATCH 04/13] feat(shorebird_cli): record release and patch command metadata --- .../lib/src/code_push_client_wrapper.dart | 15 +++--- .../src/commands/patch/patch_aar_command.dart | 27 +++++++--- .../commands/patch/patch_android_command.dart | 27 +++++++--- .../src/commands/patch/patch_ios_command.dart | 17 +++++- .../patch/patch_ios_framework_command.dart | 21 ++++++-- .../commands/release/release_aar_command.dart | 27 +++++++--- .../release/release_android_command.dart | 27 +++++++--- .../commands/release/release_ios_command.dart | 15 ++++++ .../release_ios_framework_command.dart | 14 +++++ .../lib/src/executables/xcodebuild.dart | 11 ++++ .../src/code_push_client_wrapper_test.dart | 34 +++++------- .../patch/patch_aar_command_test.dart | 39 +++++++++----- .../patch/patch_android_command_test.dart | 45 ++++++++++------ .../patch/patch_ios_command_test.dart | 52 ++++++++++++------- .../patch_ios_framework_command_test.dart | 47 +++++++++++------ .../release/release_ios_command_test.dart | 7 +++ .../release_ios_framework_command_test.dart | 6 +++ .../test/src/executables/xcodebuild_test.dart | 4 ++ .../example/main.dart | 15 +++++- .../lib/src/code_push_client.dart | 15 +++--- .../test/src/code_push_client_test.dart | 12 ++--- 21 files changed, 336 insertions(+), 141 deletions(-) diff --git a/packages/shorebird_cli/lib/src/code_push_client_wrapper.dart b/packages/shorebird_cli/lib/src/code_push_client_wrapper.dart index ab23d1664..18b15035d 100644 --- a/packages/shorebird_cli/lib/src/code_push_client_wrapper.dart +++ b/packages/shorebird_cli/lib/src/code_push_client_wrapper.dart @@ -17,6 +17,7 @@ import 'package:shorebird_cli/src/shorebird_build_mixin.dart'; import 'package:shorebird_cli/src/shorebird_env.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'; +import 'package:shorebird_code_push_protocol/shorebird_code_push_protocol.dart'; /// {@template patch_artifact_bundle} /// Metadata about a patch artifact that we are about to upload. @@ -248,6 +249,7 @@ Please create a release using "shorebird release" and try again. required int releaseId, required ReleasePlatform platform, required ReleaseStatus status, + UpdateReleaseMetadata? metadata, }) async { final updateStatusProgress = logger.progress('Updating release status'); try { @@ -256,6 +258,7 @@ Please create a release using "shorebird release" and try again. releaseId: releaseId, platform: platform, status: status, + metadata: metadata, ); updateStatusProgress.complete(); } catch (error) { @@ -642,16 +645,14 @@ aar artifact already exists, continuing...''', Future createPatch({ required String appId, required int releaseId, - required bool hasAssetChanges, - required bool hasNativeChanges, + required CreatePatchMetadata metadata, }) async { final createPatchProgress = logger.progress('Creating patch'); try { final patch = await codePushClient.createPatch( appId: appId, releaseId: releaseId, - hasAssetChanges: hasAssetChanges, - hasNativeChanges: hasNativeChanges, + metadata: metadata, ); createPatchProgress.complete(); return patch; @@ -709,8 +710,7 @@ aar artifact already exists, continuing...''', Future publishPatch({ required String appId, required int releaseId, - required bool hasAssetChanges, - required bool hasNativeChanges, + required CreatePatchMetadata metadata, required ReleasePlatform platform, required DeploymentTrack track, required Map patchArtifactBundles, @@ -718,8 +718,7 @@ aar artifact already exists, continuing...''', final patch = await createPatch( appId: appId, releaseId: releaseId, - hasAssetChanges: hasAssetChanges, - hasNativeChanges: hasNativeChanges, + metadata: metadata, ); await createPatchArtifacts( diff --git a/packages/shorebird_cli/lib/src/commands/patch/patch_aar_command.dart b/packages/shorebird_cli/lib/src/commands/patch/patch_aar_command.dart index 021765933..eb792da1b 100644 --- a/packages/shorebird_cli/lib/src/commands/patch/patch_aar_command.dart +++ b/packages/shorebird_cli/lib/src/commands/patch/patch_aar_command.dart @@ -18,11 +18,13 @@ import 'package:shorebird_cli/src/deployment_track.dart'; import 'package:shorebird_cli/src/formatters/file_size_formatter.dart'; import 'package:shorebird_cli/src/logger.dart'; import 'package:shorebird_cli/src/patch_diff_checker.dart'; +import 'package:shorebird_cli/src/platform.dart'; import 'package:shorebird_cli/src/shorebird_artifact_mixin.dart'; import 'package:shorebird_cli/src/shorebird_build_mixin.dart'; import 'package:shorebird_cli/src/shorebird_env.dart'; import 'package:shorebird_cli/src/shorebird_flutter.dart'; import 'package:shorebird_cli/src/shorebird_validator.dart'; +import 'package:shorebird_cli/src/version.dart'; import 'package:shorebird_code_push_client/shorebird_code_push_client.dart'; /// {@template patch_aar_command} @@ -151,19 +153,19 @@ Please re-run the release command for this version or create a new release.'''); return ExitCode.software.code; } - const platform = ReleasePlatform.android; + const releasePlatform = ReleasePlatform.android; final releaseArtifacts = await codePushClientWrapper.getReleaseArtifacts( appId: appId, releaseId: release.id, architectures: architectures, - platform: platform, + platform: releasePlatform, ); final releaseAarArtifact = await codePushClientWrapper.getReleaseArtifact( appId: appId, releaseId: release.id, arch: 'aar', - platform: platform, + platform: releasePlatform, ); final Map releaseArtifactPaths; @@ -250,7 +252,7 @@ Please re-run the release command for this version or create a new release.'''); final summary = [ '''šŸ“± App: ${lightCyan.wrap(app.displayName)} ${lightCyan.wrap('(${app.appId})')}''', 'šŸ“¦ Release Version: ${lightCyan.wrap(releaseVersion)}', - '''šŸ•¹ļø Platform: ${lightCyan.wrap(platform.name)} ${lightCyan.wrap('[${archMetadata.join(', ')}]')}''', + '''šŸ•¹ļø Platform: ${lightCyan.wrap(releasePlatform.name)} ${lightCyan.wrap('[${archMetadata.join(', ')}]')}''', 'šŸŸ¢ Track: ${lightCyan.wrap('Production')}', ]; @@ -276,11 +278,22 @@ ${summary.join('\n')} await codePushClientWrapper.publishPatch( appId: appId, releaseId: release.id, - hasAssetChanges: diffStatus.hasAssetChanges, - hasNativeChanges: diffStatus.hasNativeChanges, - platform: platform, + platform: releasePlatform, track: DeploymentTrack.production, patchArtifactBundles: patchArtifactBundles, + metadata: CreatePatchMetadata( + releasePlatform: releasePlatform, + usedIgnoreAssetChangesFlag: allowNativeDiffs, + hasAssetChanges: diffStatus.hasAssetChanges, + usedIgnoreNativeChangesFlag: allowNativeDiffs, + hasNativeChanges: diffStatus.hasNativeChanges, + environment: BuildEnvironmentMetadata( + operatingSystem: platform.operatingSystem, + operatingSystemVersion: platform.operatingSystemVersion, + shorebirdVersion: packageVersion, + xcodeVersion: null, + ), + ), ); return ExitCode.success.code; diff --git a/packages/shorebird_cli/lib/src/commands/patch/patch_android_command.dart b/packages/shorebird_cli/lib/src/commands/patch/patch_android_command.dart index 749a60316..a16ea9c06 100644 --- a/packages/shorebird_cli/lib/src/commands/patch/patch_android_command.dart +++ b/packages/shorebird_cli/lib/src/commands/patch/patch_android_command.dart @@ -18,11 +18,13 @@ import 'package:shorebird_cli/src/extensions/arg_results.dart'; import 'package:shorebird_cli/src/formatters/formatters.dart'; import 'package:shorebird_cli/src/logger.dart'; import 'package:shorebird_cli/src/patch_diff_checker.dart'; +import 'package:shorebird_cli/src/platform.dart'; import 'package:shorebird_cli/src/shorebird_build_mixin.dart'; import 'package:shorebird_cli/src/shorebird_env.dart'; import 'package:shorebird_cli/src/shorebird_flutter.dart'; import 'package:shorebird_cli/src/shorebird_release_version_mixin.dart'; import 'package:shorebird_cli/src/shorebird_validator.dart'; +import 'package:shorebird_cli/src/version.dart'; import 'package:shorebird_code_push_client/shorebird_code_push_client.dart'; /// {@template patch_android_command} @@ -121,7 +123,7 @@ If this option is not provided, the version number will be determined from the p await cache.updateAll(); - const platform = ReleasePlatform.android; + const releasePlatform = ReleasePlatform.android; final flavor = results.findOption('flavor', argParser: argParser); final target = results.findOption('target', argParser: argParser); @@ -252,7 +254,7 @@ Looked in: appId: app.appId, releaseId: release.id, architectures: architectures, - platform: platform, + platform: releasePlatform, ); final releaseAabArtifact = @@ -260,7 +262,7 @@ Looked in: appId: app.appId, releaseId: release.id, arch: 'aab', - platform: platform, + platform: releasePlatform, ); final releaseArtifactPaths = {}; @@ -350,7 +352,7 @@ Looked in: '''šŸ“± App: ${lightCyan.wrap(app.displayName)} ${lightCyan.wrap('(${app.appId})')}''', if (flavor != null) 'šŸ§ Flavor: ${lightCyan.wrap(flavor)}', 'šŸ“¦ Release Version: ${lightCyan.wrap(releaseVersion)}', - '''šŸ•¹ļø Platform: ${lightCyan.wrap(platform.name)} ${lightCyan.wrap('[${archMetadata.join(', ')}]')}''', + '''šŸ•¹ļø Platform: ${lightCyan.wrap(releasePlatform.name)} ${lightCyan.wrap('[${archMetadata.join(', ')}]')}''', if (isStaging) 'šŸŸ  Track: ${lightCyan.wrap('Staging')}' else @@ -379,9 +381,20 @@ ${summary.join('\n')} await codePushClientWrapper.publishPatch( appId: appId, releaseId: release.id, - hasAssetChanges: diffStatus.hasAssetChanges, - hasNativeChanges: diffStatus.hasNativeChanges, - platform: platform, + metadata: CreatePatchMetadata( + releasePlatform: releasePlatform, + usedIgnoreAssetChangesFlag: allowNativeDiffs, + hasAssetChanges: diffStatus.hasAssetChanges, + usedIgnoreNativeChangesFlag: allowNativeDiffs, + hasNativeChanges: diffStatus.hasNativeChanges, + environment: BuildEnvironmentMetadata( + operatingSystem: platform.operatingSystem, + operatingSystemVersion: platform.operatingSystemVersion, + shorebirdVersion: packageVersion, + xcodeVersion: null, + ), + ), + platform: releasePlatform, track: isStaging ? DeploymentTrack.staging : DeploymentTrack.production, patchArtifactBundles: patchArtifactBundles, diff --git a/packages/shorebird_cli/lib/src/commands/patch/patch_ios_command.dart b/packages/shorebird_cli/lib/src/commands/patch/patch_ios_command.dart index 3266c55ee..2fe9941b9 100644 --- a/packages/shorebird_cli/lib/src/commands/patch/patch_ios_command.dart +++ b/packages/shorebird_cli/lib/src/commands/patch/patch_ios_command.dart @@ -20,6 +20,7 @@ import 'package:shorebird_cli/src/extensions/arg_results.dart'; import 'package:shorebird_cli/src/formatters/file_size_formatter.dart'; import 'package:shorebird_cli/src/logger.dart'; import 'package:shorebird_cli/src/patch_diff_checker.dart'; +import 'package:shorebird_cli/src/platform.dart'; import 'package:shorebird_cli/src/platform/platform.dart'; import 'package:shorebird_cli/src/shorebird_artifact_mixin.dart'; import 'package:shorebird_cli/src/shorebird_artifacts.dart'; @@ -27,6 +28,7 @@ import 'package:shorebird_cli/src/shorebird_build_mixin.dart'; import 'package:shorebird_cli/src/shorebird_env.dart'; import 'package:shorebird_cli/src/shorebird_flutter.dart'; import 'package:shorebird_cli/src/shorebird_validator.dart'; +import 'package:shorebird_cli/src/version.dart'; import 'package:shorebird_code_push_client/shorebird_code_push_client.dart'; /// {@template patch_ios_command} @@ -394,8 +396,6 @@ ${summary.join('\n')} await codePushClientWrapper.publishPatch( appId: appId, releaseId: release.id, - hasAssetChanges: diffStatus.hasAssetChanges, - hasNativeChanges: diffStatus.hasNativeChanges, platform: releasePlatform, track: isStaging ? DeploymentTrack.staging : DeploymentTrack.production, @@ -407,6 +407,19 @@ ${summary.join('\n')} size: patchFileSize, ), }, + metadata: CreatePatchMetadata( + releasePlatform: releasePlatform, + usedIgnoreAssetChangesFlag: allowNativeDiffs, + hasAssetChanges: diffStatus.hasAssetChanges, + usedIgnoreNativeChangesFlag: allowNativeDiffs, + hasNativeChanges: diffStatus.hasNativeChanges, + environment: BuildEnvironmentMetadata( + operatingSystem: platform.operatingSystem, + operatingSystemVersion: platform.operatingSystemVersion, + shorebirdVersion: packageVersion, + xcodeVersion: await xcodeBuild.version(), + ), + ), ); return ExitCode.success.code; diff --git a/packages/shorebird_cli/lib/src/commands/patch/patch_ios_framework_command.dart b/packages/shorebird_cli/lib/src/commands/patch/patch_ios_framework_command.dart index 557f099c9..2b9e7cea8 100644 --- a/packages/shorebird_cli/lib/src/commands/patch/patch_ios_framework_command.dart +++ b/packages/shorebird_cli/lib/src/commands/patch/patch_ios_framework_command.dart @@ -15,17 +15,19 @@ import 'package:shorebird_cli/src/config/shorebird_yaml.dart'; import 'package:shorebird_cli/src/deployment_track.dart'; import 'package:shorebird_cli/src/doctor.dart'; import 'package:shorebird_cli/src/engine_config.dart'; -import 'package:shorebird_cli/src/executables/aot_tools.dart'; +import 'package:shorebird_cli/src/executables/executables.dart'; import 'package:shorebird_cli/src/formatters/file_size_formatter.dart'; import 'package:shorebird_cli/src/logger.dart'; import 'package:shorebird_cli/src/patch_diff_checker.dart'; -import 'package:shorebird_cli/src/platform/platform.dart'; +import 'package:shorebird_cli/src/platform.dart'; +import 'package:shorebird_cli/src/platform/ios.dart'; import 'package:shorebird_cli/src/shorebird_artifact_mixin.dart'; import 'package:shorebird_cli/src/shorebird_artifacts.dart'; import 'package:shorebird_cli/src/shorebird_build_mixin.dart'; import 'package:shorebird_cli/src/shorebird_env.dart'; import 'package:shorebird_cli/src/shorebird_flutter.dart'; import 'package:shorebird_cli/src/shorebird_validator.dart'; +import 'package:shorebird_cli/src/version.dart'; import 'package:shorebird_code_push_client/shorebird_code_push_client.dart'; class PatchIosFrameworkCommand extends ShorebirdCommand @@ -332,8 +334,6 @@ ${summary.join('\n')} await codePushClientWrapper.publishPatch( appId: appId, releaseId: release.id, - hasAssetChanges: diffStatus.hasAssetChanges, - hasNativeChanges: diffStatus.hasNativeChanges, platform: releasePlatform, track: DeploymentTrack.production, patchArtifactBundles: { @@ -344,6 +344,19 @@ ${summary.join('\n')} size: patchFileSize, ), }, + metadata: CreatePatchMetadata( + releasePlatform: releasePlatform, + usedIgnoreAssetChangesFlag: allowNativeDiffs, + hasAssetChanges: diffStatus.hasAssetChanges, + usedIgnoreNativeChangesFlag: allowNativeDiffs, + hasNativeChanges: diffStatus.hasNativeChanges, + environment: BuildEnvironmentMetadata( + operatingSystem: platform.operatingSystem, + operatingSystemVersion: platform.operatingSystemVersion, + shorebirdVersion: packageVersion, + xcodeVersion: await xcodeBuild.version(), + ), + ), ); return ExitCode.success.code; diff --git a/packages/shorebird_cli/lib/src/commands/release/release_aar_command.dart b/packages/shorebird_cli/lib/src/commands/release/release_aar_command.dart index bb34cf39c..6da27312c 100644 --- a/packages/shorebird_cli/lib/src/commands/release/release_aar_command.dart +++ b/packages/shorebird_cli/lib/src/commands/release/release_aar_command.dart @@ -11,12 +11,14 @@ import 'package:shorebird_cli/src/command.dart'; import 'package:shorebird_cli/src/commands/release/release.dart'; import 'package:shorebird_cli/src/config/config.dart'; import 'package:shorebird_cli/src/logger.dart'; +import 'package:shorebird_cli/src/platform.dart'; import 'package:shorebird_cli/src/shorebird_artifact_mixin.dart'; import 'package:shorebird_cli/src/shorebird_build_mixin.dart'; import 'package:shorebird_cli/src/shorebird_env.dart'; import 'package:shorebird_cli/src/shorebird_flutter.dart'; import 'package:shorebird_cli/src/shorebird_release_version_mixin.dart'; import 'package:shorebird_cli/src/shorebird_validator.dart'; +import 'package:shorebird_cli/src/version.dart'; import 'package:shorebird_code_push_client/shorebird_code_push_client.dart'; /// {@template release_aar_command} @@ -95,7 +97,7 @@ make smaller updates to your app. return ExitCode.config.code; } - const platform = ReleasePlatform.android; + const releasePlatform = ReleasePlatform.android; final buildNumber = results['build-number'] as String; final releaseVersion = results['release-version'] as String; final flutterVersion = results['flutter-version'] as String?; @@ -111,7 +113,7 @@ make smaller updates to your app. if (existingRelease != null) { codePushClientWrapper.ensureReleaseIsNotActive( release: existingRelease, - platform: platform, + platform: releasePlatform, ); } @@ -181,7 +183,7 @@ Use `shorebird flutter versions list` to list available versions. final summary = [ '''šŸ“± App: ${lightCyan.wrap(app.displayName)} ${lightCyan.wrap('(${app.appId})')}''', 'šŸ“¦ Release Version: ${lightCyan.wrap(releaseVersion)}', - '''šŸ•¹ļø Platform: ${lightCyan.wrap(platform.name)} ${lightCyan.wrap('(${archNames.join(', ')})')}''', + '''šŸ•¹ļø Platform: ${lightCyan.wrap(releasePlatform.name)} ${lightCyan.wrap('(${archNames.join(', ')})')}''', 'šŸ¦ Flutter Version: ${lightCyan.wrap(flutterVersionString)}', ]; @@ -208,7 +210,7 @@ ${summary.join('\n')} await codePushClientWrapper.updateReleaseStatus( appId: appId, releaseId: release.id, - platform: platform, + platform: releasePlatform, status: ReleaseStatus.draft, ); } else { @@ -216,7 +218,7 @@ ${summary.join('\n')} appId: appId, version: releaseVersion, flutterRevision: shorebirdEnv.flutterRevision, - platform: platform, + platform: releasePlatform, ); } @@ -242,7 +244,7 @@ ${summary.join('\n')} await codePushClientWrapper.createAndroidArchiveReleaseArtifacts( appId: app.appId, releaseId: release.id, - platform: platform, + platform: releasePlatform, aarPath: aarArtifactPath( packageName: shorebirdEnv.androidPackageName!, buildNumber: buildNumber, @@ -254,8 +256,19 @@ ${summary.join('\n')} await codePushClientWrapper.updateReleaseStatus( appId: app.appId, releaseId: release.id, - platform: platform, + platform: releasePlatform, status: ReleaseStatus.active, + metadata: UpdateReleaseMetadata( + releasePlatform: releasePlatform, + flutterVersionOverride: flutterVersion, + generatedApks: false, + environment: BuildEnvironmentMetadata( + operatingSystem: platform.operatingSystem, + operatingSystemVersion: platform.operatingSystemVersion, + shorebirdVersion: packageVersion, + xcodeVersion: null, + ), + ), ); logger diff --git a/packages/shorebird_cli/lib/src/commands/release/release_android_command.dart b/packages/shorebird_cli/lib/src/commands/release/release_android_command.dart index 7149f7daf..7fd6b1045 100644 --- a/packages/shorebird_cli/lib/src/commands/release/release_android_command.dart +++ b/packages/shorebird_cli/lib/src/commands/release/release_android_command.dart @@ -10,11 +10,13 @@ import 'package:shorebird_cli/src/config/shorebird_yaml.dart'; import 'package:shorebird_cli/src/doctor.dart'; import 'package:shorebird_cli/src/extensions/arg_results.dart'; import 'package:shorebird_cli/src/logger.dart'; +import 'package:shorebird_cli/src/platform.dart'; import 'package:shorebird_cli/src/shorebird_build_mixin.dart'; import 'package:shorebird_cli/src/shorebird_env.dart'; import 'package:shorebird_cli/src/shorebird_flutter.dart'; import 'package:shorebird_cli/src/shorebird_release_version_mixin.dart'; import 'package:shorebird_cli/src/shorebird_validator.dart'; +import 'package:shorebird_cli/src/version.dart'; import 'package:shorebird_code_push_client/shorebird_code_push_client.dart'; /// {@template release_android_command} @@ -94,7 +96,7 @@ make smaller updates to your app. return ExitCode.usage.code; } - const platform = ReleasePlatform.android; + const releasePlatform = ReleasePlatform.android; final flavor = results.findOption('flavor', argParser: argParser); final target = results.findOption('target', argParser: argParser); final generateApk = results['artifact'] as String == 'apk'; @@ -231,7 +233,7 @@ Use `shorebird flutter versions list` to list available versions. if (existingRelease != null) { codePushClientWrapper.ensureReleaseIsNotActive( release: existingRelease, - platform: platform, + platform: releasePlatform, ); } @@ -240,7 +242,7 @@ Use `shorebird flutter versions list` to list available versions. '''šŸ“± App: ${lightCyan.wrap(app.displayName)} ${lightCyan.wrap('(${app.appId})')}''', if (flavor != null) 'šŸ§ Flavor: ${lightCyan.wrap(flavor)}', 'šŸ“¦ Release Version: ${lightCyan.wrap(releaseVersion)}', - '''šŸ•¹ļø Platform: ${lightCyan.wrap(platform.name)} ${lightCyan.wrap('(${archNames.join(', ')})')}''', + '''šŸ•¹ļø Platform: ${lightCyan.wrap(releasePlatform.name)} ${lightCyan.wrap('(${archNames.join(', ')})')}''', 'šŸ¦ Flutter Version: ${lightCyan.wrap(flutterVersionString)}', ]; @@ -267,7 +269,7 @@ ${summary.join('\n')} await codePushClientWrapper.updateReleaseStatus( appId: appId, releaseId: release.id, - platform: platform, + platform: releasePlatform, status: ReleaseStatus.draft, ); } else { @@ -275,7 +277,7 @@ ${summary.join('\n')} appId: appId, version: releaseVersion, flutterRevision: shorebirdEnv.flutterRevision, - platform: platform, + platform: releasePlatform, ); } @@ -284,7 +286,7 @@ ${summary.join('\n')} releaseId: release.id, projectRoot: projectRoot.path, aabPath: bundlePath, - platform: platform, + platform: releasePlatform, architectures: architectures, flavor: flavor, ); @@ -292,8 +294,19 @@ ${summary.join('\n')} await codePushClientWrapper.updateReleaseStatus( appId: app.appId, releaseId: release.id, - platform: platform, + platform: releasePlatform, status: ReleaseStatus.active, + metadata: UpdateReleaseMetadata( + releasePlatform: releasePlatform, + flutterVersionOverride: flutterVersion, + generatedApks: false, + environment: BuildEnvironmentMetadata( + operatingSystem: platform.operatingSystem, + operatingSystemVersion: platform.operatingSystemVersion, + shorebirdVersion: packageVersion, + xcodeVersion: null, + ), + ), ); // The extra newline before and no newline after is intentional. See diff --git a/packages/shorebird_cli/lib/src/commands/release/release_ios_command.dart b/packages/shorebird_cli/lib/src/commands/release/release_ios_command.dart index dda485eb8..3ed2a3b30 100644 --- a/packages/shorebird_cli/lib/src/commands/release/release_ios_command.dart +++ b/packages/shorebird_cli/lib/src/commands/release/release_ios_command.dart @@ -10,8 +10,10 @@ import 'package:shorebird_cli/src/command.dart'; import 'package:shorebird_cli/src/commands/commands.dart'; import 'package:shorebird_cli/src/config/config.dart'; import 'package:shorebird_cli/src/doctor.dart'; +import 'package:shorebird_cli/src/executables/xcodebuild.dart'; import 'package:shorebird_cli/src/extensions/arg_results.dart'; import 'package:shorebird_cli/src/logger.dart'; +import 'package:shorebird_cli/src/platform.dart'; import 'package:shorebird_cli/src/platform/platform.dart'; import 'package:shorebird_cli/src/shorebird_artifact_mixin.dart'; import 'package:shorebird_cli/src/shorebird_build_mixin.dart'; @@ -19,6 +21,7 @@ import 'package:shorebird_cli/src/shorebird_env.dart'; import 'package:shorebird_cli/src/shorebird_flutter.dart'; import 'package:shorebird_cli/src/shorebird_validator.dart'; import 'package:shorebird_cli/src/validators/validators.dart'; +import 'package:shorebird_cli/src/version.dart'; import 'package:shorebird_code_push_client/shorebird_code_push_client.dart'; /// {@template release_ios_command} @@ -297,6 +300,7 @@ ${summary.join('\n')} releaseId: release.id, platform: releasePlatform, status: ReleaseStatus.draft, + metadata: null, ); } else { release = await codePushClientWrapper.createRelease( @@ -320,6 +324,17 @@ ${summary.join('\n')} releaseId: release.id, platform: releasePlatform, status: ReleaseStatus.active, + metadata: UpdateReleaseMetadata( + releasePlatform: releasePlatform, + flutterVersionOverride: flutterVersion, + generatedApks: false, + environment: BuildEnvironmentMetadata( + operatingSystem: platform.operatingSystem, + operatingSystemVersion: platform.operatingSystemVersion, + shorebirdVersion: packageVersion, + xcodeVersion: await xcodeBuild.version(), + ), + ), ); logger.success('\nāœ… Published Release ${release.version}!'); diff --git a/packages/shorebird_cli/lib/src/commands/release/release_ios_framework_command.dart b/packages/shorebird_cli/lib/src/commands/release/release_ios_framework_command.dart index d79b86f72..95d2221f2 100644 --- a/packages/shorebird_cli/lib/src/commands/release/release_ios_framework_command.dart +++ b/packages/shorebird_cli/lib/src/commands/release/release_ios_framework_command.dart @@ -10,13 +10,16 @@ import 'package:shorebird_cli/src/command.dart'; import 'package:shorebird_cli/src/commands/commands.dart'; import 'package:shorebird_cli/src/config/config.dart'; import 'package:shorebird_cli/src/doctor.dart'; +import 'package:shorebird_cli/src/executables/xcodebuild.dart'; import 'package:shorebird_cli/src/logger.dart'; +import 'package:shorebird_cli/src/platform.dart'; import 'package:shorebird_cli/src/shorebird_artifact_mixin.dart'; import 'package:shorebird_cli/src/shorebird_build_mixin.dart'; import 'package:shorebird_cli/src/shorebird_env.dart'; import 'package:shorebird_cli/src/shorebird_flutter.dart'; import 'package:shorebird_cli/src/shorebird_validator.dart'; import 'package:shorebird_cli/src/validators/validators.dart'; +import 'package:shorebird_cli/src/version.dart'; import 'package:shorebird_code_push_client/shorebird_code_push_client.dart'; class ReleaseIosFrameworkCommand extends ShorebirdCommand @@ -233,6 +236,17 @@ ${summary.join('\n')} releaseId: release.id, platform: releasePlatform, status: ReleaseStatus.active, + metadata: UpdateReleaseMetadata( + releasePlatform: releasePlatform, + flutterVersionOverride: flutterVersion, + generatedApks: false, + environment: BuildEnvironmentMetadata( + operatingSystem: platform.operatingSystem, + operatingSystemVersion: platform.operatingSystemVersion, + shorebirdVersion: packageVersion, + xcodeVersion: await xcodeBuild.version(), + ), + ), ); final relativeFrameworkDirectoryPath = diff --git a/packages/shorebird_cli/lib/src/executables/xcodebuild.dart b/packages/shorebird_cli/lib/src/executables/xcodebuild.dart index ed5f3369d..15bc6d965 100644 --- a/packages/shorebird_cli/lib/src/executables/xcodebuild.dart +++ b/packages/shorebird_cli/lib/src/executables/xcodebuild.dart @@ -106,4 +106,15 @@ class XcodeBuild { schemes: schemes, ); } + + /// Get the current Xcode version. + Future version() async { + final result = await process.run(executable, ['-version']); + if (result.exitCode != ExitCode.success.code) { + throw ProcessException(executable, ['-version'], '${result.stderr}'); + } + + final lines = LineSplitter.split('${result.stdout}').map((e) => e.trim()); + return lines.join(' '); + } } diff --git a/packages/shorebird_cli/test/src/code_push_client_wrapper_test.dart b/packages/shorebird_cli/test/src/code_push_client_wrapper_test.dart index 8b0fbefc9..3a4c89b70 100644 --- a/packages/shorebird_cli/test/src/code_push_client_wrapper_test.dart +++ b/packages/shorebird_cli/test/src/code_push_client_wrapper_test.dart @@ -24,6 +24,10 @@ void main() { late Platform platform; late ShorebirdEnv shorebirdEnv; + setUpAll(() { + registerFallbackValue(CreatePatchMetadata.forTest()); + }); + setUp(() { auth = MockAuth(); httpClient = MockHttpClient(); @@ -1804,8 +1808,7 @@ Please bump your version number and try again.''', () => codePushClient.createPatch( appId: appId, releaseId: releaseId, - hasAssetChanges: any(named: 'hasAssetChanges'), - hasNativeChanges: any(named: 'hasNativeChanges'), + metadata: any(named: 'metadata'), ), ).thenThrow(error); @@ -1814,8 +1817,7 @@ Please bump your version number and try again.''', () => codePushClientWrapper.createPatch( appId: appId, releaseId: releaseId, - hasAssetChanges: false, - hasNativeChanges: false, + metadata: CreatePatchMetadata.forTest(), ), ), exitsWithCode(ExitCode.software), @@ -1828,8 +1830,7 @@ Please bump your version number and try again.''', () => codePushClient.createPatch( appId: appId, releaseId: releaseId, - hasAssetChanges: any(named: 'hasAssetChanges'), - hasNativeChanges: any(named: 'hasNativeChanges'), + metadata: any(named: 'metadata'), ), ).thenAnswer((_) async => patch); @@ -1837,8 +1838,7 @@ Please bump your version number and try again.''', () => codePushClientWrapper.createPatch( appId: appId, releaseId: releaseId, - hasAssetChanges: false, - hasNativeChanges: false, + metadata: CreatePatchMetadata.forTest(), ), ); @@ -1965,8 +1965,7 @@ Please bump your version number and try again.''', () => codePushClient.createPatch( appId: any(named: 'appId'), releaseId: any(named: 'releaseId'), - hasAssetChanges: any(named: 'hasAssetChanges'), - hasNativeChanges: any(named: 'hasNativeChanges'), + metadata: any(named: 'metadata'), ), ).thenAnswer((_) async => patch); when( @@ -1996,11 +1995,10 @@ Please bump your version number and try again.''', () => codePushClientWrapper.publishPatch( appId: appId, releaseId: releaseId, - hasAssetChanges: true, - hasNativeChanges: false, platform: releasePlatform, track: track, patchArtifactBundles: patchArtifactBundles, + metadata: CreatePatchMetadata.forTest(), ), ); @@ -2008,8 +2006,7 @@ Please bump your version number and try again.''', () => codePushClient.createPatch( appId: appId, releaseId: releaseId, - hasAssetChanges: true, - hasNativeChanges: false, + metadata: CreatePatchMetadata.forTest(), ), ).called(1); verify( @@ -2054,11 +2051,10 @@ Please bump your version number and try again.''', () => codePushClientWrapper.publishPatch( appId: appId, releaseId: releaseId, - hasAssetChanges: false, - hasNativeChanges: true, platform: releasePlatform, track: track, patchArtifactBundles: patchArtifactBundles, + metadata: CreatePatchMetadata.forTest(), ), ); @@ -2066,8 +2062,7 @@ Please bump your version number and try again.''', () => codePushClient.createPatch( appId: appId, releaseId: releaseId, - hasAssetChanges: false, - hasNativeChanges: true, + metadata: CreatePatchMetadata.forTest(), ), ).called(1); verify( @@ -2101,11 +2096,10 @@ Please bump your version number and try again.''', () => codePushClientWrapper.publishPatch( appId: appId, releaseId: releaseId, - hasAssetChanges: false, - hasNativeChanges: false, platform: releasePlatform, track: track, patchArtifactBundles: patchArtifactBundles, + metadata: CreatePatchMetadata.forTest(), ), ); diff --git a/packages/shorebird_cli/test/src/commands/patch/patch_aar_command_test.dart b/packages/shorebird_cli/test/src/commands/patch/patch_aar_command_test.dart index d843ac67d..545198e6c 100644 --- a/packages/shorebird_cli/test/src/commands/patch/patch_aar_command_test.dart +++ b/packages/shorebird_cli/test/src/commands/patch/patch_aar_command_test.dart @@ -156,6 +156,7 @@ void main() { } setUpAll(() { + registerFallbackValue(CreatePatchMetadata.forTest()); registerFallbackValue(Directory('')); registerFallbackValue(File('')); registerFallbackValue(FileSetDiff.empty()); @@ -195,6 +196,8 @@ void main() { when(() => operatingSystemInterface.which('flutter')) .thenReturn('/path/to/flutter'); when(() => platform.environment).thenReturn({}); + when(() => platform.operatingSystem).thenReturn('macos'); + when(() => platform.operatingSystemVersion).thenReturn('1.2.3'); when(() => shorebirdEnv.shorebirdRoot).thenReturn(shorebirdRoot); when( () => shorebirdEnv.copyWith( @@ -305,11 +308,10 @@ void main() { () => codePushClientWrapper.publishPatch( appId: any(named: 'appId'), releaseId: any(named: 'releaseId'), - hasAssetChanges: any(named: 'hasAssetChanges'), - hasNativeChanges: any(named: 'hasNativeChanges'), platform: any(named: 'platform'), track: any(named: 'track'), patchArtifactBundles: any(named: 'patchArtifactBundles'), + metadata: any(named: 'metadata'), ), ).thenAnswer((_) async {}); when(() => cache.updateAll()).thenAnswer((_) async => {}); @@ -663,12 +665,11 @@ Please re-run the release command for this version or create a new release.'''), verifyNever( () => codePushClientWrapper.publishPatch( appId: any(named: 'appId'), - hasAssetChanges: any(named: 'hasAssetChanges'), - hasNativeChanges: any(named: 'hasNativeChanges'), releaseId: any(named: 'releaseId'), platform: any(named: 'platform'), track: any(named: 'track'), patchArtifactBundles: any(named: 'patchArtifactBundles'), + metadata: any(named: 'metadata'), ), ); }); @@ -704,11 +705,10 @@ Please re-run the release command for this version or create a new release.'''), () => codePushClientWrapper.publishPatch( appId: any(named: 'appId'), releaseId: any(named: 'releaseId'), - hasAssetChanges: any(named: 'hasAssetChanges'), - hasNativeChanges: any(named: 'hasNativeChanges'), platform: any(named: 'platform'), track: any(named: 'track'), patchArtifactBundles: any(named: 'patchArtifactBundles'), + metadata: any(named: 'metadata'), ), ); }); @@ -737,11 +737,10 @@ Please re-run the release command for this version or create a new release.'''), () => codePushClientWrapper.publishPatch( appId: any(named: 'appId'), releaseId: any(named: 'releaseId'), - hasAssetChanges: any(named: 'hasAssetChanges'), - hasNativeChanges: any(named: 'hasNativeChanges'), platform: any(named: 'platform'), track: any(named: 'track'), patchArtifactBundles: any(named: 'patchArtifactBundles'), + metadata: any(named: 'metadata'), ), ); verify(() => logger.info('No issues detected.')).called(1); @@ -822,11 +821,28 @@ Please re-run the release command for this version or create a new release.'''), () => codePushClientWrapper.publishPatch( appId: appId, releaseId: release.id, - hasAssetChanges: true, - hasNativeChanges: true, platform: releasePlatform, track: track, patchArtifactBundles: any(named: 'patchArtifactBundles'), + metadata: any( + named: 'metadata', + that: isA() + .having( + (m) => m.releasePlatform, + 'releasePlatform', + ReleasePlatform.android, + ) + .having( + (m) => m.hasAssetChanges, + 'hasAssetChanges', + true, + ) + .having( + (m) => m.hasNativeChanges, + 'hasNativeChanges', + true, + ), + ), ), ).called(1); }); @@ -871,11 +887,10 @@ Please re-run the release command for this version or create a new release.'''), () => codePushClientWrapper.publishPatch( appId: appId, releaseId: release.id, - hasAssetChanges: false, - hasNativeChanges: false, platform: releasePlatform, track: track, patchArtifactBundles: any(named: 'patchArtifactBundles'), + metadata: any(named: 'metadata'), ), ).called(1); }); diff --git a/packages/shorebird_cli/test/src/commands/patch/patch_android_command_test.dart b/packages/shorebird_cli/test/src/commands/patch/patch_android_command_test.dart index 668094d71..da776839f 100644 --- a/packages/shorebird_cli/test/src/commands/patch/patch_android_command_test.dart +++ b/packages/shorebird_cli/test/src/commands/patch/patch_android_command_test.dart @@ -173,6 +173,7 @@ flutter: } setUpAll(() { + registerFallbackValue(CreatePatchMetadata.forTest()); registerFallbackValue(Directory('')); registerFallbackValue(File('')); registerFallbackValue(FileSetDiff.empty()); @@ -342,11 +343,10 @@ flutter: () => codePushClientWrapper.publishPatch( appId: any(named: 'appId'), releaseId: any(named: 'releaseId'), - hasAssetChanges: any(named: 'hasAssetChanges'), - hasNativeChanges: any(named: 'hasNativeChanges'), platform: any(named: 'platform'), track: any(named: 'track'), patchArtifactBundles: any(named: 'patchArtifactBundles'), + metadata: any(named: 'metadata'), ), ).thenAnswer((_) async {}); when( @@ -383,6 +383,8 @@ flutter: hasNativeChanges: false, ), ); + when(() => platform.operatingSystem).thenReturn('linux'); + when(() => platform.operatingSystemVersion).thenReturn('1.2.3'); when(() => shorebirdEnv.isRunningOnCI).thenReturn(false); }); @@ -754,11 +756,10 @@ Please re-run the release command for this version or create a new release.'''), () => codePushClientWrapper.publishPatch( appId: any(named: 'appId'), releaseId: any(named: 'releaseId'), - hasAssetChanges: any(named: 'hasAssetChanges'), - hasNativeChanges: any(named: 'hasNativeChanges'), platform: any(named: 'platform'), track: any(named: 'track'), patchArtifactBundles: any(named: 'patchArtifactBundles'), + metadata: any(named: 'metadata'), ), ); }); @@ -795,11 +796,10 @@ Please re-run the release command for this version or create a new release.'''), () => codePushClientWrapper.publishPatch( appId: any(named: 'appId'), releaseId: any(named: 'releaseId'), - hasAssetChanges: any(named: 'hasAssetChanges'), - hasNativeChanges: any(named: 'hasNativeChanges'), platform: any(named: 'platform'), track: any(named: 'track'), patchArtifactBundles: any(named: 'patchArtifactBundles'), + metadata: any(named: 'metadata'), ), ); }); @@ -830,11 +830,10 @@ Please re-run the release command for this version or create a new release.'''), () => codePushClientWrapper.publishPatch( appId: any(named: 'appId'), releaseId: any(named: 'releaseId'), - hasAssetChanges: any(named: 'hasAssetChanges'), - hasNativeChanges: any(named: 'hasNativeChanges'), platform: any(named: 'platform'), track: any(named: 'track'), patchArtifactBundles: any(named: 'patchArtifactBundles'), + metadata: any(named: 'metadata'), ), ); verify(() => logger.info('No issues detected.')).called(1); @@ -908,11 +907,28 @@ Please re-run the release command for this version or create a new release.'''), () => codePushClientWrapper.publishPatch( appId: appId, releaseId: release.id, - hasAssetChanges: true, - hasNativeChanges: true, platform: releasePlatform, track: track, patchArtifactBundles: any(named: 'patchArtifactBundles'), + metadata: any( + named: 'metadata', + that: isA() + .having( + (m) => m.releasePlatform, + 'releasePlatform', + ReleasePlatform.android, + ) + .having( + (m) => m.hasAssetChanges, + 'hasAssetChanges', + true, + ) + .having( + (m) => m.hasNativeChanges, + 'hasNativeChanges', + true, + ), + ), ), ).called(1); }); @@ -954,11 +970,10 @@ Please re-run the release command for this version or create a new release.'''), () => codePushClientWrapper.publishPatch( appId: appId, releaseId: release.id, - hasAssetChanges: false, - hasNativeChanges: false, platform: releasePlatform, track: track, patchArtifactBundles: any(named: 'patchArtifactBundles'), + metadata: any(named: 'metadata'), ), ).called(1); expect(exitCode, ExitCode.success.code); @@ -984,11 +999,10 @@ Please re-run the release command for this version or create a new release.'''), () => codePushClientWrapper.publishPatch( appId: appId, releaseId: release.id, - hasAssetChanges: false, - hasNativeChanges: false, platform: releasePlatform, track: DeploymentTrack.staging, patchArtifactBundles: any(named: 'patchArtifactBundles'), + metadata: any(named: 'metadata'), ), ).called(1); expect(exitCode, ExitCode.success.code); @@ -1039,11 +1053,10 @@ flavors: () => codePushClientWrapper.publishPatch( appId: appId, releaseId: release.id, - hasAssetChanges: false, - hasNativeChanges: false, platform: releasePlatform, track: track, patchArtifactBundles: any(named: 'patchArtifactBundles'), + metadata: any(named: 'metadata'), ), ).called(1); expect(exitCode, ExitCode.success.code); diff --git a/packages/shorebird_cli/test/src/commands/patch/patch_ios_command_test.dart b/packages/shorebird_cli/test/src/commands/patch/patch_ios_command_test.dart index 3a746e67a..3f5df9999 100644 --- a/packages/shorebird_cli/test/src/commands/patch/patch_ios_command_test.dart +++ b/packages/shorebird_cli/test/src/commands/patch/patch_ios_command_test.dart @@ -18,6 +18,7 @@ import 'package:shorebird_cli/src/deployment_track.dart'; import 'package:shorebird_cli/src/doctor.dart'; import 'package:shorebird_cli/src/engine_config.dart'; import 'package:shorebird_cli/src/executables/aot_tools.dart'; +import 'package:shorebird_cli/src/executables/xcodebuild.dart'; import 'package:shorebird_cli/src/logger.dart'; import 'package:shorebird_cli/src/os/operating_system_interface.dart'; import 'package:shorebird_cli/src/patch_diff_checker.dart'; @@ -170,6 +171,7 @@ flutter: late ShorebirdFlutterValidator flutterValidator; late ShorebirdProcess shorebirdProcess; late ShorebirdValidator shorebirdValidator; + late XcodeBuild xcodeBuild; late PatchIosCommand command; R runWithOverrides(R Function() body) { @@ -192,6 +194,7 @@ flutter: shorebirdEnvRef.overrideWith(() => shorebirdEnv), shorebirdFlutterRef.overrideWith(() => shorebirdFlutter), shorebirdValidatorRef.overrideWith(() => shorebirdValidator), + xcodeBuildRef.overrideWith(() => xcodeBuild), }, ); } @@ -256,6 +259,7 @@ flutter: } setUpAll(() { + registerFallbackValue(CreatePatchMetadata.forTest()); registerFallbackValue(Directory('')); registerFallbackValue(File('')); registerFallbackValue(FileSetDiff.empty()); @@ -322,6 +326,7 @@ flutter: flutterValidator = MockShorebirdFlutterValidator(); shorebirdProcess = MockShorebirdProcess(); shorebirdValidator = MockShorebirdValidator(); + xcodeBuild = MockXcodeBuild(); when(() => argResults['allow-asset-diffs']).thenReturn(false); when(() => argResults['allow-native-diffs']).thenReturn(false); @@ -399,11 +404,10 @@ flutter: () => codePushClientWrapper.publishPatch( appId: any(named: 'appId'), releaseId: any(named: 'releaseId'), - hasAssetChanges: any(named: 'hasAssetChanges'), - hasNativeChanges: any(named: 'hasNativeChanges'), platform: any(named: 'platform'), track: any(named: 'track'), patchArtifactBundles: any(named: 'patchArtifactBundles'), + metadata: any(named: 'metadata'), ), ).thenAnswer((_) async {}); when(() => doctor.iosCommandValidators).thenReturn([flutterValidator]); @@ -417,6 +421,7 @@ flutter: () => operatingSystemInterface.which('flutter'), ).thenReturn('/path/to/flutter'); when(() => platform.operatingSystem).thenReturn(Platform.macOS); + when(() => platform.operatingSystemVersion).thenReturn('1.2.3'); when(() => platform.environment).thenReturn({}); when(() => platform.script).thenReturn(shorebirdRoot.uri); when(() => shorebirdEnv.getShorebirdYaml()).thenReturn(shorebirdYaml); @@ -505,6 +510,7 @@ flutter: hasNativeChanges: false, ), ); + when(() => xcodeBuild.version()).thenAnswer((_) async => '15.0'); command = runWithOverrides( () => PatchIosCommand(archiveDiffer: archiveDiffer), @@ -1042,11 +1048,10 @@ Please re-run the release command for this version or create a new release.'''), () => codePushClientWrapper.publishPatch( appId: any(named: 'appId'), releaseId: any(named: 'releaseId'), - hasAssetChanges: any(named: 'hasAssetChanges'), - hasNativeChanges: any(named: 'hasNativeChanges'), platform: any(named: 'platform'), track: any(named: 'track'), patchArtifactBundles: any(named: 'patchArtifactBundles'), + metadata: any(named: 'metadata'), ), ); }); @@ -1119,11 +1124,10 @@ Please re-run the release command for this version or create a new release.'''), () => codePushClientWrapper.publishPatch( appId: any(named: 'appId'), releaseId: any(named: 'releaseId'), - hasAssetChanges: any(named: 'hasAssetChanges'), - hasNativeChanges: any(named: 'hasNativeChanges'), platform: any(named: 'platform'), track: any(named: 'track'), patchArtifactBundles: any(named: 'patchArtifactBundles'), + metadata: any(named: 'metadata'), ), ); }); @@ -1299,8 +1303,6 @@ Please re-run the release command for this version or create a new release.'''), () => codePushClientWrapper.publishPatch( appId: appId, releaseId: postLinkerRelease.id, - hasAssetChanges: false, - hasNativeChanges: false, platform: releasePlatform, track: track, patchArtifactBundles: any( @@ -1308,6 +1310,7 @@ Please re-run the release command for this version or create a new release.'''), that: isA>() .having((e) => e[Arch.arm64]!.path, 'patch path', diffPath), ), + metadata: any(named: 'metadata'), ), ).called(1); }); @@ -1323,8 +1326,7 @@ Please re-run the release command for this version or create a new release.'''), () => codePushClientWrapper.createPatch( appId: any(named: 'appId'), releaseId: any(named: 'releaseId'), - hasAssetChanges: any(named: 'hasAssetChanges'), - hasNativeChanges: any(named: 'hasNativeChanges'), + metadata: any(named: 'metadata'), ), ); verify(() => logger.info('No issues detected.')).called(1); @@ -1401,11 +1403,28 @@ Please re-run the release command for this version or create a new release.'''), () => codePushClientWrapper.publishPatch( appId: appId, releaseId: preLinkerRelease.id, - hasAssetChanges: true, - hasNativeChanges: true, platform: releasePlatform, track: track, patchArtifactBundles: any(named: 'patchArtifactBundles'), + metadata: any( + named: 'metadata', + that: isA() + .having( + (m) => m.releasePlatform, + 'releasePlatform', + releasePlatform, + ) + .having( + (m) => m.hasAssetChanges, + 'hasAssetChanges', + true, + ) + .having( + (m) => m.hasNativeChanges, + 'hasNativeChanges', + true, + ), + ), ), ).called(1); }); @@ -1429,11 +1448,10 @@ Please re-run the release command for this version or create a new release.'''), () => codePushClientWrapper.publishPatch( appId: appId, releaseId: preLinkerRelease.id, - hasAssetChanges: false, - hasNativeChanges: false, platform: releasePlatform, track: track, patchArtifactBundles: any(named: 'patchArtifactBundles'), + metadata: any(named: 'metadata'), ), ).called(1); @@ -1475,11 +1493,10 @@ Please re-run the release command for this version or create a new release.'''), () => codePushClientWrapper.publishPatch( appId: appId, releaseId: preLinkerRelease.id, - hasAssetChanges: false, - hasNativeChanges: false, platform: releasePlatform, track: DeploymentTrack.staging, patchArtifactBundles: any(named: 'patchArtifactBundles'), + metadata: any(named: 'metadata'), ), ).called(1); expect(exitCode, ExitCode.success.code); @@ -1567,11 +1584,10 @@ flavors: () => codePushClientWrapper.publishPatch( appId: appId, releaseId: preLinkerRelease.id, - hasAssetChanges: false, - hasNativeChanges: false, platform: releasePlatform, track: track, patchArtifactBundles: any(named: 'patchArtifactBundles'), + metadata: any(named: 'metadata'), ), ).called(1); }); diff --git a/packages/shorebird_cli/test/src/commands/patch/patch_ios_framework_command_test.dart b/packages/shorebird_cli/test/src/commands/patch/patch_ios_framework_command_test.dart index 47f16a175..0fef5b936 100644 --- a/packages/shorebird_cli/test/src/commands/patch/patch_ios_framework_command_test.dart +++ b/packages/shorebird_cli/test/src/commands/patch/patch_ios_framework_command_test.dart @@ -15,7 +15,7 @@ import 'package:shorebird_cli/src/config/config.dart'; import 'package:shorebird_cli/src/deployment_track.dart'; import 'package:shorebird_cli/src/doctor.dart'; import 'package:shorebird_cli/src/engine_config.dart'; -import 'package:shorebird_cli/src/executables/aot_tools.dart'; +import 'package:shorebird_cli/src/executables/executables.dart'; import 'package:shorebird_cli/src/logger.dart'; import 'package:shorebird_cli/src/os/operating_system_interface.dart'; import 'package:shorebird_cli/src/patch_diff_checker.dart'; @@ -121,6 +121,7 @@ flutter: late ShorebirdFlutterValidator flutterValidator; late ShorebirdProcess shorebirdProcess; late ShorebirdValidator shorebirdValidator; + late XcodeBuild xcodeBuild; late PatchIosFrameworkCommand command; R runWithOverrides(R Function() body) { @@ -142,6 +143,7 @@ flutter: shorebirdEnvRef.overrideWith(() => shorebirdEnv), shorebirdFlutterRef.overrideWith(() => shorebirdFlutter), shorebirdValidatorRef.overrideWith(() => shorebirdValidator), + xcodeBuildRef.overrideWith(() => xcodeBuild), }, ); } @@ -191,6 +193,7 @@ flutter: } setUpAll(() { + registerFallbackValue(CreatePatchMetadata.forTest()); registerFallbackValue(Directory('')); registerFallbackValue(File('')); registerFallbackValue(FileSetDiff.empty()); @@ -210,6 +213,7 @@ flutter: shorebirdArtifacts = MockShorebirdArtifacts(); patchDiffChecker = MockPatchDiffChecker(); platform = MockPlatform(); + xcodeBuild = MockXcodeBuild(); shorebirdRoot = Directory.systemTemp.createTempSync(); projectRoot = Directory.systemTemp.createTempSync(); flutterDirectory = Directory( @@ -314,6 +318,7 @@ flutter: () => operatingSystemInterface.which('flutter'), ).thenReturn('/path/to/flutter'); when(() => platform.operatingSystem).thenReturn(Platform.macOS); + when(() => platform.operatingSystemVersion).thenReturn('14.3.1'); when(() => shorebirdEnv.getShorebirdYaml()).thenReturn(shorebirdYaml); when(() => shorebirdEnv.shorebirdRoot).thenReturn(shorebirdRoot); when( @@ -374,11 +379,10 @@ flutter: () => codePushClientWrapper.publishPatch( appId: any(named: 'appId'), releaseId: any(named: 'releaseId'), - hasAssetChanges: any(named: 'hasAssetChanges'), - hasNativeChanges: any(named: 'hasNativeChanges'), platform: any(named: 'platform'), track: any(named: 'track'), patchArtifactBundles: any(named: 'patchArtifactBundles'), + metadata: any(named: 'metadata'), ), ).thenAnswer((_) async {}); when( @@ -403,6 +407,7 @@ flutter: hasNativeChanges: false, ), ); + when(() => xcodeBuild.version()).thenAnswer((_) async => '15.0'); command = runWithOverrides( () => PatchIosFrameworkCommand(archiveDiffer: archiveDiffer), @@ -780,11 +785,10 @@ Please re-run the release command for this version or create a new release.'''), () => codePushClientWrapper.publishPatch( appId: any(named: 'appId'), releaseId: any(named: 'releaseId'), - hasAssetChanges: any(named: 'hasAssetChanges'), - hasNativeChanges: any(named: 'hasNativeChanges'), platform: any(named: 'platform'), track: any(named: 'track'), patchArtifactBundles: any(named: 'patchArtifactBundles'), + metadata: any(named: 'metadata'), ), ); }); @@ -820,11 +824,10 @@ Please re-run the release command for this version or create a new release.'''), () => codePushClientWrapper.publishPatch( appId: any(named: 'appId'), releaseId: any(named: 'releaseId'), - hasAssetChanges: any(named: 'hasAssetChanges'), - hasNativeChanges: any(named: 'hasNativeChanges'), platform: any(named: 'platform'), track: any(named: 'track'), patchArtifactBundles: any(named: 'patchArtifactBundles'), + metadata: any(named: 'metadata'), ), ); }); @@ -839,8 +842,7 @@ Please re-run the release command for this version or create a new release.'''), () => codePushClientWrapper.createPatch( appId: any(named: 'appId'), releaseId: any(named: 'releaseId'), - hasAssetChanges: any(named: 'hasAssetChanges'), - hasNativeChanges: any(named: 'hasNativeChanges'), + metadata: any(named: 'metadata'), ), ); verify(() => logger.info('No issues detected.')).called(1); @@ -914,11 +916,28 @@ Please re-run the release command for this version or create a new release.'''), () => codePushClientWrapper.publishPatch( appId: appId, releaseId: postLinkerRelease.id, - hasAssetChanges: true, - hasNativeChanges: true, platform: ReleasePlatform.ios, track: track, patchArtifactBundles: any(named: 'patchArtifactBundles'), + metadata: any( + named: 'metadata', + that: isA() + .having( + (m) => m.releasePlatform, + 'releasePlatform', + ReleasePlatform.ios, + ) + .having( + (m) => m.hasAssetChanges, + 'hasAssetChanges', + true, + ) + .having( + (m) => m.hasNativeChanges, + 'hasNativeChanges', + true, + ), + ), ), ).called(1); }); @@ -942,11 +961,10 @@ Please re-run the release command for this version or create a new release.'''), () => codePushClientWrapper.publishPatch( appId: appId, releaseId: preLinkerRelease.id, - hasAssetChanges: false, - hasNativeChanges: false, platform: ReleasePlatform.ios, track: track, patchArtifactBundles: any(named: 'patchArtifactBundles'), + metadata: any(named: 'metadata'), ), ).called(1); expect(exitCode, ExitCode.success.code); @@ -1146,8 +1164,6 @@ Please re-run the release command for this version or create a new release.'''), () => codePushClientWrapper.publishPatch( appId: appId, releaseId: preLinkerRelease.id, - hasAssetChanges: false, - hasNativeChanges: false, platform: ReleasePlatform.ios, track: track, patchArtifactBundles: any( @@ -1155,6 +1171,7 @@ Please re-run the release command for this version or create a new release.'''), that: isA>() .having((e) => e[Arch.arm64]!.path, 'patch path', diffPath), ), + metadata: any(named: 'metadata'), ), ).called(1); }); diff --git a/packages/shorebird_cli/test/src/commands/release/release_ios_command_test.dart b/packages/shorebird_cli/test/src/commands/release/release_ios_command_test.dart index d652f99ab..d8bb7a77f 100644 --- a/packages/shorebird_cli/test/src/commands/release/release_ios_command_test.dart +++ b/packages/shorebird_cli/test/src/commands/release/release_ios_command_test.dart @@ -12,6 +12,7 @@ import 'package:shorebird_cli/src/code_push_client_wrapper.dart'; import 'package:shorebird_cli/src/commands/commands.dart'; import 'package:shorebird_cli/src/config/config.dart'; import 'package:shorebird_cli/src/doctor.dart'; +import 'package:shorebird_cli/src/executables/xcodebuild.dart'; import 'package:shorebird_cli/src/logger.dart'; import 'package:shorebird_cli/src/os/operating_system_interface.dart'; import 'package:shorebird_cli/src/platform.dart'; @@ -123,6 +124,7 @@ flutter: late ShorebirdEnv shorebirdEnv; late ShorebirdFlutter shorebirdFlutter; late ShorebirdValidator shorebirdValidator; + late XcodeBuild xcodeBuild; late ReleaseIosCommand command; R runWithOverrides(R Function() body) { @@ -140,6 +142,7 @@ flutter: shorebirdEnvRef.overrideWith(() => shorebirdEnv), shorebirdFlutterRef.overrideWith(() => shorebirdFlutter), shorebirdValidatorRef.overrideWith(() => shorebirdValidator), + xcodeBuildRef.overrideWith(() => xcodeBuild), }, ); } @@ -205,6 +208,7 @@ flutter: shorebirdEnv = MockShorebirdEnv(); shorebirdFlutter = MockShorebirdFlutter(); shorebirdValidator = MockShorebirdValidator(); + xcodeBuild = MockXcodeBuild(); when(() => shorebirdEnv.getShorebirdYaml()).thenReturn(shorebirdYaml); when(() => shorebirdEnv.shorebirdRoot).thenReturn(shorebirdRoot); @@ -264,6 +268,7 @@ flutter: () => operatingSystemInterface.which('flutter'), ).thenReturn('/path/to/flutter'); when(() => platform.operatingSystem).thenReturn(Platform.macOS); + when(() => platform.operatingSystemVersion).thenReturn('1.2.3'); when( () => flutterBuildProcessResult.exitCode, ).thenReturn(ExitCode.success.code); @@ -308,6 +313,7 @@ flutter: releaseId: any(named: 'releaseId'), platform: any(named: 'platform'), status: any(named: 'status'), + metadata: any(named: 'metadata'), ), ).thenAnswer((_) async => {}); @@ -320,6 +326,7 @@ flutter: supportedOperatingSystems: any(named: 'supportedOperatingSystems'), ), ).thenAnswer((_) async {}); + when(() => xcodeBuild.version()).thenAnswer((_) async => '15.0'); command = runWithOverrides(ReleaseIosCommand.new) ..testArgResults = argResults; diff --git a/packages/shorebird_cli/test/src/commands/release/release_ios_framework_command_test.dart b/packages/shorebird_cli/test/src/commands/release/release_ios_framework_command_test.dart index ec737b059..a5b7c1fb2 100644 --- a/packages/shorebird_cli/test/src/commands/release/release_ios_framework_command_test.dart +++ b/packages/shorebird_cli/test/src/commands/release/release_ios_framework_command_test.dart @@ -11,6 +11,7 @@ import 'package:shorebird_cli/src/code_push_client_wrapper.dart'; import 'package:shorebird_cli/src/commands/release/release.dart'; import 'package:shorebird_cli/src/config/config.dart'; import 'package:shorebird_cli/src/doctor.dart'; +import 'package:shorebird_cli/src/executables/xcodebuild.dart'; import 'package:shorebird_cli/src/logger.dart'; import 'package:shorebird_cli/src/os/operating_system_interface.dart'; import 'package:shorebird_cli/src/platform.dart'; @@ -79,6 +80,7 @@ flutter: late ShorebirdEnv shorebirdEnv; late ShorebirdFlutter shorebirdFlutter; late ShorebirdValidator shorebirdValidator; + late XcodeBuild xcodeBuild; late ReleaseIosFrameworkCommand command; R runWithOverrides(R Function() body) { @@ -95,6 +97,7 @@ flutter: shorebirdEnvRef.overrideWith(() => shorebirdEnv), shorebirdFlutterRef.overrideWith(() => shorebirdFlutter), shorebirdValidatorRef.overrideWith(() => shorebirdValidator), + xcodeBuildRef.overrideWith(() => xcodeBuild), }, ); } @@ -148,6 +151,7 @@ flutter: shorebirdEnv = MockShorebirdEnv(); shorebirdFlutter = MockShorebirdFlutter(); shorebirdValidator = MockShorebirdValidator(); + xcodeBuild = MockXcodeBuild(); when(() => shorebirdEnv.getShorebirdYaml()).thenReturn(shorebirdYaml); when(() => shorebirdEnv.shorebirdRoot).thenReturn(shorebirdRoot); @@ -203,6 +207,7 @@ flutter: when(() => operatingSystemInterface.which('flutter')) .thenReturn('/path/to/flutter'); when(() => platform.operatingSystem).thenReturn(Platform.macOS); + when(() => platform.operatingSystemVersion).thenReturn('1.2.3'); when( () => codePushClientWrapper.getApp(appId: any(named: 'appId')), ).thenAnswer((_) async => appMetadata); @@ -249,6 +254,7 @@ flutter: supportedOperatingSystems: any(named: 'supportedOperatingSystems'), ), ).thenAnswer((_) async {}); + when(() => xcodeBuild.version()).thenAnswer((_) async => '15.0'); command = runWithOverrides(ReleaseIosFrameworkCommand.new) ..testArgResults = argResults; diff --git a/packages/shorebird_cli/test/src/executables/xcodebuild_test.dart b/packages/shorebird_cli/test/src/executables/xcodebuild_test.dart index 379f7d323..4b9a952c3 100644 --- a/packages/shorebird_cli/test/src/executables/xcodebuild_test.dart +++ b/packages/shorebird_cli/test/src/executables/xcodebuild_test.dart @@ -132,5 +132,9 @@ To add iOS, run "flutter create . --platforms ios"''', ).called(1); }); }); + + group('version', () { + test('TODO', () async {}); + }); }); } diff --git a/packages/shorebird_code_push_client/example/main.dart b/packages/shorebird_code_push_client/example/main.dart index 705dc83f3..58b1fe316 100644 --- a/packages/shorebird_code_push_client/example/main.dart +++ b/packages/shorebird_code_push_client/example/main.dart @@ -43,8 +43,19 @@ Future main() async { final patch = await client.createPatch( appId: app.id, releaseId: release.id, - hasAssetChanges: false, - hasNativeChanges: false, + metadata: const CreatePatchMetadata( + releasePlatform: ReleasePlatform.android, + usedIgnoreAssetChangesFlag: false, + hasAssetChanges: false, + usedIgnoreNativeChangesFlag: false, + hasNativeChanges: false, + environment: BuildEnvironmentMetadata( + operatingSystem: 'Windows', + operatingSystemVersion: '10', + shorebirdVersion: '1.2.3', + xcodeVersion: null, + ), + ), ); // Create a patch artifact. diff --git a/packages/shorebird_code_push_client/lib/src/code_push_client.dart b/packages/shorebird_code_push_client/lib/src/code_push_client.dart index e7fc4ded3..9da72de24 100644 --- a/packages/shorebird_code_push_client/lib/src/code_push_client.dart +++ b/packages/shorebird_code_push_client/lib/src/code_push_client.dart @@ -2,6 +2,7 @@ import 'dart:convert'; import 'dart:io'; import 'package:http/http.dart' as http; +import 'package:shorebird_code_push_client/shorebird_code_push_client.dart'; import 'package:shorebird_code_push_client/src/version.dart'; import 'package:shorebird_code_push_protocol/shorebird_code_push_protocol.dart'; @@ -245,16 +246,14 @@ class CodePushClient { Future createPatch({ required String appId, required int releaseId, - required bool hasAssetChanges, - required bool hasNativeChanges, + required CreatePatchMetadata metadata, }) async { final request = CreatePatchRequest( releaseId: releaseId, wasForced: false, - hasAssetChanges: hasAssetChanges, - hasNativeChanges: hasNativeChanges, - // TODO(bryanoltman): add metadata - metadata: null, + hasAssetChanges: metadata.hasAssetChanges, + hasNativeChanges: metadata.hasNativeChanges, + metadata: metadata, ); final response = await _httpClient.post( Uri.parse('$_v1/apps/$appId/patches'), @@ -299,6 +298,7 @@ class CodePushClient { required int releaseId, required ReleasePlatform platform, required ReleaseStatus status, + UpdateReleaseMetadata? metadata, }) async { final response = await _httpClient.patch( Uri.parse('$_v1/apps/$appId/releases/$releaseId'), @@ -306,8 +306,7 @@ class CodePushClient { UpdateReleaseRequest( status: status, platform: platform, - // TODO(bryanoltman): add metadata - metadata: null, + metadata: metadata, ).toJson(), ), ); diff --git a/packages/shorebird_code_push_client/test/src/code_push_client_test.dart b/packages/shorebird_code_push_client/test/src/code_push_client_test.dart index 50e2e2b5a..484aceb1b 100644 --- a/packages/shorebird_code_push_client/test/src/code_push_client_test.dart +++ b/packages/shorebird_code_push_client/test/src/code_push_client_test.dart @@ -824,8 +824,7 @@ void main() { .createPatch( appId: appId, releaseId: releaseId, - hasAssetChanges: false, - hasNativeChanges: true, + metadata: CreatePatchMetadata.forTest(), ) .ignore(); final request = verify(() => httpClient.send(captureAny())) @@ -848,8 +847,7 @@ void main() { codePushClient.createPatch( appId: appId, releaseId: releaseId, - hasAssetChanges: false, - hasNativeChanges: true, + metadata: CreatePatchMetadata.forTest(), ), throwsA( isA().having( @@ -873,8 +871,7 @@ void main() { codePushClient.createPatch( appId: appId, releaseId: releaseId, - hasAssetChanges: false, - hasNativeChanges: true, + metadata: CreatePatchMetadata.forTest(), ), throwsA( isA().having( @@ -904,8 +901,7 @@ void main() { codePushClient.createPatch( appId: appId, releaseId: releaseId, - hasAssetChanges: false, - hasNativeChanges: true, + metadata: CreatePatchMetadata.forTest(), ), completion( equals( From 887ee2fcae119542bc980d66c7496d43e7044407 Mon Sep 17 00:00:00 2001 From: Bryan Oltman Date: Wed, 27 Mar 2024 11:32:14 -0400 Subject: [PATCH 05/13] coverage --- .../models/create_patch_metadata_test.dart | 26 +++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 packages/shorebird_code_push_protocol/test/src/models/create_patch_metadata_test.dart diff --git a/packages/shorebird_code_push_protocol/test/src/models/create_patch_metadata_test.dart b/packages/shorebird_code_push_protocol/test/src/models/create_patch_metadata_test.dart new file mode 100644 index 000000000..39344e0c8 --- /dev/null +++ b/packages/shorebird_code_push_protocol/test/src/models/create_patch_metadata_test.dart @@ -0,0 +1,26 @@ +import 'package:shorebird_code_push_protocol/shorebird_code_push_protocol.dart'; +import 'package:test/test.dart'; + +void main() { + group(CreatePatchMetadata, () { + test('can be (de)serialized', () { + const metadata = CreatePatchMetadata( + releasePlatform: ReleasePlatform.android, + usedIgnoreAssetChangesFlag: false, + hasAssetChanges: false, + usedIgnoreNativeChangesFlag: false, + hasNativeChanges: false, + environment: BuildEnvironmentMetadata( + operatingSystem: 'macos', + operatingSystemVersion: '1.2.3', + shorebirdVersion: '4.5.6', + xcodeVersion: '15.0', + ), + ); + expect( + CreatePatchMetadata.fromJson(metadata.toJson()).toJson(), + equals(metadata.toJson()), + ); + }); + }); +} From 13acd2fb55ad358287c45d60102b493ae7ea7574 Mon Sep 17 00:00:00 2001 From: Bryan Oltman Date: Wed, 27 Mar 2024 11:36:56 -0400 Subject: [PATCH 06/13] coverage --- .../build_environment_metadata_test.dart | 54 ++++++++++++++++ .../models/create_patch_metadata_test.dart | 62 +++++++++++++++++++ 2 files changed, 116 insertions(+) create mode 100644 packages/shorebird_code_push_protocol/test/src/models/build_environment_metadata_test.dart diff --git a/packages/shorebird_code_push_protocol/test/src/models/build_environment_metadata_test.dart b/packages/shorebird_code_push_protocol/test/src/models/build_environment_metadata_test.dart new file mode 100644 index 000000000..8133c395c --- /dev/null +++ b/packages/shorebird_code_push_protocol/test/src/models/build_environment_metadata_test.dart @@ -0,0 +1,54 @@ +import 'package:shorebird_code_push_protocol/shorebird_code_push_protocol.dart'; +import 'package:shorebird_code_push_protocol/src/models/build_environment_metadata.dart'; +import 'package:test/test.dart'; + +void main() { + group(BuildEnvironmentMetadata, () { + test('can be (de)serialized', () { + const metadata = BuildEnvironmentMetadata( + operatingSystem: 'macos', + operatingSystemVersion: '1.2.3', + shorebirdVersion: '4.5.6', + xcodeVersion: '15.0', + ); + expect( + BuildEnvironmentMetadata.fromJson(metadata.toJson()).toJson(), + equals(metadata.toJson()), + ); + }); + + group('equatable', () { + test('two metadatas with the same properties are equal', () { + const metadata = BuildEnvironmentMetadata( + operatingSystem: 'macos', + operatingSystemVersion: '1.2.3', + shorebirdVersion: '4.5.6', + xcodeVersion: '15.0', + ); + const otherMetadata = BuildEnvironmentMetadata( + operatingSystem: 'macos', + operatingSystemVersion: '1.2.3', + shorebirdVersion: '4.5.6', + xcodeVersion: '15.0', + ); + expect(metadata, equals(otherMetadata)); + }); + + test('two metadatas with different properties are not equal', () { + const metadata = BuildEnvironmentMetadata( + operatingSystem: 'macos', + operatingSystemVersion: '1.2.3', + shorebirdVersion: '4.5.6', + xcodeVersion: '15.0', + ); + const otherMetadata = BuildEnvironmentMetadata( + operatingSystem: 'macos', + operatingSystemVersion: '1.2.3', + shorebirdVersion: '4.5.6', + xcodeVersion: '15.1', + ); + expect(metadata, isNot(equals(otherMetadata))); + }); + }); + }); +} diff --git a/packages/shorebird_code_push_protocol/test/src/models/create_patch_metadata_test.dart b/packages/shorebird_code_push_protocol/test/src/models/create_patch_metadata_test.dart index 39344e0c8..2732c9b48 100644 --- a/packages/shorebird_code_push_protocol/test/src/models/create_patch_metadata_test.dart +++ b/packages/shorebird_code_push_protocol/test/src/models/create_patch_metadata_test.dart @@ -22,5 +22,67 @@ void main() { equals(metadata.toJson()), ); }); + + group('equatable', () { + test('two metadatas with the same properties are equal', () { + const metadata = CreatePatchMetadata( + releasePlatform: ReleasePlatform.android, + usedIgnoreAssetChangesFlag: false, + hasAssetChanges: false, + usedIgnoreNativeChangesFlag: false, + hasNativeChanges: false, + environment: BuildEnvironmentMetadata( + operatingSystem: 'macos', + operatingSystemVersion: '1.2.3', + shorebirdVersion: '4.5.6', + xcodeVersion: '15.0', + ), + ); + const otherMetadata = CreatePatchMetadata( + releasePlatform: ReleasePlatform.android, + usedIgnoreAssetChangesFlag: false, + hasAssetChanges: false, + usedIgnoreNativeChangesFlag: false, + hasNativeChanges: false, + environment: BuildEnvironmentMetadata( + operatingSystem: 'macos', + operatingSystemVersion: '1.2.3', + shorebirdVersion: '4.5.6', + xcodeVersion: '15.0', + ), + ); + expect(metadata, equals(otherMetadata)); + }); + + test('two metadatas with different properties are not equal', () { + const metadata = CreatePatchMetadata( + releasePlatform: ReleasePlatform.android, + usedIgnoreAssetChangesFlag: false, + hasAssetChanges: false, + usedIgnoreNativeChangesFlag: false, + hasNativeChanges: false, + environment: BuildEnvironmentMetadata( + operatingSystem: 'macos', + operatingSystemVersion: '1.2.3', + shorebirdVersion: '4.5.6', + xcodeVersion: '15.0', + ), + ); + const otherMetadata = CreatePatchMetadata( + releasePlatform: ReleasePlatform.ios, + usedIgnoreAssetChangesFlag: false, + hasAssetChanges: false, + usedIgnoreNativeChangesFlag: false, + hasNativeChanges: false, + environment: BuildEnvironmentMetadata( + operatingSystem: 'macos', + operatingSystemVersion: '1.2.3', + shorebirdVersion: '4.5.6', + xcodeVersion: '15.0', + ), + ); + expect(metadata, isNot(equals(otherMetadata))); + }); + }); }); } From 0b18e409a4fbcf6e0cdfeea698824b449441cb0b Mon Sep 17 00:00:00 2001 From: Bryan Oltman Date: Wed, 27 Mar 2024 12:01:41 -0400 Subject: [PATCH 07/13] equatable + coverage --- .../src/models/update_release_metadata.dart | 11 ++- .../models/update_release_metadata_test.dart | 78 +++++++++++++++++++ 2 files changed, 88 insertions(+), 1 deletion(-) create mode 100644 packages/shorebird_code_push_protocol/test/src/models/update_release_metadata_test.dart diff --git a/packages/shorebird_code_push_protocol/lib/src/models/update_release_metadata.dart b/packages/shorebird_code_push_protocol/lib/src/models/update_release_metadata.dart index 6ef384d46..b4e6fb7ed 100644 --- a/packages/shorebird_code_push_protocol/lib/src/models/update_release_metadata.dart +++ b/packages/shorebird_code_push_protocol/lib/src/models/update_release_metadata.dart @@ -1,3 +1,4 @@ +import 'package:equatable/equatable.dart'; import 'package:json_annotation/json_annotation.dart'; import 'package:shorebird_code_push_protocol/src/models/models.dart'; @@ -7,7 +8,7 @@ part 'update_release_metadata.g.dart'; /// Information about the creation of patch, used for debugging purposes. /// {@endtemplate} @JsonSerializable() -class UpdateReleaseMetadata { +class UpdateReleaseMetadata extends Equatable { /// {@macro release_metadata} const UpdateReleaseMetadata({ required this.releasePlatform, @@ -35,4 +36,12 @@ class UpdateReleaseMetadata { /// Properties about the environment in which the update to the release was /// performed. final BuildEnvironmentMetadata environment; + + @override + List get props => [ + releasePlatform, + flutterVersionOverride, + generatedApks, + environment, + ]; } diff --git a/packages/shorebird_code_push_protocol/test/src/models/update_release_metadata_test.dart b/packages/shorebird_code_push_protocol/test/src/models/update_release_metadata_test.dart new file mode 100644 index 000000000..53fa15b3c --- /dev/null +++ b/packages/shorebird_code_push_protocol/test/src/models/update_release_metadata_test.dart @@ -0,0 +1,78 @@ +import 'package:shorebird_code_push_protocol/shorebird_code_push_protocol.dart'; +import 'package:test/test.dart'; + +void main() { + group(UpdateReleaseMetadata, () { + test('can be (de)serialized', () { + const metadata = UpdateReleaseMetadata( + releasePlatform: ReleasePlatform.android, + flutterVersionOverride: '1.2.3', + generatedApks: false, + environment: BuildEnvironmentMetadata( + operatingSystem: 'macos', + operatingSystemVersion: '1.2.3', + shorebirdVersion: '4.5.6', + xcodeVersion: '15.0', + ), + ); + expect( + UpdateReleaseMetadata.fromJson(metadata.toJson()).toJson(), + equals(metadata.toJson()), + ); + }); + + group('equatable', () { + test('two metadatas with the same properties are equal', () { + const metadata = UpdateReleaseMetadata( + releasePlatform: ReleasePlatform.android, + flutterVersionOverride: '1.2.3', + generatedApks: false, + environment: BuildEnvironmentMetadata( + operatingSystem: 'macos', + operatingSystemVersion: '1.2.3', + shorebirdVersion: '4.5.6', + xcodeVersion: '15.0', + ), + ); + const otherMetadata = UpdateReleaseMetadata( + releasePlatform: ReleasePlatform.android, + flutterVersionOverride: '1.2.3', + generatedApks: false, + environment: BuildEnvironmentMetadata( + operatingSystem: 'macos', + operatingSystemVersion: '1.2.3', + shorebirdVersion: '4.5.6', + xcodeVersion: '15.0', + ), + ); + expect(metadata, equals(otherMetadata)); + }); + + test('two metadatas with different properties are not equal', () { + const metadata = UpdateReleaseMetadata( + releasePlatform: ReleasePlatform.android, + flutterVersionOverride: '1.2.3', + generatedApks: false, + environment: BuildEnvironmentMetadata( + operatingSystem: 'macos', + operatingSystemVersion: '1.2.3', + shorebirdVersion: '4.5.6', + xcodeVersion: '15.0', + ), + ); + const otherMetadata = UpdateReleaseMetadata( + releasePlatform: ReleasePlatform.android, + flutterVersionOverride: '1.2.4', + generatedApks: false, + environment: BuildEnvironmentMetadata( + operatingSystem: 'macos', + operatingSystemVersion: '1.2.3', + shorebirdVersion: '4.5.6', + xcodeVersion: '15.0', + ), + ); + expect(metadata, isNot(equals(otherMetadata))); + }); + }); + }); +} From 4961487ce983490f0e5d71c5a5c9ee50f61a1250 Mon Sep 17 00:00:00 2001 From: Bryan Oltman Date: Wed, 27 Mar 2024 13:12:27 -0400 Subject: [PATCH 08/13] add forTest constructors --- .../models/build_environment_metadata.dart | 16 ++++++++++++++ .../lib/src/models/create_patch_metadata.dart | 21 +++++++++++++++++++ .../src/models/update_release_metadata.dart | 17 +++++++++++++++ 3 files changed, 54 insertions(+) diff --git a/packages/shorebird_code_push_protocol/lib/src/models/build_environment_metadata.dart b/packages/shorebird_code_push_protocol/lib/src/models/build_environment_metadata.dart index 49f37a0b6..93ccaa412 100644 --- a/packages/shorebird_code_push_protocol/lib/src/models/build_environment_metadata.dart +++ b/packages/shorebird_code_push_protocol/lib/src/models/build_environment_metadata.dart @@ -16,6 +16,22 @@ class BuildEnvironmentMetadata extends Equatable { required this.xcodeVersion, }); + /// coverage:ignore-start + /// Creates a [BuildEnvironmentMetadata] with overridable default values for + /// testing purposes. + factory BuildEnvironmentMetadata.forTest({ + String shorebirdVersion = '4.5.6', + String operatingSystem = 'macos', + String operatingSystemVersion = '1.2.3', + String? xcodeVersion = '15.0', + }) => + BuildEnvironmentMetadata( + shorebirdVersion: shorebirdVersion, + operatingSystem: operatingSystem, + operatingSystemVersion: operatingSystemVersion, + xcodeVersion: xcodeVersion, + ); + /// Converts a Map to a [BuildEnvironmentMetadata] factory BuildEnvironmentMetadata.fromJson(Map json) => _$BuildEnvironmentMetadataFromJson(json); diff --git a/packages/shorebird_code_push_protocol/lib/src/models/create_patch_metadata.dart b/packages/shorebird_code_push_protocol/lib/src/models/create_patch_metadata.dart index 97065d0ec..00e0095ec 100644 --- a/packages/shorebird_code_push_protocol/lib/src/models/create_patch_metadata.dart +++ b/packages/shorebird_code_push_protocol/lib/src/models/create_patch_metadata.dart @@ -19,6 +19,27 @@ class CreatePatchMetadata extends Equatable { required this.environment, }); + // coverage:ignore-start + /// Creates a [CreatePatchMetadata] with overridable default values for + /// testing purposes. + factory CreatePatchMetadata.forTest({ + ReleasePlatform releasePlatform = ReleasePlatform.android, + bool usedIgnoreAssetChangesFlag = false, + bool hasAssetChanges = false, + bool usedIgnoreNativeChangesFlag = false, + bool hasNativeChanges = false, + BuildEnvironmentMetadata? environment, + }) => + CreatePatchMetadata( + releasePlatform: releasePlatform, + usedIgnoreAssetChangesFlag: usedIgnoreAssetChangesFlag, + hasAssetChanges: hasAssetChanges, + usedIgnoreNativeChangesFlag: usedIgnoreNativeChangesFlag, + hasNativeChanges: hasNativeChanges, + environment: environment ?? BuildEnvironmentMetadata.forTest(), + ); + // coverage:ignore-end + /// Converts a Map to a [CreatePatchMetadata] factory CreatePatchMetadata.fromJson(Map json) => _$CreatePatchMetadataFromJson(json); diff --git a/packages/shorebird_code_push_protocol/lib/src/models/update_release_metadata.dart b/packages/shorebird_code_push_protocol/lib/src/models/update_release_metadata.dart index b4e6fb7ed..0ebc6edb1 100644 --- a/packages/shorebird_code_push_protocol/lib/src/models/update_release_metadata.dart +++ b/packages/shorebird_code_push_protocol/lib/src/models/update_release_metadata.dart @@ -17,6 +17,23 @@ class UpdateReleaseMetadata extends Equatable { required this.environment, }); + // coverage:ignore-start + /// Creates a [UpdateReleaseMetadata] with overridable default values for + /// testing purposes. + factory UpdateReleaseMetadata.forTest({ + ReleasePlatform releasePlatform = ReleasePlatform.android, + String? flutterVersionOverride = '1.2.3', + bool? generatedApks = false, + BuildEnvironmentMetadata? environment, + }) => + UpdateReleaseMetadata( + releasePlatform: releasePlatform, + flutterVersionOverride: flutterVersionOverride, + generatedApks: generatedApks, + environment: environment ?? BuildEnvironmentMetadata.forTest(), + ); + // coverage:ignore-end + /// Converts a Map to a [UpdateReleaseMetadata]. factory UpdateReleaseMetadata.fromJson(Map json) => _$UpdateReleaseMetadataFromJson(json); From c96b6b3547f6cf527b6dade6f03d65a6b808db05 Mon Sep 17 00:00:00 2001 From: Bryan Oltman Date: Wed, 27 Mar 2024 14:31:21 -0400 Subject: [PATCH 09/13] Improve tests --- .../release/release_android_command.dart | 2 +- .../patch/patch_aar_command_test.dart | 22 +++++++-- .../patch/patch_android_command_test.dart | 22 +++++++-- .../patch/patch_ios_command_test.dart | 39 +++++++++++++-- .../patch_ios_framework_command_test.dart | 25 ++++++++-- .../release/release_aar_command_test.dart | 19 +++++++ .../release/release_android_command_test.dart | 49 +++++++++++++++++++ .../release/release_ios_command_test.dart | 42 ++++++++++++++-- .../release_ios_framework_command_test.dart | 43 ++++++++++++++-- 9 files changed, 241 insertions(+), 22 deletions(-) diff --git a/packages/shorebird_cli/lib/src/commands/release/release_android_command.dart b/packages/shorebird_cli/lib/src/commands/release/release_android_command.dart index 7fd6b1045..daf8d57bc 100644 --- a/packages/shorebird_cli/lib/src/commands/release/release_android_command.dart +++ b/packages/shorebird_cli/lib/src/commands/release/release_android_command.dart @@ -299,7 +299,7 @@ ${summary.join('\n')} metadata: UpdateReleaseMetadata( releasePlatform: releasePlatform, flutterVersionOverride: flutterVersion, - generatedApks: false, + generatedApks: generateApk, environment: BuildEnvironmentMetadata( operatingSystem: platform.operatingSystem, operatingSystemVersion: platform.operatingSystemVersion, diff --git a/packages/shorebird_cli/test/src/commands/patch/patch_aar_command_test.dart b/packages/shorebird_cli/test/src/commands/patch/patch_aar_command_test.dart index 545198e6c..267398d9c 100644 --- a/packages/shorebird_cli/test/src/commands/patch/patch_aar_command_test.dart +++ b/packages/shorebird_cli/test/src/commands/patch/patch_aar_command_test.dart @@ -26,6 +26,7 @@ import 'package:shorebird_cli/src/shorebird_env.dart'; import 'package:shorebird_cli/src/shorebird_flutter.dart'; import 'package:shorebird_cli/src/shorebird_process.dart'; import 'package:shorebird_cli/src/shorebird_validator.dart'; +import 'package:shorebird_cli/src/version.dart'; import 'package:shorebird_code_push_client/shorebird_code_push_client.dart'; import 'package:test/test.dart'; @@ -41,6 +42,8 @@ void main() { const versionName = '1.2.3'; const versionCode = '1'; const version = '$versionName+$versionCode'; + const operatingSystem = 'macOS'; + const operatingSystemVersion = '11.0.0'; const arch = 'aarch64'; const releasePlatform = ReleasePlatform.android; const track = DeploymentTrack.production; @@ -196,8 +199,9 @@ void main() { when(() => operatingSystemInterface.which('flutter')) .thenReturn('/path/to/flutter'); when(() => platform.environment).thenReturn({}); - when(() => platform.operatingSystem).thenReturn('macos'); - when(() => platform.operatingSystemVersion).thenReturn('1.2.3'); + when(() => platform.operatingSystem).thenReturn(operatingSystem); + when(() => platform.operatingSystemVersion) + .thenReturn(operatingSystemVersion); when(() => shorebirdEnv.shorebirdRoot).thenReturn(shorebirdRoot); when( () => shorebirdEnv.copyWith( @@ -890,7 +894,19 @@ Please re-run the release command for this version or create a new release.'''), platform: releasePlatform, track: track, patchArtifactBundles: any(named: 'patchArtifactBundles'), - metadata: any(named: 'metadata'), + metadata: const CreatePatchMetadata( + releasePlatform: releasePlatform, + usedIgnoreAssetChangesFlag: false, + hasAssetChanges: false, + usedIgnoreNativeChangesFlag: false, + hasNativeChanges: false, + environment: BuildEnvironmentMetadata( + shorebirdVersion: packageVersion, + operatingSystem: operatingSystem, + operatingSystemVersion: operatingSystemVersion, + xcodeVersion: null, + ), + ), ), ).called(1); }); diff --git a/packages/shorebird_cli/test/src/commands/patch/patch_android_command_test.dart b/packages/shorebird_cli/test/src/commands/patch/patch_android_command_test.dart index da776839f..f1d353ef7 100644 --- a/packages/shorebird_cli/test/src/commands/patch/patch_android_command_test.dart +++ b/packages/shorebird_cli/test/src/commands/patch/patch_android_command_test.dart @@ -29,6 +29,7 @@ import 'package:shorebird_cli/src/shorebird_flutter.dart'; import 'package:shorebird_cli/src/shorebird_process.dart'; import 'package:shorebird_cli/src/shorebird_validator.dart'; import 'package:shorebird_cli/src/validators/validators.dart'; +import 'package:shorebird_cli/src/version.dart'; import 'package:shorebird_code_push_client/shorebird_code_push_client.dart'; import 'package:test/test.dart'; @@ -43,6 +44,8 @@ void main() { const versionName = '1.2.3'; const versionCode = '1'; const version = '$versionName+$versionCode'; + const operatingSystem = 'macOS'; + const operatingSystemVersion = '11.0.0'; const arch = 'aarch64'; const releasePlatform = ReleasePlatform.android; const track = DeploymentTrack.production; @@ -383,8 +386,9 @@ flutter: hasNativeChanges: false, ), ); - when(() => platform.operatingSystem).thenReturn('linux'); - when(() => platform.operatingSystemVersion).thenReturn('1.2.3'); + when(() => platform.operatingSystem).thenReturn(operatingSystem); + when(() => platform.operatingSystemVersion) + .thenReturn(operatingSystemVersion); when(() => shorebirdEnv.isRunningOnCI).thenReturn(false); }); @@ -973,7 +977,19 @@ Please re-run the release command for this version or create a new release.'''), platform: releasePlatform, track: track, patchArtifactBundles: any(named: 'patchArtifactBundles'), - metadata: any(named: 'metadata'), + metadata: const CreatePatchMetadata( + releasePlatform: releasePlatform, + usedIgnoreAssetChangesFlag: false, + hasAssetChanges: false, + usedIgnoreNativeChangesFlag: false, + hasNativeChanges: false, + environment: BuildEnvironmentMetadata( + shorebirdVersion: packageVersion, + operatingSystem: operatingSystem, + operatingSystemVersion: operatingSystemVersion, + xcodeVersion: null, + ), + ), ), ).called(1); expect(exitCode, ExitCode.success.code); diff --git a/packages/shorebird_cli/test/src/commands/patch/patch_ios_command_test.dart b/packages/shorebird_cli/test/src/commands/patch/patch_ios_command_test.dart index 3f5df9999..b0902fb02 100644 --- a/packages/shorebird_cli/test/src/commands/patch/patch_ios_command_test.dart +++ b/packages/shorebird_cli/test/src/commands/patch/patch_ios_command_test.dart @@ -32,6 +32,7 @@ import 'package:shorebird_cli/src/shorebird_process.dart'; import 'package:shorebird_cli/src/shorebird_validator.dart'; import 'package:shorebird_cli/src/third_party/flutter_tools/lib/flutter_tools.dart'; import 'package:shorebird_cli/src/validators/validators.dart'; +import 'package:shorebird_cli/src/version.dart'; import 'package:shorebird_code_push_client/shorebird_code_push_client.dart'; import 'package:test/test.dart'; @@ -47,6 +48,9 @@ void main() { const versionCode = '1'; const version = '$versionName+$versionCode'; const arch = 'aarch64'; + const operatingSystem = 'macOS'; + const operatingSystemVersion = '11.0.0'; + const xcodeVersion = '12.0'; const track = DeploymentTrack.production; const appDisplayName = 'Test App'; const releasePlatform = ReleasePlatform.ios; @@ -420,8 +424,9 @@ flutter: when( () => operatingSystemInterface.which('flutter'), ).thenReturn('/path/to/flutter'); - when(() => platform.operatingSystem).thenReturn(Platform.macOS); - when(() => platform.operatingSystemVersion).thenReturn('1.2.3'); + when(() => platform.operatingSystem).thenReturn(operatingSystem); + when(() => platform.operatingSystemVersion) + .thenReturn(operatingSystemVersion); when(() => platform.environment).thenReturn({}); when(() => platform.script).thenReturn(shorebirdRoot.uri); when(() => shorebirdEnv.getShorebirdYaml()).thenReturn(shorebirdYaml); @@ -510,7 +515,7 @@ flutter: hasNativeChanges: false, ), ); - when(() => xcodeBuild.version()).thenAnswer((_) async => '15.0'); + when(() => xcodeBuild.version()).thenAnswer((_) async => xcodeVersion); command = runWithOverrides( () => PatchIosCommand(archiveDiffer: archiveDiffer), @@ -1310,7 +1315,19 @@ Please re-run the release command for this version or create a new release.'''), that: isA>() .having((e) => e[Arch.arm64]!.path, 'patch path', diffPath), ), - metadata: any(named: 'metadata'), + metadata: const CreatePatchMetadata( + releasePlatform: releasePlatform, + usedIgnoreAssetChangesFlag: false, + hasAssetChanges: false, + usedIgnoreNativeChangesFlag: false, + hasNativeChanges: false, + environment: BuildEnvironmentMetadata( + shorebirdVersion: packageVersion, + operatingSystem: operatingSystem, + operatingSystemVersion: operatingSystemVersion, + xcodeVersion: xcodeVersion, + ), + ), ), ).called(1); }); @@ -1587,7 +1604,19 @@ flavors: platform: releasePlatform, track: track, patchArtifactBundles: any(named: 'patchArtifactBundles'), - metadata: any(named: 'metadata'), + metadata: const CreatePatchMetadata( + releasePlatform: releasePlatform, + usedIgnoreAssetChangesFlag: false, + hasAssetChanges: false, + usedIgnoreNativeChangesFlag: false, + hasNativeChanges: false, + environment: BuildEnvironmentMetadata( + shorebirdVersion: packageVersion, + operatingSystem: operatingSystem, + operatingSystemVersion: operatingSystemVersion, + xcodeVersion: xcodeVersion, + ), + ), ), ).called(1); }); diff --git a/packages/shorebird_cli/test/src/commands/patch/patch_ios_framework_command_test.dart b/packages/shorebird_cli/test/src/commands/patch/patch_ios_framework_command_test.dart index 0fef5b936..1e2f47f57 100644 --- a/packages/shorebird_cli/test/src/commands/patch/patch_ios_framework_command_test.dart +++ b/packages/shorebird_cli/test/src/commands/patch/patch_ios_framework_command_test.dart @@ -27,6 +27,7 @@ import 'package:shorebird_cli/src/shorebird_flutter.dart'; import 'package:shorebird_cli/src/shorebird_process.dart'; import 'package:shorebird_cli/src/shorebird_validator.dart'; import 'package:shorebird_cli/src/validators/validators.dart'; +import 'package:shorebird_cli/src/version.dart'; import 'package:shorebird_code_push_client/shorebird_code_push_client.dart'; import 'package:test/test.dart'; @@ -43,6 +44,9 @@ void main() { const version = '$versionName+$versionCode'; const linkFileName = 'out.vmcode'; const elfAotSnapshotFileName = 'out.aot'; + const operatingSystem = 'macOS'; + const operatingSystemVersion = '11.0.0'; + const xcodeVersion = '12.0'; const postLinkerFlutterRevision = 'deadbeefdeadbeefdeadbeefdeadbeefdeadbeef'; const preLinkerFlutterRevision = '83305b5088e6fe327fb3334a73ff190828d85713'; @@ -317,8 +321,9 @@ flutter: when( () => operatingSystemInterface.which('flutter'), ).thenReturn('/path/to/flutter'); - when(() => platform.operatingSystem).thenReturn(Platform.macOS); - when(() => platform.operatingSystemVersion).thenReturn('14.3.1'); + when(() => platform.operatingSystem).thenReturn(operatingSystem); + when(() => platform.operatingSystemVersion) + .thenReturn(operatingSystemVersion); when(() => shorebirdEnv.getShorebirdYaml()).thenReturn(shorebirdYaml); when(() => shorebirdEnv.shorebirdRoot).thenReturn(shorebirdRoot); when( @@ -407,7 +412,7 @@ flutter: hasNativeChanges: false, ), ); - when(() => xcodeBuild.version()).thenAnswer((_) async => '15.0'); + when(() => xcodeBuild.version()).thenAnswer((_) async => xcodeVersion); command = runWithOverrides( () => PatchIosFrameworkCommand(archiveDiffer: archiveDiffer), @@ -964,7 +969,19 @@ Please re-run the release command for this version or create a new release.'''), platform: ReleasePlatform.ios, track: track, patchArtifactBundles: any(named: 'patchArtifactBundles'), - metadata: any(named: 'metadata'), + metadata: const CreatePatchMetadata( + releasePlatform: ReleasePlatform.ios, + usedIgnoreAssetChangesFlag: false, + hasAssetChanges: false, + usedIgnoreNativeChangesFlag: false, + hasNativeChanges: false, + environment: BuildEnvironmentMetadata( + shorebirdVersion: packageVersion, + operatingSystem: operatingSystem, + operatingSystemVersion: operatingSystemVersion, + xcodeVersion: xcodeVersion, + ), + ), ), ).called(1); expect(exitCode, ExitCode.success.code); diff --git a/packages/shorebird_cli/test/src/commands/release/release_aar_command_test.dart b/packages/shorebird_cli/test/src/commands/release/release_aar_command_test.dart index 914e4733d..7b6108506 100644 --- a/packages/shorebird_cli/test/src/commands/release/release_aar_command_test.dart +++ b/packages/shorebird_cli/test/src/commands/release/release_aar_command_test.dart @@ -21,6 +21,7 @@ import 'package:shorebird_cli/src/shorebird_env.dart'; import 'package:shorebird_cli/src/shorebird_flutter.dart'; import 'package:shorebird_cli/src/shorebird_process.dart'; import 'package:shorebird_cli/src/shorebird_validator.dart'; +import 'package:shorebird_cli/src/version.dart'; import 'package:shorebird_code_push_client/shorebird_code_push_client.dart'; import 'package:test/test.dart'; @@ -44,6 +45,8 @@ void main() { const versionName = '1.2.3'; const versionCode = '1'; const version = '$versionName+$versionCode'; + const operatingSystem = 'macOS'; + const operatingSystemVersion = '11.0.0'; final release = Release( id: 0, appId: appId, @@ -159,6 +162,9 @@ void main() { when( () => operatingSystemInterface.which('flutter'), ).thenReturn('/path/to/flutter'); + when(() => platform.operatingSystem).thenReturn(operatingSystem); + when(() => platform.operatingSystemVersion) + .thenReturn(operatingSystemVersion); when(() => shorebirdEnv.getShorebirdYaml()).thenReturn(shorebirdYaml); when( @@ -254,6 +260,7 @@ void main() { releaseId: any(named: 'releaseId'), platform: any(named: 'platform'), status: any(named: 'status'), + metadata: any(named: 'metadata'), ), ).thenAnswer((_) async => {}); @@ -519,6 +526,17 @@ $exception''', releaseId: release.id, platform: releasePlatform, status: ReleaseStatus.active, + metadata: const UpdateReleaseMetadata( + releasePlatform: releasePlatform, + flutterVersionOverride: null, + generatedApks: false, + environment: BuildEnvironmentMetadata( + operatingSystem: operatingSystem, + operatingSystemVersion: operatingSystemVersion, + shorebirdVersion: packageVersion, + xcodeVersion: null, + ), + ), ), ).called(1); }); @@ -574,6 +592,7 @@ $exception''', releaseId: release.id, platform: releasePlatform, status: ReleaseStatus.active, + metadata: any(named: 'metadata'), ), ).called(1); }); diff --git a/packages/shorebird_cli/test/src/commands/release/release_android_command_test.dart b/packages/shorebird_cli/test/src/commands/release/release_android_command_test.dart index 1b3883c98..5fdd8b768 100644 --- a/packages/shorebird_cli/test/src/commands/release/release_android_command_test.dart +++ b/packages/shorebird_cli/test/src/commands/release/release_android_command_test.dart @@ -23,6 +23,7 @@ import 'package:shorebird_cli/src/shorebird_flutter.dart'; import 'package:shorebird_cli/src/shorebird_process.dart'; import 'package:shorebird_cli/src/shorebird_validator.dart'; import 'package:shorebird_cli/src/validators/validators.dart'; +import 'package:shorebird_cli/src/version.dart'; import 'package:shorebird_code_push_client/shorebird_code_push_client.dart'; import 'package:test/test.dart'; @@ -38,6 +39,8 @@ void main() { const versionName = '1.2.3'; const versionCode = '1'; const version = '$versionName+$versionCode'; + const operatingSystem = 'macOS'; + const operatingSystemVersion = '11.0.0'; const appDisplayName = 'Test App'; const arch = 'aarch64'; const releasePlatform = ReleasePlatform.android; @@ -194,6 +197,9 @@ void main() { when( () => logger.prompt(any(), defaultValue: any(named: 'defaultValue')), ).thenReturn(version); + when(() => platform.operatingSystem).thenReturn(operatingSystem); + when(() => platform.operatingSystemVersion) + .thenReturn(operatingSystemVersion); when( () => flutterBuildProcessResult.exitCode, ).thenReturn(ExitCode.success.code); @@ -239,6 +245,7 @@ void main() { releaseId: any(named: 'releaseId'), platform: any(named: 'platform'), status: any(named: 'status'), + metadata: any(named: 'metadata'), ), ).thenAnswer((_) async {}); when(() => doctor.androidCommandValidators) @@ -396,6 +403,25 @@ $exception''', platform: releasePlatform, ), ).called(1); + verify( + () => codePushClientWrapper.updateReleaseStatus( + appId: appId, + releaseId: release.id, + platform: releasePlatform, + status: ReleaseStatus.active, + metadata: const UpdateReleaseMetadata( + releasePlatform: releasePlatform, + flutterVersionOverride: flutterVersion, + generatedApks: false, + environment: BuildEnvironmentMetadata( + operatingSystem: operatingSystem, + operatingSystemVersion: operatingSystemVersion, + shorebirdVersion: packageVersion, + xcodeVersion: null, + ), + ), + ), + ).called(1); }); group('when flutter version install fails', () { @@ -506,6 +532,17 @@ ${link(uri: Uri.parse('https://support.google.com/googleplay/android-developer/a releaseId: release.id, platform: releasePlatform, status: ReleaseStatus.active, + metadata: const UpdateReleaseMetadata( + releasePlatform: releasePlatform, + flutterVersionOverride: null, + generatedApks: false, + environment: BuildEnvironmentMetadata( + operatingSystem: operatingSystem, + operatingSystemVersion: operatingSystemVersion, + shorebirdVersion: packageVersion, + xcodeVersion: null, + ), + ), ), ).called(1); expect(exitCode, ExitCode.success.code); @@ -563,6 +600,17 @@ ${link(uri: Uri.parse('https://support.google.com/googleplay/android-developer/a releaseId: release.id, platform: releasePlatform, status: ReleaseStatus.active, + metadata: const UpdateReleaseMetadata( + releasePlatform: releasePlatform, + flutterVersionOverride: null, + generatedApks: true, + environment: BuildEnvironmentMetadata( + operatingSystem: operatingSystem, + operatingSystemVersion: operatingSystemVersion, + shorebirdVersion: packageVersion, + xcodeVersion: null, + ), + ), ), ).called(1); const buildApkArguments = ['build', 'apk', '--release']; @@ -721,6 +769,7 @@ Either run `flutter pub get` manually, or follow the steps in ${link(uri: Uri.pa releaseId: release.id, platform: releasePlatform, status: ReleaseStatus.active, + metadata: any(named: 'metadata'), ), ).called(1); expect(exitCode, ExitCode.success.code); diff --git a/packages/shorebird_cli/test/src/commands/release/release_ios_command_test.dart b/packages/shorebird_cli/test/src/commands/release/release_ios_command_test.dart index d8bb7a77f..86d0a1372 100644 --- a/packages/shorebird_cli/test/src/commands/release/release_ios_command_test.dart +++ b/packages/shorebird_cli/test/src/commands/release/release_ios_command_test.dart @@ -22,6 +22,7 @@ import 'package:shorebird_cli/src/shorebird_flutter.dart'; import 'package:shorebird_cli/src/shorebird_process.dart'; import 'package:shorebird_cli/src/shorebird_validator.dart'; import 'package:shorebird_cli/src/validators/validators.dart'; +import 'package:shorebird_cli/src/version.dart'; import 'package:shorebird_code_push_client/shorebird_code_push_client.dart'; import 'package:test/test.dart'; @@ -37,6 +38,9 @@ void main() { const versionName = '1.2.3'; const versionCode = '1'; const version = '$versionName+$versionCode'; + const operatingSystem = 'macOS'; + const operatingSystemVersion = '11.0.0'; + const xcodeVersion = '12.0'; const appDisplayName = 'Test App'; const arch = 'armv7'; const releasePlatform = ReleasePlatform.ios; @@ -267,8 +271,9 @@ flutter: when( () => operatingSystemInterface.which('flutter'), ).thenReturn('/path/to/flutter'); - when(() => platform.operatingSystem).thenReturn(Platform.macOS); - when(() => platform.operatingSystemVersion).thenReturn('1.2.3'); + when(() => platform.operatingSystem).thenReturn(operatingSystem); + when(() => platform.operatingSystemVersion) + .thenReturn(operatingSystemVersion); when( () => flutterBuildProcessResult.exitCode, ).thenReturn(ExitCode.success.code); @@ -326,7 +331,7 @@ flutter: supportedOperatingSystems: any(named: 'supportedOperatingSystems'), ), ).thenAnswer((_) async {}); - when(() => xcodeBuild.version()).thenAnswer((_) async => '15.0'); + when(() => xcodeBuild.version()).thenAnswer((_) async => xcodeVersion); command = runWithOverrides(ReleaseIosCommand.new) ..testArgResults = argResults; @@ -656,6 +661,25 @@ $exception''', platform: releasePlatform, ), ).called(1); + verify( + () => codePushClientWrapper.updateReleaseStatus( + appId: appId, + releaseId: release.id, + platform: releasePlatform, + status: ReleaseStatus.active, + metadata: const UpdateReleaseMetadata( + releasePlatform: releasePlatform, + flutterVersionOverride: flutterVersion, + generatedApks: false, + environment: BuildEnvironmentMetadata( + operatingSystem: operatingSystem, + operatingSystemVersion: operatingSystemVersion, + shorebirdVersion: packageVersion, + xcodeVersion: xcodeVersion, + ), + ), + ), + ).called(1); }); group('when flutter version install fails', () { @@ -903,6 +927,17 @@ error: exportArchive: No signing certificate "iOS Distribution" found releaseId: release.id, platform: releasePlatform, status: ReleaseStatus.active, + metadata: const UpdateReleaseMetadata( + releasePlatform: releasePlatform, + flutterVersionOverride: null, + generatedApks: false, + environment: BuildEnvironmentMetadata( + operatingSystem: operatingSystem, + operatingSystemVersion: operatingSystemVersion, + shorebirdVersion: packageVersion, + xcodeVersion: xcodeVersion, + ), + ), ), ).called(1); expect(exitCode, ExitCode.success.code); @@ -1004,6 +1039,7 @@ flavors: releaseId: release.id, platform: releasePlatform, status: ReleaseStatus.active, + metadata: any(named: 'metadata'), ), ).called(1); }); diff --git a/packages/shorebird_cli/test/src/commands/release/release_ios_framework_command_test.dart b/packages/shorebird_cli/test/src/commands/release/release_ios_framework_command_test.dart index a5b7c1fb2..a49484c99 100644 --- a/packages/shorebird_cli/test/src/commands/release/release_ios_framework_command_test.dart +++ b/packages/shorebird_cli/test/src/commands/release/release_ios_framework_command_test.dart @@ -20,6 +20,7 @@ import 'package:shorebird_cli/src/shorebird_flutter.dart'; import 'package:shorebird_cli/src/shorebird_process.dart'; import 'package:shorebird_cli/src/shorebird_validator.dart'; import 'package:shorebird_cli/src/validators/validators.dart'; +import 'package:shorebird_cli/src/version.dart'; import 'package:shorebird_code_push_client/shorebird_code_push_client.dart'; import 'package:test/test.dart'; @@ -35,6 +36,9 @@ void main() { const versionName = '1.2.3'; const versionCode = '1'; const version = '$versionName+$versionCode'; + const operatingSystem = 'macOS'; + const operatingSystemVersion = '11.0.0'; + const xcodeVersion = '12.0'; const appDisplayName = 'Test App'; const releasePlatform = ReleasePlatform.ios; final appMetadata = AppMetadata( @@ -206,8 +210,9 @@ flutter: when(() => logger.confirm(any())).thenReturn(true); when(() => operatingSystemInterface.which('flutter')) .thenReturn('/path/to/flutter'); - when(() => platform.operatingSystem).thenReturn(Platform.macOS); - when(() => platform.operatingSystemVersion).thenReturn('1.2.3'); + when(() => platform.operatingSystem).thenReturn(operatingSystem); + when(() => platform.operatingSystemVersion) + .thenReturn(operatingSystemVersion); when( () => codePushClientWrapper.getApp(appId: any(named: 'appId')), ).thenAnswer((_) async => appMetadata); @@ -244,6 +249,7 @@ flutter: releaseId: any(named: 'releaseId'), platform: any(named: 'platform'), status: any(named: 'status'), + metadata: any(named: 'metadata'), ), ).thenAnswer((_) async => {}); when( @@ -254,7 +260,7 @@ flutter: supportedOperatingSystems: any(named: 'supportedOperatingSystems'), ), ).thenAnswer((_) async {}); - when(() => xcodeBuild.version()).thenAnswer((_) async => '15.0'); + when(() => xcodeBuild.version()).thenAnswer((_) async => xcodeVersion); command = runWithOverrides(ReleaseIosFrameworkCommand.new) ..testArgResults = argResults; @@ -386,6 +392,25 @@ $exception''', platform: releasePlatform, ), ).called(1); + verify( + () => codePushClientWrapper.updateReleaseStatus( + appId: appId, + releaseId: release.id, + platform: releasePlatform, + status: ReleaseStatus.active, + metadata: const UpdateReleaseMetadata( + releasePlatform: releasePlatform, + flutterVersionOverride: flutterVersion, + generatedApks: false, + environment: BuildEnvironmentMetadata( + operatingSystem: operatingSystem, + operatingSystemVersion: operatingSystemVersion, + shorebirdVersion: packageVersion, + xcodeVersion: xcodeVersion, + ), + ), + ), + ).called(1); }); group('when flutter version install fails', () { @@ -483,6 +508,7 @@ $exception''', releaseId: release.id, platform: releasePlatform, status: ReleaseStatus.active, + metadata: any(named: 'metadata'), ), ).called(1); }); @@ -525,6 +551,17 @@ $exception''', releaseId: release.id, platform: releasePlatform, status: ReleaseStatus.active, + metadata: const UpdateReleaseMetadata( + releasePlatform: releasePlatform, + flutterVersionOverride: null, + generatedApks: false, + environment: BuildEnvironmentMetadata( + operatingSystem: operatingSystem, + operatingSystemVersion: operatingSystemVersion, + shorebirdVersion: packageVersion, + xcodeVersion: xcodeVersion, + ), + ), ), ).called(1); expect(exitCode, ExitCode.success.code); From 9b109cb807b4bde612c074b736341905e88ebb30 Mon Sep 17 00:00:00 2001 From: Bryan Oltman Date: Wed, 27 Mar 2024 14:32:10 -0400 Subject: [PATCH 10/13] Add missing coverage:ignore-end --- .../lib/src/models/build_environment_metadata.dart | 1 + 1 file changed, 1 insertion(+) diff --git a/packages/shorebird_code_push_protocol/lib/src/models/build_environment_metadata.dart b/packages/shorebird_code_push_protocol/lib/src/models/build_environment_metadata.dart index 93ccaa412..ad7fca7fd 100644 --- a/packages/shorebird_code_push_protocol/lib/src/models/build_environment_metadata.dart +++ b/packages/shorebird_code_push_protocol/lib/src/models/build_environment_metadata.dart @@ -31,6 +31,7 @@ class BuildEnvironmentMetadata extends Equatable { operatingSystemVersion: operatingSystemVersion, xcodeVersion: xcodeVersion, ); + // coverage:ignore-end /// Converts a Map to a [BuildEnvironmentMetadata] factory BuildEnvironmentMetadata.fromJson(Map json) => From 45d5be6aef8f70c5a6aea744e9764f1a7b27cc83 Mon Sep 17 00:00:00 2001 From: Bryan Oltman Date: Wed, 27 Mar 2024 14:51:17 -0400 Subject: [PATCH 11/13] coverage --- .../test/src/executables/xcodebuild_test.dart | 42 ++++++++++++++++++- 1 file changed, 41 insertions(+), 1 deletion(-) diff --git a/packages/shorebird_cli/test/src/executables/xcodebuild_test.dart b/packages/shorebird_cli/test/src/executables/xcodebuild_test.dart index 4b9a952c3..35bad2ddb 100644 --- a/packages/shorebird_cli/test/src/executables/xcodebuild_test.dart +++ b/packages/shorebird_cli/test/src/executables/xcodebuild_test.dart @@ -6,6 +6,7 @@ import 'package:path/path.dart' as p; import 'package:scoped/scoped.dart'; import 'package:shorebird_cli/src/executables/executables.dart'; import 'package:shorebird_cli/src/shorebird_process.dart'; +import 'package:test/expect.dart'; import 'package:test/test.dart'; import '../mocks.dart'; @@ -134,7 +135,46 @@ To add iOS, run "flutter create . --platforms ios"''', }); group('version', () { - test('TODO', () async {}); + group('when command exits with non-zero code', () { + setUp(() { + when(() => process.run('xcodebuild', ['-version'])).thenAnswer( + (_) async => ShorebirdProcessResult( + exitCode: ExitCode.software.code, + stdout: '', + stderr: 'error', + ), + ); + }); + + test('throws ProcessException', () async { + expect( + () => runWithOverrides(xcodeBuild.version), + throwsA(isA()), + ); + }); + }); + + group('when command exits with success code', () { + setUp(() { + when(() => process.run('xcodebuild', ['-version'])).thenAnswer( + (_) async => ShorebirdProcessResult( + exitCode: ExitCode.success.code, + stdout: ''' +Xcode 15.3 +Build version 15E204a +''', + stderr: '', + ), + ); + }); + + test('returns output lines joined by spaces', () async { + expect( + await runWithOverrides(xcodeBuild.version), + equals('Xcode 15.3 Build version 15E204a'), + ); + }); + }); }); }); } From 95874c210cb14395315cf773c8a3a491be22a2d1 Mon Sep 17 00:00:00 2001 From: Bryan Oltman Date: Wed, 27 Mar 2024 17:37:07 -0400 Subject: [PATCH 12/13] Update metadata comment headers --- .../lib/src/models/build_environment_metadata.dart | 7 +++++++ .../lib/src/models/create_patch_metadata.dart | 7 +++++++ .../lib/src/models/update_release_metadata.dart | 7 +++++++ 3 files changed, 21 insertions(+) diff --git a/packages/shorebird_code_push_protocol/lib/src/models/build_environment_metadata.dart b/packages/shorebird_code_push_protocol/lib/src/models/build_environment_metadata.dart index ad7fca7fd..3551618a4 100644 --- a/packages/shorebird_code_push_protocol/lib/src/models/build_environment_metadata.dart +++ b/packages/shorebird_code_push_protocol/lib/src/models/build_environment_metadata.dart @@ -5,6 +5,13 @@ part 'build_environment_metadata.g.dart'; /// {@template build_environment_metadata} /// Information about the environment used to build a release or patch. +/// +/// Collection of this information is done to help Shorebird users debug any +/// later failures in their builds. +/// +/// We do not collect Personally Identifying Information (e.g. no paths, +/// argument lists, etc.) in accordance with our privacy policy: +/// https://shorebird.dev/privacy/ /// {@endtemplate} @JsonSerializable() class BuildEnvironmentMetadata extends Equatable { diff --git a/packages/shorebird_code_push_protocol/lib/src/models/create_patch_metadata.dart b/packages/shorebird_code_push_protocol/lib/src/models/create_patch_metadata.dart index 00e0095ec..f3ecd8d59 100644 --- a/packages/shorebird_code_push_protocol/lib/src/models/create_patch_metadata.dart +++ b/packages/shorebird_code_push_protocol/lib/src/models/create_patch_metadata.dart @@ -6,6 +6,13 @@ part 'create_patch_metadata.g.dart'; /// {@template create_patch_metadata} /// Information about a patch, used for debugging purposes. +/// +/// Collection of this information is done to help Shorebird users debug any +/// later failures in their builds. +/// +/// We do not collect Personally Identifying Information (e.g. no paths, +/// argument lists, etc.) in accordance with our privacy policy: +/// https://shorebird.dev/privacy/ /// {@endtemplate} @JsonSerializable() class CreatePatchMetadata extends Equatable { diff --git a/packages/shorebird_code_push_protocol/lib/src/models/update_release_metadata.dart b/packages/shorebird_code_push_protocol/lib/src/models/update_release_metadata.dart index 0ebc6edb1..e543dad2a 100644 --- a/packages/shorebird_code_push_protocol/lib/src/models/update_release_metadata.dart +++ b/packages/shorebird_code_push_protocol/lib/src/models/update_release_metadata.dart @@ -6,6 +6,13 @@ part 'update_release_metadata.g.dart'; /// {@template release_metadata} /// Information about the creation of patch, used for debugging purposes. +/// +/// Collection of this information is done to help Shorebird users debug any +/// later failures in their builds. +/// +/// We do not collect Personally Identifying Information (e.g. no paths, +/// argument lists, etc.) in accordance with our privacy policy: +/// https://shorebird.dev/privacy/ /// {@endtemplate} @JsonSerializable() class UpdateReleaseMetadata extends Equatable { From 7f677ced9d26649db17464d14a39e7052f193eeb Mon Sep 17 00:00:00 2001 From: Bryan Oltman Date: Wed, 27 Mar 2024 17:59:07 -0400 Subject: [PATCH 13/13] Add reasons --- .../src/models/build_environment_metadata.dart | 12 ++++++++++++ .../lib/src/models/create_patch_metadata.dart | 16 ++++++++++++++++ .../lib/src/models/update_release_metadata.dart | 9 +++++++++ 3 files changed, 37 insertions(+) diff --git a/packages/shorebird_code_push_protocol/lib/src/models/build_environment_metadata.dart b/packages/shorebird_code_push_protocol/lib/src/models/build_environment_metadata.dart index 3551618a4..73bd98640 100644 --- a/packages/shorebird_code_push_protocol/lib/src/models/build_environment_metadata.dart +++ b/packages/shorebird_code_push_protocol/lib/src/models/build_environment_metadata.dart @@ -48,16 +48,28 @@ class BuildEnvironmentMetadata extends Equatable { Map toJson() => _$BuildEnvironmentMetadataToJson(this); /// The version of Shorebird used to run the command. + /// + /// Reason: each version of shorebird has new features and bug fixes. Users + /// using an older version may be running into issues that have already been + /// fixed. final String shorebirdVersion; /// The operating system used to run the release command. + /// + /// Reason: issues may occur on some OSes and not others (especially Windows + /// vs non-Windows). final String operatingSystem; /// The version of [operatingSystem]. + /// + /// Reason: issues may occur on some OS versions and not others. final String operatingSystemVersion; /// The version of Xcode used to build the patch. Only provided for iOS /// patches. + /// + /// Reason: Xcode behavior can change between versions. Ex: the + /// `shorebird preview` mechanism changed entirely between Xcode 14 and 15. final String? xcodeVersion; @override diff --git a/packages/shorebird_code_push_protocol/lib/src/models/create_patch_metadata.dart b/packages/shorebird_code_push_protocol/lib/src/models/create_patch_metadata.dart index f3ecd8d59..adbe5d10e 100644 --- a/packages/shorebird_code_push_protocol/lib/src/models/create_patch_metadata.dart +++ b/packages/shorebird_code_push_protocol/lib/src/models/create_patch_metadata.dart @@ -58,18 +58,34 @@ class CreatePatchMetadata extends Equatable { final ReleasePlatform releasePlatform; /// Whether the `--allow-asset-diffs` flag was used. + /// + /// Reason: this helps us understand how often prevalent the need to ignore + /// asset changes is. final bool usedIgnoreAssetChangesFlag; /// Whether asset changes were detected in the patch. + /// + /// Reason: shorebird does not support asset changes in patches, and knowing + /// that asset changes were detected can help explain unexpected behavior in + /// a patch. final bool hasAssetChanges; /// Whether the `--allow-native-diffs` flag was used. + /// + /// Reason: this helps us understand how often prevalent the need to ignore + /// native code changes is. final bool usedIgnoreNativeChangesFlag; /// Whether native code changes were detected in the patch. + /// + /// Reason: shorebird does not support native code changes in patches, and + /// knowing that native code changes were detected can help explain unexpected + /// behavior in a patch. final bool hasNativeChanges; /// Properties about the environment in which the patch was created. + /// + /// Reason: see [BuildEnvironmentMetadata]. final BuildEnvironmentMetadata environment; @override diff --git a/packages/shorebird_code_push_protocol/lib/src/models/update_release_metadata.dart b/packages/shorebird_code_push_protocol/lib/src/models/update_release_metadata.dart index e543dad2a..3d8038fe1 100644 --- a/packages/shorebird_code_push_protocol/lib/src/models/update_release_metadata.dart +++ b/packages/shorebird_code_push_protocol/lib/src/models/update_release_metadata.dart @@ -52,13 +52,22 @@ class UpdateReleaseMetadata extends Equatable { final ReleasePlatform releasePlatform; /// The Flutter version specified by the user, if any. + /// + /// Reason: different Flutter versions have different performance + /// characteristics and features. Additionally, this helps us understand which + /// versions of Flutter are most commonly used. final String? flutterVersionOverride; /// Whether the user opted to generate an APK for the release (android-only). + /// + /// Reason: if this flag is present, it produces different build artifacts, + /// which may affect the build process. final bool? generatedApks; /// Properties about the environment in which the update to the release was /// performed. + /// + /// Reason: see [BuildEnvironmentMetadata]. final BuildEnvironmentMetadata environment; @override