Batches
[Release 1.0.5-rc20-alpha7] deploying a batch abstraction
This commit is contained in:
parent
64d49c661d
commit
aeebf8bea9
10 changed files with 642 additions and 7 deletions
73
Yavsc.Server/Models/IT/SourceCode/GitBatch.cs
Normal file
73
Yavsc.Server/Models/IT/SourceCode/GitBatch.cs
Normal file
|
|
@ -0,0 +1,73 @@
|
|||
using System;
|
||||
using System.Diagnostics;
|
||||
using System.IO;
|
||||
using System.Threading.Tasks;
|
||||
using Yavsc.Abstract.Interfaces;
|
||||
|
||||
namespace Yavsc.Server.Models.IT.SourceCode
|
||||
{
|
||||
public abstract class GitBatch : Batch<GitRepositoryReference>
|
||||
{
|
||||
|
||||
public GitBatch()
|
||||
{
|
||||
// git -c color.status=always status
|
||||
// | ~/bin/ansi2html.sh --bg=dark --palette=xterm > ../test.html
|
||||
|
||||
}
|
||||
|
||||
ProcessStartInfo CreateAnsiFilter
|
||||
(GitRepositoryReference input, params string [] args )
|
||||
{
|
||||
|
||||
var pStart = new ProcessStartInfo("git", string.Join(" ", args));
|
||||
if (args[0]=="clone")
|
||||
pStart.WorkingDirectory = WorkingDir;
|
||||
else
|
||||
pStart.WorkingDirectory = Path.Combine( WorkingDir, input.Path);
|
||||
return pStart;
|
||||
}
|
||||
|
||||
protected ProcessStartInfo CreateProcessStart(string args)
|
||||
{
|
||||
return new ProcessStartInfo("git", args)
|
||||
{ WorkingDirectory = WorkingDir };
|
||||
}
|
||||
bool Clone (GitRepositoryReference input)
|
||||
|
||||
{
|
||||
var pStart = CreateProcessStart( $"clone -b {input.Branch} {input.Url} {input.Path}");
|
||||
pStart.WorkingDirectory = WorkingDir;
|
||||
var proc = Process.Start(pStart);
|
||||
proc.WaitForExit();
|
||||
return proc.ExitCode == 0;
|
||||
}
|
||||
bool Pull (GitRepositoryReference input)
|
||||
{
|
||||
HtmlLogPath = Path.Combine( WorkingDir, "git.log");
|
||||
var pStart = new ProcessStartInfo("git", "pull");
|
||||
|
||||
pStart.WorkingDirectory = Path.Combine(WorkingDir,input.Path);
|
||||
pStart.RedirectStandardOutput = true;
|
||||
|
||||
HtmlLogPath = Path.Combine( WorkingDir, "git.log");
|
||||
|
||||
using (var mem = new MemoryStream())
|
||||
{
|
||||
using (var memWriter = new StreamWriter(mem))
|
||||
{
|
||||
var proc = Process.Start(pStart);
|
||||
using (var memReader = new StreamReader(mem)) {
|
||||
while (!proc.StandardOutput.EndOfStream)
|
||||
memWriter.Write(proc.StandardOutput.Read());
|
||||
proc.WaitForExit();
|
||||
|
||||
}
|
||||
bool ok = proc.ExitCode==0;
|
||||
ResultHandler(ok);
|
||||
return ok;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue