feat(shorebird_cli): include file hash in publish (#167)
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
import 'dart:io';
|
||||
|
||||
import 'package:collection/collection.dart';
|
||||
import 'package:crypto/crypto.dart';
|
||||
import 'package:mason_logger/mason_logger.dart';
|
||||
import 'package:path/path.dart' as p;
|
||||
import 'package:shorebird_cli/src/command.dart';
|
||||
@@ -10,6 +11,9 @@ import 'package:shorebird_cli/src/shorebird_create_app_mixin.dart';
|
||||
import 'package:shorebird_cli/src/shorebird_engine_mixin.dart';
|
||||
import 'package:shorebird_code_push_client/shorebird_code_push_client.dart';
|
||||
|
||||
/// Signature for a function which takes a list of bytes and returns a hash.
|
||||
typedef HashFunction = String Function(List<int> bytes);
|
||||
|
||||
/// {@template publish_command}
|
||||
///
|
||||
/// `shorebird publish <path/to/artifact>`
|
||||
@@ -27,7 +31,8 @@ class PublishCommand extends ShorebirdCommand
|
||||
super.auth,
|
||||
super.buildCodePushClient,
|
||||
super.runProcess,
|
||||
});
|
||||
HashFunction? hashFn,
|
||||
}) : _hashFn = hashFn ?? ((m) => sha256.convert(m).toString());
|
||||
|
||||
@override
|
||||
String get description => 'Publish an update.';
|
||||
@@ -40,6 +45,8 @@ class PublishCommand extends ShorebirdCommand
|
||||
static const String _platform = 'android';
|
||||
static const String _channel = 'stable';
|
||||
|
||||
final HashFunction _hashFn;
|
||||
|
||||
@override
|
||||
Future<int> run() async {
|
||||
if (!isShorebirdInitialized) {
|
||||
@@ -91,6 +98,7 @@ class PublishCommand extends ShorebirdCommand
|
||||
return ExitCode.software.code;
|
||||
}
|
||||
|
||||
final hash = _hashFn(await artifact.readAsBytes());
|
||||
final pubspecYaml = getPubspecYaml()!;
|
||||
final shorebirdYaml = getShorebirdYaml()!;
|
||||
final codePushClient = buildCodePushClient(
|
||||
@@ -141,6 +149,7 @@ ${styleBold.wrap(lightGreen.wrap('🚀 Ready to publish a new patch!'))}
|
||||
|
||||
📱 App: ${lightCyan.wrap(app.displayName)} ${lightCyan.wrap('(${app.id})')}
|
||||
📦 Release Version: ${lightCyan.wrap(versionString)}
|
||||
#️⃣ Hash: ${lightCyan.wrap(hash)}
|
||||
''',
|
||||
);
|
||||
|
||||
@@ -198,7 +207,7 @@ ${styleBold.wrap(lightGreen.wrap('🚀 Ready to publish a new patch!'))}
|
||||
artifactPath: artifact.path,
|
||||
arch: _arch,
|
||||
platform: _platform,
|
||||
hash: '#',
|
||||
hash: hash,
|
||||
);
|
||||
createArtifactProgress.complete();
|
||||
} catch (error) {
|
||||
|
||||
@@ -15,6 +15,7 @@ dependencies:
|
||||
cli_completion: ^0.3.0
|
||||
cli_util: ^0.4.0
|
||||
collection: ^1.17.1
|
||||
crypto: ^3.0.2
|
||||
json_annotation: ^4.8.0
|
||||
mason_logger: ^0.2.4
|
||||
meta: ^1.9.0
|
||||
|
||||
Reference in New Issue
Block a user