From 1893a0d55d9e3240ef235cd886ed5ee61a08f759 Mon Sep 17 00:00:00 2001 From: Felix Angelov Date: Fri, 24 Mar 2023 16:50:12 -0500 Subject: [PATCH] feat(shorebird_cli): include file hash in publish (#167) --- .../lib/src/commands/publish_command.dart | 13 +++++++++++-- packages/shorebird_cli/pubspec.yaml | 1 + 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/packages/shorebird_cli/lib/src/commands/publish_command.dart b/packages/shorebird_cli/lib/src/commands/publish_command.dart index 1b7f134c..90479656 100644 --- a/packages/shorebird_cli/lib/src/commands/publish_command.dart +++ b/packages/shorebird_cli/lib/src/commands/publish_command.dart @@ -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 bytes); + /// {@template publish_command} /// /// `shorebird publish ` @@ -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 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) { diff --git a/packages/shorebird_cli/pubspec.yaml b/packages/shorebird_cli/pubspec.yaml index f82b1fb8..babd719c 100644 --- a/packages/shorebird_cli/pubspec.yaml +++ b/packages/shorebird_cli/pubspec.yaml @@ -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