uploadBuild method
Implementation
Future<void> uploadBuild({
required final String filePath,
required final String keyId,
required final String issuerId,
required final String privateKey,
}) async {
final file = File(
'${Platform.environment['HOME']}/.appstoreconnect/private_keys/AuthKey_$keyId.p8',
);
stdout.writeln('Checking if private key exists in ${file.path}...');
if (!file.existsSync()) {
stdout.writeln('Private key not found. Creating one...');
await file.create(recursive: true);
await file.writeAsString(privateKey);
}
stdout.writeln('Uploading build from $filePath...');
final result = await Process.run('xcrun', [
'altool',
'--upload-app',
'-f',
filePath,
'-t',
'ios',
'--apiKey',
keyId,
'--apiIssuer',
issuerId,
]);
if (result.exitCode != 0) {
throw Exception('Error uploading build to TestFlight. ${result.stderr}');
}
stdout.writeln('Uploaded to TestFlight successfully.');
}