packaging

This commit is contained in:
Paul Schneider 2019-06-24 14:30:47 +01:00
commit 36722d338b
14 changed files with 61 additions and 21 deletions

View file

@ -1,49 +0,0 @@
using System.ComponentModel.DataAnnotations;
using Newtonsoft.Json;
public class CiBuildSettings
{
/// <summary>
/// The global process environment variables
/// </summary>
/// <value></value>
[JsonPropertyAttribute("env")]
public string[] Environment { get; set; }
/// <summary>
/// The required building command.
/// </summary>
/// <value></value>
[Required]
[JsonPropertyAttribute("build")]
public CommandPipe Build { get; set; }
/// <summary>
/// A preparing command.
/// It is optional, but when specified,
/// must end ok in order to launch the build.
/// </summary>
/// <value></value>
[JsonPropertyAttribute("prepare")]
public CommandPipe Prepare { get; set; }
/// <summary>
/// A post-production command,
/// for an example, some publishing,
/// push in prod env ...
/// only fired on successful build.
/// </summary>
/// <value></value>
[JsonPropertyAttribute("post_build")]
public CommandPipe PostBuild { get; set; }
/// <summary>
/// Additional emails, as dest of notifications
/// </summary>
/// <value></value>
[JsonPropertyAttribute("emails")]
public string[] Emails { get; set; }
}

View file

@ -1,36 +0,0 @@
using System.ComponentModel.DataAnnotations;
using System.Diagnostics;
using Newtonsoft.Json;
/// <summary>
/// A command specification (a system command),
/// in order to reference some trusted server-side process
/// </summary>
public class Command
{
[Required]
[JsonPropertyAttribute("path")]
public string Path { get; set; }
[JsonPropertyAttribute("args")]
public string[] Args { get; set; }
/// <summary>
/// Specific variables for this process
/// </summary>
/// <value></value>
[JsonPropertyAttribute("env")]
public string[] Environment { get; set; }
public virtual Process Start(string workingDir=null, bool redirectInput=false, bool redirectOutput=false)
{
var procStart = new ProcessStartInfo(Path, string.Join(" ",Args));
procStart.WorkingDirectory = workingDir;
procStart.UseShellExecute = false;
procStart.RedirectStandardInput = true;
procStart.RedirectStandardOutput = true;
procStart.RedirectStandardError = false;
return Process.Start(procStart);
}
}

View file

@ -1,64 +0,0 @@
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Diagnostics;
using System.Threading.Tasks;
using Newtonsoft.Json;
public class CommandPipe
{
[JsonPropertyAttribute("pipe")]
public Command[] Pipe { get; set; }
[JsonPropertyAttribute("working_dir")]
public string WorkingDir { get; set; }
public virtual int Run()
{
Process latest = null;
Queue<Process> runQueue = new Queue<Process>();
Queue<Task> joints = new Queue<Task>();
if (Pipe.Length == 0) return -1;
if (Pipe.Length == 1)
{
latest = Pipe[0].Start();
latest.WaitForExit();
return latest.ExitCode;
}
for (int i = 0; i < Pipe.Length; i++)
{
Process newProcess = null;
var cmd = Pipe[i];
bool isNotLast = (i + 1) >= Pipe.Length;
if (latest != null) // i.e. isNotFirst
{
newProcess = cmd.Start(WorkingDir, true, isNotLast);
var jt = Task.Run(async () =>
{
while (!latest.HasExited && !newProcess.HasExited)
{
string line = await latest.StandardOutput.ReadLineAsync();
if (line != null)
await newProcess.StandardInput.WriteLineAsync(line);
}
});
joints.Enqueue(jt);
}
else
{
newProcess = cmd.Start(WorkingDir, false, isNotLast);
Task ending = Task.Run(() => { latest.WaitForExit(); });
joints.Enqueue(ending);
}
latest = newProcess;
runQueue.Enqueue(latest);
}
while (runQueue.Count > 0)
(latest = runQueue.Dequeue()).WaitForExit();
return latest.ExitCode;
}
}