Add VelopackFlow repository

This commit is contained in:
Caelan Sayler
2024-03-10 19:34:28 +00:00
parent 1c2c112ee3
commit 612e54736f
3 changed files with 64 additions and 2 deletions

View File

@@ -0,0 +1,62 @@
using Microsoft.Extensions.Logging;
using Velopack.NuGet;
using Velopack.Packaging;
using Velopack.Packaging.Flow;
using Velopack.Sources;
namespace Velopack.Deployment;
public class VelopackFlowDownloadOptions : RepositoryOptions
{
public string Version { get; set; }
}
public class VelopackFlowUploadOptions : VelopackFlowDownloadOptions
{
}
public class VelopackFlowRepository : SourceRepository<VelopackFlowDownloadOptions, VelopackFlowUpdateSource>, IRepositoryCanUpload<VelopackFlowUploadOptions>
{
private static HttpClient Client { get; } = new HttpClient {
BaseAddress = new Uri(VelopackServiceOptions.DefaultBaseUrl)
};
public VelopackFlowRepository(ILogger logger)
: base(logger)
{ }
public override VelopackFlowUpdateSource CreateSource(VelopackFlowDownloadOptions options)
{
return new VelopackFlowUpdateSource();
}
public async Task UploadMissingAssetsAsync(VelopackFlowUploadOptions options)
{
var helper = new ReleaseEntryHelper(options.ReleaseDir.FullName, options.Channel, Log);
var latest = helper.GetLatestAssets().ToList();
Log.Info($"Preparing to upload {latest.Count} assets to Velopack");
foreach (var asset in latest) {
var latestPath = Path.Combine(options.ReleaseDir.FullName, asset.FileName);
ZipPackage zipPackage = new(latestPath);
var semVer = options.Version ?? asset.Version.ToString();
using var formData = new MultipartFormDataContent
{
{ new StringContent(options.Channel), "Channel" },
};
using var fileStream = File.OpenRead(latestPath);
using var fileContent = new StreamContent(fileStream);
formData.Add(fileContent, "File", asset.FileName);
var response = await Client.PostAsync("api/v1/upload", formData);
response.EnsureSuccessStatusCode();
Log.Info($" Uploaded {asset.FileName} to Velopack");
}
}
}

View File

@@ -28,7 +28,7 @@ public static partial class OptionMapper
public static partial DeltaPatchOptions ToOptions(this DeltaPatchCommand cmd);
public static partial LoginOptions ToOptions(this LoginCommand cmd);
public static partial LogoutOptions ToOptions(this LogoutCommand cmd);
public static partial VelopackUploadOptions ToOptions(this VelopackPublishCommand cmd);
public static partial VelopackFlowUploadOptions ToOptions(this VelopackPublishCommand cmd);
private static DirectoryInfo StringToDirectoryInfo(string t)
{

View File

@@ -101,7 +101,7 @@ public class Program
rootCommand.AddCommand<LoginCommand, LoginCommandRunner, LoginOptions>(provider);
rootCommand.AddCommand<LogoutCommand, LogoutCommandRunner, LogoutOptions>(provider);
rootCommand.AddRepositoryUpload<VelopackPublishCommand, VelopackRepository, VelopackUploadOptions>(provider);
rootCommand.AddRepositoryUpload<VelopackPublishCommand, VelopackFlowRepository, VelopackFlowUploadOptions>(provider);
var cli = new CliConfiguration(rootCommand);
return await cli.InvokeAsync(args);