Skip to content

Commit

Permalink
feat(shorebird_cli): record release and patch command metadata (#1824)
Browse files Browse the repository at this point in the history
  • Loading branch information
bryanoltman authored Mar 28, 2024
1 parent 1547272 commit 6209302
Show file tree
Hide file tree
Showing 23 changed files with 599 additions and 145 deletions.
15 changes: 7 additions & 8 deletions packages/shorebird_cli/lib/src/code_push_client_wrapper.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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 {
Expand All @@ -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) {
Expand Down Expand Up @@ -642,16 +645,14 @@ aar artifact already exists, continuing...''',
Future<Patch> 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;
Expand Down Expand Up @@ -709,17 +710,15 @@ aar artifact already exists, continuing...''',
Future<void> publishPatch({
required String appId,
required int releaseId,
required bool hasAssetChanges,
required bool hasNativeChanges,
required CreatePatchMetadata metadata,
required ReleasePlatform platform,
required DeploymentTrack track,
required Map<Arch, PatchArtifactBundle> patchArtifactBundles,
}) async {
final patch = await createPatch(
appId: appId,
releaseId: releaseId,
hasAssetChanges: hasAssetChanges,
hasNativeChanges: hasNativeChanges,
metadata: metadata,
);

await createPatchArtifacts(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand Down Expand Up @@ -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<Arch, String> releaseArtifactPaths;
Expand Down Expand Up @@ -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')}',
];

Expand All @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand Down Expand Up @@ -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);

Expand Down Expand Up @@ -252,15 +254,15 @@ Looked in:
appId: app.appId,
releaseId: release.id,
architectures: architectures,
platform: platform,
platform: releasePlatform,
);

final releaseAabArtifact =
await codePushClientWrapper.getReleaseArtifact(
appId: app.appId,
releaseId: release.id,
arch: 'aab',
platform: platform,
platform: releasePlatform,
);

final releaseArtifactPaths = <Arch, String>{};
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,15 @@ 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';
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}
Expand Down Expand Up @@ -392,8 +394,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,
Expand All @@ -405,6 +405,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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,19 @@ import 'package:shorebird_cli/src/commands/commands.dart';
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/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
Expand Down Expand Up @@ -330,8 +332,6 @@ ${summary.join('\n')}
await codePushClientWrapper.publishPatch(
appId: appId,
releaseId: release.id,
hasAssetChanges: diffStatus.hasAssetChanges,
hasNativeChanges: diffStatus.hasNativeChanges,
platform: releasePlatform,
track: DeploymentTrack.production,
patchArtifactBundles: {
Expand All @@ -342,6 +342,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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand Down Expand Up @@ -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?;
Expand All @@ -111,7 +113,7 @@ make smaller updates to your app.
if (existingRelease != null) {
codePushClientWrapper.ensureReleaseIsNotActive(
release: existingRelease,
platform: platform,
platform: releasePlatform,
);
}

Expand Down Expand Up @@ -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)}',
];

Expand All @@ -208,15 +210,15 @@ ${summary.join('\n')}
await codePushClientWrapper.updateReleaseStatus(
appId: appId,
releaseId: release.id,
platform: platform,
platform: releasePlatform,
status: ReleaseStatus.draft,
);
} else {
release = await codePushClientWrapper.createRelease(
appId: appId,
version: releaseVersion,
flutterRevision: shorebirdEnv.flutterRevision,
platform: platform,
platform: releasePlatform,
);
}

Expand All @@ -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,
Expand All @@ -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
Expand Down
Loading

0 comments on commit 6209302

Please sign in to comment.