mirror of
https://github.com/velopack/velopack.git
synced 2025-10-25 15:19:22 +00:00
Add VelopackFlow repository
This commit is contained in:
62
src/Velopack.Deployment/VelopackFlowRepository.cs
Normal file
62
src/Velopack.Deployment/VelopackFlowRepository.cs
Normal 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");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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)
|
||||
{
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user