execute method

  1. @override
Future<bool> execute(
  1. ReleasePacker releasePacker,
  2. Directory rootDirectory, {
  3. ReleaseBundle? releaseBundle,
})
override

Implementation

@override
Future<bool> execute(ReleasePacker releasePacker, Directory rootDirectory,
    {ReleaseBundle? releaseBundle}) async {
  var params = await resolveUploadParameters(releaseBundle: releaseBundle);

  if (params == null) return false;

  gcs.ObjectMetadata? metadata;
  if (params.release != null) {
    metadata = gcs.ObjectMetadata(
      contentType: params.contentType,
      custom: {
        'release': params.release!,
      },
    );
  }

  print('   »  Parsing Google Cloud Storage credential...');

  var client = await createGCSClient(credential);

  print(
      '   »  Uploading to Google Cloud Storage> project: $project ; bucket: ${this.bucket} ; file: ${params.filePath}');

  var storage = gcs.Storage(client, project);
  var bucket = storage.bucket(this.bucket);

  var objInfo = await bucket.writeBytes(
    params.filePath,
    params.bodyBytes,
    contentType: params.contentType,
    metadata: metadata,
  );

  var ok = objInfo.length == params.bodyBytes.length;

  print('   »  GCS response> ${ok ? 'Ok' : 'Faul'}');

  return ok;
}