run method

  1. @override
Future<void> run()
override

Runs this command.

The return value is wrapped in a Future if necessary and returned by CommandRunner.runCommand.

Implementation

@override
Future<void> run() async {
  final results = argResults!;

  final appId = results['appId'] as String;
  final issuerId = results['issuerId'] as String;
  final keyId = results['keyId'] as String;
  final privateKey =
      (results['privateKey'] as String).replaceAll(r'\n', '\n');
  final gitUrl = results['gitUrl'] as String;
  final buildOptions = results['buildOptions'] as String;
  final flutterVersion = results['flutterVersion'] as String;
  final allowAssetDiffs = results['allowAssetDiffs'] as bool;

  final appleAppStoreUtil = AppleAppStoreUtil(
    issuerId: issuerId,
    keyId: keyId,
    privateKey: privateKey,
    appId: appId,
  );

  await appleAppStoreUtil.configureSigning(gitUrl: gitUrl);

  final release = await appleAppStoreUtil.latestRelease();
  final buildName = release.buildName;
  final buildNumber = release.buildNumber;

  final pubspecVersionChange = await GitUtil.pubspecVersionChange();

  if (pubspecVersionChange == null) {
    await ShorebirdUtil.patch(
      buildName: buildName,
      buildNumber: buildNumber,
      platform: 'ios',
      buildOptions: buildOptions,
      flutterVersion: flutterVersion,
      allowAssetDiffs: allowAssetDiffs,
    );

    return;
  }

  final newBuildPaths = await ShorebirdUtil.release(
    buildName: pubspecVersionChange,
    buildNumber: buildNumber,
    platform: 'ios',
    buildOptions: buildOptions,
    flutterVersion: flutterVersion,
  );
  for (final buildPath in newBuildPaths) {
    stdout.writeln(
      'Uploading shorebird build from $buildPath to TestFlight...',
    );
    await appleAppStoreUtil.uploadBuild(
      filePath: buildPath,
      keyId: keyId,
      issuerId: issuerId,
      privateKey: privateKey,
    );
  }
}