1
0
mirror of https://github.com/bitwarden/mobile.git synced 2024-12-04 13:33:33 +01:00
bitwarden-mobile/store/google/Publisher/Program.cs

128 lines
4.1 KiB
C#
Raw Normal View History

2022-04-26 17:21:17 +02:00
using System;
2019-05-28 19:29:09 +02:00
using System.Collections.Generic;
using System.IO;
using System.Threading.Tasks;
2022-04-26 17:21:17 +02:00
using Google.Apis.AndroidPublisher.v3;
using Google.Apis.AndroidPublisher.v3.Data;
using Google.Apis.Auth.OAuth2;
using Google.Apis.Services;
2019-05-28 19:29:09 +02:00
namespace Bit.Publisher
{
public class Program
{
private const string Package = "com.x8bit.bitwarden";
private static string _aabFilePath;
2019-05-28 19:29:09 +02:00
private static string _credsFilePath;
private static string _track;
static void Main(string[] args)
{
if (args.Length < 3)
2019-05-28 19:29:09 +02:00
{
throw new ArgumentException("Not enough arguments.");
}
try
{
_credsFilePath = args[0];
_aabFilePath = args[1];
2019-05-28 19:29:09 +02:00
var track = args[2].Substring(0, 1).ToLower();
if (track == "a")
2019-05-28 19:29:09 +02:00
{
_track = "alpha";
}
else if (track == "b")
2019-05-28 19:29:09 +02:00
{
_track = "beta";
}
else if (track == "p")
2019-05-28 19:29:09 +02:00
{
_track = "production";
}
else if (track == "r")
2019-05-28 19:29:09 +02:00
{
_track = "rollout";
}
else if (track == "i")
2019-05-28 19:29:09 +02:00
{
_track = "internal";
}
new Program().Run().Wait();
}
catch (AggregateException ex)
2019-05-28 19:29:09 +02:00
{
foreach (var e in ex.InnerExceptions)
2019-05-28 19:29:09 +02:00
{
Console.WriteLine("ERROR: " + e.Message);
}
throw;
}
}
private async Task Run()
{
GoogleCredential creds;
using (var stream = new FileStream(_credsFilePath, FileMode.Open))
2019-05-28 19:29:09 +02:00
{
creds = GoogleCredential.FromStream(stream).CreateScoped(
AndroidPublisherService.Scope.Androidpublisher);
}
var service = new AndroidPublisherService(new BaseClientService.Initializer
{
HttpClientInitializer = creds
});
service.HttpClient.Timeout = TimeSpan.FromMinutes(3);
2019-05-28 19:29:09 +02:00
var editRequest = service.Edits.Insert(null, Package);
var edit = await editRequest.ExecuteAsync();
Console.WriteLine("Created edit with id {0}.", edit.Id);
Bundle aab = null;
using (var stream = new FileStream(_aabFilePath, FileMode.Open))
2019-05-28 19:29:09 +02:00
{
var uploadMedia = service.Edits.Bundles.Upload(Package, edit.Id, stream,
"application/octet-stream");
2019-05-28 19:29:09 +02:00
var progress = await uploadMedia.UploadAsync();
if (progress.Status == Google.Apis.Upload.UploadStatus.Completed)
2019-05-28 19:29:09 +02:00
{
aab = uploadMedia.ResponseBody;
2019-05-28 19:29:09 +02:00
}
else
{
if (progress.Exception != null)
{
Console.WriteLine("Upload exception: {0}", progress.Exception);
}
throw new Exception("Upload failed.");
2019-05-28 19:29:09 +02:00
}
}
Console.WriteLine("Version code {0} has been uploaded.", aab.VersionCode);
var trackRequest = service.Edits.Tracks.Update(new Track
{
TrackValue = _track,
Releases = new List<TrackRelease>
{
new TrackRelease { VersionCodes = new List<long?> { aab.VersionCode }, Status = "completed" }
}
}, Package, edit.Id, _track);
var updatedTrack = await trackRequest.ExecuteAsync();
Console.WriteLine("Track {0} has been updated.", updatedTrack.TrackValue);
var commitRequest = service.Edits.Commit(Package, edit.Id);
var commitEdit = await commitRequest.ExecuteAsync();
Console.WriteLine("App edit with id {0} has been comitted.", commitEdit.Id);
2019-05-28 19:29:09 +02:00
}
}
}