feat(shorebird_cli): add uses_shorebird_code_push_package to patch and release metadata (#3393)

This commit is contained in:
Bryan Oltman
2025-11-20 14:45:51 -05:00
committed by GitHub
parent 3f3834f007
commit 2ec5af7cf6
20 changed files with 148 additions and 17 deletions
@@ -453,6 +453,8 @@ Building patch with Flutter $flutterVersionString
operatingSystemVersion: platform.operatingSystemVersion,
shorebirdVersion: packageVersion,
shorebirdYaml: shorebirdEnv.getShorebirdYaml()!,
usesShorebirdCodePushPackage:
shorebirdEnv.usesShorebirdCodePushPackage,
),
);
final updateMetadata = await patcher.updatedCreatePatchMetadata(
@@ -570,6 +570,7 @@ ${summary.join('\n')}
operatingSystemVersion: platform.operatingSystemVersion,
shorebirdVersion: packageVersion,
shorebirdYaml: shorebirdEnv.getShorebirdYaml()!,
usesShorebirdCodePushPackage: shorebirdEnv.usesShorebirdCodePushPackage,
),
);
final updatedMetadata = await releaser.updatedReleaseMetadata(baseMetadata);
@@ -23,6 +23,7 @@ class BuildEnvironmentMetadata extends Equatable {
required this.operatingSystem,
required this.operatingSystemVersion,
required this.shorebirdYaml,
required this.usesShorebirdCodePushPackage,
this.xcodeVersion,
});
@@ -35,6 +36,7 @@ class BuildEnvironmentMetadata extends Equatable {
String operatingSystem = 'macos',
String operatingSystemVersion = '1.2.3',
ShorebirdYaml shorebirdYaml = const ShorebirdYaml(appId: '123'),
bool usesShorebirdCodePushPackage = false,
String? xcodeVersion = '15.0',
}) => BuildEnvironmentMetadata(
flutterRevision: flutterRevision,
@@ -42,6 +44,7 @@ class BuildEnvironmentMetadata extends Equatable {
operatingSystem: operatingSystem,
operatingSystemVersion: operatingSystemVersion,
shorebirdYaml: shorebirdYaml,
usesShorebirdCodePushPackage: usesShorebirdCodePushPackage,
xcodeVersion: xcodeVersion,
);
// coverage:ignore-end
@@ -61,6 +64,7 @@ class BuildEnvironmentMetadata extends Equatable {
String? operatingSystem,
String? operatingSystemVersion,
ShorebirdYaml? shorebirdYaml,
bool? usesShorebirdCodePushPackage,
String? xcodeVersion,
}) => BuildEnvironmentMetadata(
flutterRevision: flutterRevision ?? this.flutterRevision,
@@ -69,6 +73,8 @@ class BuildEnvironmentMetadata extends Equatable {
operatingSystemVersion:
operatingSystemVersion ?? this.operatingSystemVersion,
shorebirdYaml: shorebirdYaml ?? this.shorebirdYaml,
usesShorebirdCodePushPackage:
usesShorebirdCodePushPackage ?? this.usesShorebirdCodePushPackage,
xcodeVersion: xcodeVersion ?? this.xcodeVersion,
);
@@ -99,6 +105,12 @@ class BuildEnvironmentMetadata extends Equatable {
/// The shorebird.yaml file for this project.
final ShorebirdYaml shorebirdYaml;
/// Whether the project uses package:shorebird_code_push.
///
/// Reason: this helps us understand which projects are using the Shorebird
/// CodePush package and better support customers who encounter issues.
final bool usesShorebirdCodePushPackage;
/// The version of Xcode used to build the patch. Only provided for iOS
/// patches.
///
@@ -113,6 +125,7 @@ class BuildEnvironmentMetadata extends Equatable {
operatingSystem,
operatingSystemVersion,
shorebirdYaml,
usesShorebirdCodePushPackage,
xcodeVersion,
];
}
@@ -29,6 +29,10 @@ BuildEnvironmentMetadata _$BuildEnvironmentMetadataFromJson(
'shorebird_yaml',
(v) => ShorebirdYaml.fromJson(v as Map<String, dynamic>),
),
usesShorebirdCodePushPackage: $checkedConvert(
'uses_shorebird_code_push_package',
(v) => v as bool,
),
xcodeVersion: $checkedConvert('xcode_version', (v) => v as String?),
);
return val;
@@ -39,6 +43,7 @@ BuildEnvironmentMetadata _$BuildEnvironmentMetadataFromJson(
'operatingSystem': 'operating_system',
'operatingSystemVersion': 'operating_system_version',
'shorebirdYaml': 'shorebird_yaml',
'usesShorebirdCodePushPackage': 'uses_shorebird_code_push_package',
'xcodeVersion': 'xcode_version',
},
);
@@ -51,5 +56,6 @@ Map<String, dynamic> _$BuildEnvironmentMetadataToJson(
'operating_system': instance.operatingSystem,
'operating_system_version': instance.operatingSystemVersion,
'shorebird_yaml': instance.shorebirdYaml.toJson(),
'uses_shorebird_code_push_package': instance.usesShorebirdCodePushPackage,
'xcode_version': instance.xcodeVersion,
};
@@ -69,6 +69,12 @@ class ShorebirdEnv {
).readAsStringSync().trim();
}
/// Whether the project uses package:shorebird_code_push.
bool get usesShorebirdCodePushPackage {
final pubspec = getPubspecYaml();
return pubspec?.dependencies.containsKey('shorebird_code_push') ?? false;
}
/// The root of the Shorebird-vended Flutter git checkout.
Directory get flutterDirectory {
return Directory(
@@ -634,6 +634,7 @@ void main() {
operatingSystemVersion: operatingSystemVersion,
shorebirdVersion: packageVersion,
shorebirdYaml: ShorebirdYaml(appId: 'app-id'),
usesShorebirdCodePushPackage: true,
),
);
@@ -736,6 +736,7 @@ Looked in:
operatingSystemVersion: operatingSystemVersion,
shorebirdVersion: packageVersion,
shorebirdYaml: ShorebirdYaml(appId: 'app-id'),
usesShorebirdCodePushPackage: false,
),
);
@@ -1023,6 +1023,7 @@ void main() {
operatingSystemVersion: operatingSystemVersion,
shorebirdVersion: packageVersion,
shorebirdYaml: ShorebirdYaml(appId: 'app-id'),
usesShorebirdCodePushPackage: true,
),
);
@@ -1044,6 +1045,7 @@ void main() {
operatingSystemVersion: operatingSystemVersion,
shorebirdVersion: packageVersion,
shorebirdYaml: ShorebirdYaml(appId: 'app-id'),
usesShorebirdCodePushPackage: true,
xcodeVersion: xcodeVersion,
),
),
@@ -1076,6 +1078,7 @@ void main() {
operatingSystemVersion: operatingSystemVersion,
shorebirdVersion: packageVersion,
shorebirdYaml: ShorebirdYaml(appId: 'app-id'),
usesShorebirdCodePushPackage: true,
),
);
@@ -1099,6 +1102,7 @@ void main() {
operatingSystemVersion: operatingSystemVersion,
shorebirdVersion: packageVersion,
shorebirdYaml: ShorebirdYaml(appId: 'app-id'),
usesShorebirdCodePushPackage: true,
xcodeVersion: xcodeVersion,
),
),
@@ -1540,6 +1540,7 @@ For more information see: ${supportedFlutterVersionsUrl.toLink()}'''),
operatingSystemVersion: operatingSystemVersion,
shorebirdVersion: packageVersion,
shorebirdYaml: ShorebirdYaml(appId: 'app-id'),
usesShorebirdCodePushPackage: false,
),
);
@@ -1561,6 +1562,7 @@ For more information see: ${supportedFlutterVersionsUrl.toLink()}'''),
operatingSystemVersion: operatingSystemVersion,
shorebirdVersion: packageVersion,
shorebirdYaml: ShorebirdYaml(appId: 'app-id'),
usesShorebirdCodePushPackage: false,
xcodeVersion: xcodeVersion,
),
),
@@ -1593,6 +1595,7 @@ For more information see: ${supportedFlutterVersionsUrl.toLink()}'''),
operatingSystemVersion: operatingSystemVersion,
shorebirdVersion: packageVersion,
shorebirdYaml: ShorebirdYaml(appId: 'app-id'),
usesShorebirdCodePushPackage: false,
),
);
@@ -1616,6 +1619,7 @@ For more information see: ${supportedFlutterVersionsUrl.toLink()}'''),
operatingSystemVersion: operatingSystemVersion,
shorebirdVersion: packageVersion,
xcodeVersion: xcodeVersion,
usesShorebirdCodePushPackage: false,
shorebirdYaml: ShorebirdYaml(appId: 'app-id'),
),
),
@@ -1158,6 +1158,7 @@ For more information see: ${supportedFlutterVersionsUrl.toLink()}'''),
operatingSystemVersion: operatingSystemVersion,
shorebirdVersion: packageVersion,
shorebirdYaml: ShorebirdYaml(appId: 'app-id'),
usesShorebirdCodePushPackage: false,
),
);
@@ -1178,6 +1179,7 @@ For more information see: ${supportedFlutterVersionsUrl.toLink()}'''),
shorebirdVersion: packageVersion,
xcodeVersion: xcodeVersion,
shorebirdYaml: ShorebirdYaml(appId: 'app-id'),
usesShorebirdCodePushPackage: false,
),
),
),
@@ -313,6 +313,7 @@ void main() {
return shorebirdEnv;
});
when(() => shorebirdEnv.canAcceptUserInput).thenReturn(true);
when(() => shorebirdEnv.usesShorebirdCodePushPackage).thenReturn(false);
when(
() => shorebirdFlutter.getVersionAndRevision(),
@@ -598,6 +598,7 @@ To change the version of this release, change your app's version in your pubspec
operatingSystemVersion: operatingSystemVersion,
shorebirdVersion: packageVersion,
shorebirdYaml: ShorebirdYaml(appId: 'app-id'),
usesShorebirdCodePushPackage: true,
),
);
@@ -622,6 +623,7 @@ To change the version of this release, change your app's version in your pubspec
operatingSystemVersion: operatingSystemVersion,
shorebirdVersion: packageVersion,
shorebirdYaml: ShorebirdYaml(appId: 'app-id'),
usesShorebirdCodePushPackage: true,
),
),
),
@@ -650,6 +652,7 @@ To change the version of this release, change your app's version in your pubspec
operatingSystemVersion: operatingSystemVersion,
shorebirdVersion: packageVersion,
shorebirdYaml: ShorebirdYaml(appId: 'app-id'),
usesShorebirdCodePushPackage: true,
),
),
),
@@ -454,6 +454,7 @@ void main() {
operatingSystemVersion: operatingSystemVersion,
shorebirdVersion: packageVersion,
shorebirdYaml: ShorebirdYaml(appId: 'app-id'),
usesShorebirdCodePushPackage: false,
),
);
@@ -476,6 +477,7 @@ void main() {
operatingSystemVersion: operatingSystemVersion,
shorebirdVersion: packageVersion,
shorebirdYaml: ShorebirdYaml(appId: 'app-id'),
usesShorebirdCodePushPackage: false,
xcodeVersion: xcodeVersion,
),
),
@@ -693,6 +693,7 @@ To change the version of this release, change your app's version in your pubspec
operatingSystemVersion: operatingSystemVersion,
shorebirdVersion: packageVersion,
shorebirdYaml: ShorebirdYaml(appId: 'app-id'),
usesShorebirdCodePushPackage: true,
),
);
@@ -713,6 +714,7 @@ To change the version of this release, change your app's version in your pubspec
operatingSystemVersion: operatingSystemVersion,
shorebirdVersion: packageVersion,
shorebirdYaml: ShorebirdYaml(appId: 'app-id'),
usesShorebirdCodePushPackage: true,
xcodeVersion: xcodeVersion,
),
),
@@ -620,6 +620,7 @@ To change the version of this release, change your app's version in your pubspec
operatingSystemVersion: operatingSystemVersion,
shorebirdVersion: packageVersion,
shorebirdYaml: ShorebirdYaml(appId: 'app-id'),
usesShorebirdCodePushPackage: false,
),
);
@@ -640,6 +641,7 @@ To change the version of this release, change your app's version in your pubspec
operatingSystemVersion: operatingSystemVersion,
shorebirdVersion: packageVersion,
shorebirdYaml: ShorebirdYaml(appId: 'app-id'),
usesShorebirdCodePushPackage: false,
xcodeVersion: xcodeVersion,
),
),
@@ -182,6 +182,7 @@ void main() {
).thenReturn(projectRoot);
when(() => shorebirdEnv.flutterRevision).thenReturn(flutterRevision);
when(() => shorebirdEnv.canAcceptUserInput).thenReturn(true);
when(() => shorebirdEnv.usesShorebirdCodePushPackage).thenReturn(true);
when(
() => shorebirdFlutter.getVersionAndRevision(),
@@ -10,8 +10,9 @@ void main() {
operatingSystem: 'macos',
operatingSystemVersion: '1.2.3',
shorebirdVersion: '4.5.6',
xcodeVersion: '15.0',
shorebirdYaml: ShorebirdYaml(appId: 'app-id'),
usesShorebirdCodePushPackage: false,
xcodeVersion: '15.0',
);
expect(
BuildEnvironmentMetadata.fromJson(metadata.toJson()).toJson(),
@@ -26,8 +27,9 @@ void main() {
operatingSystem: 'macos',
operatingSystemVersion: '1.2.3',
shorebirdVersion: '4.5.6',
xcodeVersion: '15.0',
shorebirdYaml: ShorebirdYaml(appId: 'app-id'),
usesShorebirdCodePushPackage: false,
xcodeVersion: '15.0',
);
expect(metadata.copyWith(), equals(metadata));
@@ -39,16 +41,18 @@ void main() {
operatingSystem: 'macos',
operatingSystemVersion: '1.2.3',
shorebirdVersion: '4.5.6',
xcodeVersion: '15.0',
shorebirdYaml: ShorebirdYaml(appId: 'app-id'),
usesShorebirdCodePushPackage: false,
xcodeVersion: '15.0',
);
final newMetadata = metadata.copyWith(
flutterRevision: 'asdf',
operatingSystem: 'windows',
operatingSystemVersion: '11',
shorebirdVersion: '1.2.3',
xcodeVersion: '14.0',
shorebirdYaml: const ShorebirdYaml(appId: 'app-id2'),
usesShorebirdCodePushPackage: true,
xcodeVersion: '14.0',
);
expect(
newMetadata,
@@ -58,8 +62,9 @@ void main() {
operatingSystem: 'windows',
operatingSystemVersion: '11',
shorebirdVersion: '1.2.3',
xcodeVersion: '14.0',
shorebirdYaml: ShorebirdYaml(appId: 'app-id2'),
usesShorebirdCodePushPackage: true,
xcodeVersion: '14.0',
),
),
);
@@ -73,16 +78,18 @@ void main() {
operatingSystem: 'macos',
operatingSystemVersion: '1.2.3',
shorebirdVersion: '4.5.6',
xcodeVersion: '15.0',
shorebirdYaml: ShorebirdYaml(appId: 'app-id'),
usesShorebirdCodePushPackage: true,
xcodeVersion: '15.0',
);
const otherMetadata = BuildEnvironmentMetadata(
flutterRevision: '853d13d954df3b6e9c2f07b72062f33c52a9a64b',
operatingSystem: 'macos',
operatingSystemVersion: '1.2.3',
shorebirdVersion: '4.5.6',
xcodeVersion: '15.0',
shorebirdYaml: ShorebirdYaml(appId: 'app-id'),
usesShorebirdCodePushPackage: true,
xcodeVersion: '15.0',
);
expect(metadata, equals(otherMetadata));
});
@@ -93,16 +100,18 @@ void main() {
operatingSystem: 'macos',
operatingSystemVersion: '1.2.3',
shorebirdVersion: '4.5.6',
xcodeVersion: '15.0',
shorebirdYaml: ShorebirdYaml(appId: 'app-id'),
usesShorebirdCodePushPackage: true,
xcodeVersion: '15.0',
);
const otherMetadata = BuildEnvironmentMetadata(
flutterRevision: '853d13d954df3b6e9c2f07b72062f33c52a9a64b',
operatingSystem: 'macos',
operatingSystemVersion: '1.2.3',
shorebirdVersion: '4.5.6',
xcodeVersion: '15.1',
shorebirdYaml: ShorebirdYaml(appId: 'app-id2'),
usesShorebirdCodePushPackage: true,
xcodeVersion: '15.1',
);
expect(metadata, isNot(equals(otherMetadata)));
});
@@ -19,8 +19,9 @@ void main() {
operatingSystem: 'macos',
operatingSystemVersion: '1.2.3',
shorebirdVersion: '4.5.6',
xcodeVersion: '15.0',
shorebirdYaml: ShorebirdYaml(appId: 'app-id'),
usesShorebirdCodePushPackage: false,
xcodeVersion: '15.0',
),
);
expect(
@@ -44,8 +45,9 @@ void main() {
operatingSystem: 'macos',
operatingSystemVersion: '1.2.3',
shorebirdVersion: '4.5.6',
xcodeVersion: '15.0',
shorebirdYaml: ShorebirdYaml(appId: 'app-id'),
usesShorebirdCodePushPackage: false,
xcodeVersion: '15.0',
),
);
@@ -66,8 +68,9 @@ void main() {
operatingSystem: 'macos',
operatingSystemVersion: '1.2.3',
shorebirdVersion: '4.5.6',
xcodeVersion: '15.0',
shorebirdYaml: ShorebirdYaml(appId: 'app-id'),
usesShorebirdCodePushPackage: false,
xcodeVersion: '15.0',
),
);
@@ -83,8 +86,9 @@ void main() {
operatingSystem: 'windows',
operatingSystemVersion: '11',
shorebirdVersion: '1.2.3',
xcodeVersion: '14.0',
shorebirdYaml: ShorebirdYaml(appId: 'app-id'),
usesShorebirdCodePushPackage: false,
xcodeVersion: '14.0',
),
);
@@ -104,8 +108,9 @@ void main() {
operatingSystem: 'windows',
operatingSystemVersion: '11',
shorebirdVersion: '1.2.3',
xcodeVersion: '14.0',
shorebirdYaml: ShorebirdYaml(appId: 'app-id'),
usesShorebirdCodePushPackage: false,
xcodeVersion: '14.0',
),
),
),
@@ -129,6 +134,7 @@ void main() {
operatingSystemVersion: '1.2.3',
shorebirdVersion: '4.5.6',
xcodeVersion: '15.0',
usesShorebirdCodePushPackage: false,
shorebirdYaml: ShorebirdYaml(appId: 'app-id'),
),
);
@@ -145,8 +151,9 @@ void main() {
operatingSystem: 'macos',
operatingSystemVersion: '1.2.3',
shorebirdVersion: '4.5.6',
xcodeVersion: '15.0',
shorebirdYaml: ShorebirdYaml(appId: 'app-id'),
usesShorebirdCodePushPackage: false,
xcodeVersion: '15.0',
),
);
expect(metadata, equals(otherMetadata));
@@ -165,8 +172,9 @@ void main() {
operatingSystem: 'macos',
operatingSystemVersion: '1.2.3',
shorebirdVersion: '4.5.6',
xcodeVersion: '15.0',
shorebirdYaml: ShorebirdYaml(appId: 'app-id'),
usesShorebirdCodePushPackage: false,
xcodeVersion: '15.0',
),
);
const otherMetadata = CreatePatchMetadata(
@@ -181,8 +189,9 @@ void main() {
operatingSystem: 'macos',
operatingSystemVersion: '1.2.3',
shorebirdVersion: '4.5.6',
xcodeVersion: '15.0',
shorebirdYaml: ShorebirdYaml(appId: 'app-id'),
usesShorebirdCodePushPackage: false,
xcodeVersion: '15.0',
),
);
expect(metadata, isNot(equals(otherMetadata)));
@@ -16,6 +16,7 @@ void main() {
operatingSystemVersion: '1.2.3',
shorebirdVersion: '4.5.6',
shorebirdYaml: ShorebirdYaml(appId: 'app-id'),
usesShorebirdCodePushPackage: false,
xcodeVersion: '15.0',
),
);
@@ -37,6 +38,7 @@ void main() {
operatingSystemVersion: '1.2.3',
shorebirdVersion: '4.5.6',
shorebirdYaml: ShorebirdYaml(appId: 'app-id'),
usesShorebirdCodePushPackage: false,
xcodeVersion: '15.0',
),
);
@@ -55,6 +57,7 @@ void main() {
operatingSystemVersion: '1.2.3',
shorebirdVersion: '4.5.6',
shorebirdYaml: ShorebirdYaml(appId: 'app-id'),
usesShorebirdCodePushPackage: false,
xcodeVersion: '15.0',
),
);
@@ -69,6 +72,7 @@ void main() {
operatingSystemVersion: '11',
shorebirdVersion: '1.2.3',
shorebirdYaml: ShorebirdYaml(appId: 'app-id'),
usesShorebirdCodePushPackage: true,
xcodeVersion: '14.0',
),
);
@@ -86,6 +90,7 @@ void main() {
operatingSystemVersion: '11',
shorebirdVersion: '1.2.3',
shorebirdYaml: ShorebirdYaml(appId: 'app-id'),
usesShorebirdCodePushPackage: true,
xcodeVersion: '14.0',
),
),
@@ -106,6 +111,7 @@ void main() {
operatingSystemVersion: '1.2.3',
shorebirdVersion: '4.5.6',
shorebirdYaml: ShorebirdYaml(appId: 'app-id'),
usesShorebirdCodePushPackage: false,
xcodeVersion: '15.0',
),
);
@@ -119,6 +125,7 @@ void main() {
operatingSystemVersion: '1.2.3',
shorebirdVersion: '4.5.6',
shorebirdYaml: ShorebirdYaml(appId: 'app-id'),
usesShorebirdCodePushPackage: false,
xcodeVersion: '15.0',
),
);
@@ -136,6 +143,7 @@ void main() {
operatingSystemVersion: '1.2.3',
shorebirdVersion: '4.5.6',
shorebirdYaml: ShorebirdYaml(appId: 'app-id'),
usesShorebirdCodePushPackage: true,
xcodeVersion: '15.0',
),
);
@@ -149,6 +157,7 @@ void main() {
operatingSystemVersion: '1.2.3',
shorebirdVersion: '4.5.6',
shorebirdYaml: ShorebirdYaml(appId: 'app-id'),
usesShorebirdCodePushPackage: true,
xcodeVersion: '15.0',
),
);
@@ -688,6 +688,59 @@ test-revision
});
});
group('usesShorebirdCodePushPackage', () {
group('when pubspec.yaml does not contain shorebird_code_push', () {
setUp(() {
final tempDir = Directory.systemTemp.createTempSync();
File(p.join(tempDir.path, 'pubspec.yaml')).writeAsStringSync('''
name: test
dependencies:
clock: ^1.1.2
collection: ^1.19.1
crypto: ^3.0.6
dart_frog: ^1.2.4
''');
shorebirdEnv = runWithOverrides(
() => ShorebirdEnv(flutterProjectRootOverride: tempDir.path),
);
});
test('returns false', () {
expect(
runWithOverrides(() => shorebirdEnv.usesShorebirdCodePushPackage),
isFalse,
);
});
});
group('when pubspec.yaml contains shorebird_code_push', () {
setUp(() {
final tempDir = Directory.systemTemp.createTempSync();
File(p.join(tempDir.path, 'pubspec.yaml')).writeAsStringSync('''
name: test
dependencies:
clock: ^1.1.2
collection: ^1.19.1
crypto: ^3.0.6
dart_frog: ^1.2.4
shorebird_code_push: ^1.0.0
''');
shorebirdEnv = runWithOverrides(
() => ShorebirdEnv(flutterProjectRootOverride: tempDir.path),
);
});
test('returns true', () {
expect(
runWithOverrides(() => shorebirdEnv.usesShorebirdCodePushPackage),
isTrue,
);
});
});
});
group('shorebirdEngineRevision', () {
test('returns correct revision', () {
const engineRevision = 'test-revision';