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