aboutsummaryrefslogtreecommitdiff
path: root/src/Commands/PublishCommand.cs
diff options
context:
space:
mode:
authorLibravatar vnugent <public@vaughnnugent.com>2024-09-06 20:50:06 -0400
committerLibravatar vnugent <public@vaughnnugent.com>2024-09-06 20:50:06 -0400
commit7f1482c5d77b1b5f7e369ade925d2351d7623fa1 (patch)
treec99a0c8a0137e940492892977ef1e4f6f42b6d52 /src/Commands/PublishCommand.cs
parent79d824cfb0e0cc9ff4fab0e0c546a83c0edaae1c (diff)
cleanup and add fluent-ftp as an publishing location
Diffstat (limited to 'src/Commands/PublishCommand.cs')
-rw-r--r--src/Commands/PublishCommand.cs97
1 files changed, 79 insertions, 18 deletions
diff --git a/src/Commands/PublishCommand.cs b/src/Commands/PublishCommand.cs
index 4179f86..33a7329 100644
--- a/src/Commands/PublishCommand.cs
+++ b/src/Commands/PublishCommand.cs
@@ -2,20 +2,25 @@
using System;
using System.Linq;
using System.Threading.Tasks;
+using System.Collections.Generic;
using Typin.Console;
using Typin.Attributes;
using VNLib.Tools.Build.Executor.Model;
using VNLib.Tools.Build.Executor.Constants;
+using VNLib.Tools.Build.Executor.Publishing;
namespace VNLib.Tools.Build.Executor.Commands
{
[Command("publish", Description = "Runs publishig build steps on a completed build")]
public sealed class PublishCommand(BuildPipeline pipeline, ConfigManager bm) : BaseCommand(pipeline, bm)
{
- [CommandOption("upload-path", 'p', Description = "The path to upload the build artifacts")]
- public string? UploadPath { get; set; }
+ [CommandOption("minio", Description = "The path to upload the build artifacts")]
+ public string? MinioPath { get; set; }
+
+ [CommandOption("ftp", Description = "The FTP server address to upload the build artifacts. Enables FTP mode over s3")]
+ public string? FtpServerAddress { get; set; }
[CommandOption("sign", 's', Description = "Enables gpg signing of build artifacts")]
public bool Sign { get; set; } = false;
@@ -35,46 +40,102 @@ namespace VNLib.Tools.Build.Executor.Commands
public override async ValueTask ExecStepsAsync(IConsole console)
{
//Specify custom output dir
- (base.Config.Index as Dirs)!.OutputDir = BuildDirs.GetOrCreateDir(Constants.Config.OUTPUT_DIR, CustomOutDir);
+ (Config.Index as Dirs)!.OutputDir = BuildDirs.GetOrCreateDir(Constants.Config.OUTPUT_DIR, CustomOutDir);
- IUploadManager? uploads = MinioUploadManager.Create(UploadPath);
+ IUploadManager uploads = GetUploadManager(console);
IFeedManager? feed = Feeds.FirstOrDefault();
//Optional gpg signer for signing published artifacts
BuildPublisher pub = new(Config, new GpgSigner(Sign, GpgKey));
- console.WithForegroundColor(ConsoleColor.DarkGreen, static o => o.Output.WriteLine("Publishing modules"));
+ console.WithForegroundColor(
+ ConsoleColor.DarkGreen,
+ static o => o.Output.WriteLine("Publishing modules")
+ );
//Run publish steps
- await pipeline.OnPublishingAsync().ConfigureAwait(false);
+ await pipeline.OnPublishingAsync()
+ .ConfigureAwait(false);
- console.WithForegroundColor(ConsoleColor.DarkGreen, static o => o.Output.WriteLine("Preparing module output for upload"));
+ console.WithForegroundColor(
+ ConsoleColor.DarkGreen,
+ static o => o.Output.WriteLine("Preparing module output for upload")
+ );
//Prepare the output
- await pipeline.PrepareOutputAsync(pub).ConfigureAwait(false);
-
- if(uploads is null)
- {
- console.WithForegroundColor(ConsoleColor.DarkYellow, static o => o.Output.WriteLine("No upload path specified. Skipping upload"));
- console.WithForegroundColor(ConsoleColor.Green, static o => o.Output.WriteLine("Upload build complete"));
- return;
- }
+ await pipeline.PrepareOutputAsync(pub)
+ .ConfigureAwait(false);
//Run upload
- await pipeline.ManualUpload(pub, uploads).ConfigureAwait(false);
+ await pipeline.ManualUpload(pub, uploads)
+ .ConfigureAwait(false);
//Publish feeds
if (feed is not null)
{
- console.WithForegroundColor(ConsoleColor.DarkGreen, static o => o.Output.WriteLine("Uploading feeds..."));
+ console.WithForegroundColor(
+ ConsoleColor.DarkGreen,
+ static o => o.Output.WriteLine("Uploading feeds...")
+ );
//Exec feed upload
await uploads.UploadDirectoryAsync(feed.FeedOutputDir);
}
- console.WithForegroundColor(ConsoleColor.Green, static o => o.Output.WriteLine("Upload build complete"));
+ console.WithForegroundColor(
+ ConsoleColor.Green,
+ static o => o.Output.WriteLine("Upload build complete")
+ );
}
public override IFeedManager[] Feeds => SleetPath is null ? [] : [SleetFeedManager.GetSleetFeed(SleetPath)];
+
+ private MultiUploadManager GetUploadManager(IConsole console)
+ {
+ try
+ {
+ IUploadManager[] uploadMan = [];
+
+ if (!string.IsNullOrWhiteSpace(MinioPath))
+ {
+ console.Output.WriteLine("Creating Minio publisher");
+
+ uploadMan = [MinioUploadManager.Create(MinioPath), ..uploadMan];
+ }
+
+ if (!string.IsNullOrWhiteSpace(FtpServerAddress))
+ {
+ console.Output.WriteLine("Using FTP publisher");
+
+ uploadMan = [FtpUploadManager.Create(FtpServerAddress), .. uploadMan];
+ }
+
+ if(uploadMan.Length == 0)
+ {
+ console.WithForegroundColor(
+ ConsoleColor.DarkYellow,
+ static o => o.Output.WriteLine("No upload manager specified, output will be skipped")
+ );
+ }
+
+ return new MultiUploadManager(uploadMan);
+ }
+ catch(UriFormatException urie)
+ {
+ throw new BuildFailedException("Invalid server address", urie);
+ }
+ }
+
+ private sealed class MultiUploadManager(params IUploadManager[] managers) : IUploadManager
+ {
+ private readonly IUploadManager[] _managers = managers;
+
+ public async Task UploadDirectoryAsync(string path)
+ {
+ IEnumerable<Task> tasks = _managers.Select(m => m.UploadDirectoryAsync(path));
+
+ await Task.WhenAll(tasks);
+ }
+ }
}
} \ No newline at end of file