99 lines
3.0 KiB
C#
99 lines
3.0 KiB
C#
|
|
using System;
|
|
using System.IO;
|
|
using System.Reflection.Metadata.Ecma335;
|
|
using System.Runtime.Serialization.Formatters;
|
|
using System.Text;
|
|
using System.Text.RegularExpressions;
|
|
using LibGit2Sharp.Handlers;
|
|
using ln.logging;
|
|
using ln.type;
|
|
|
|
namespace ln.build
|
|
{
|
|
|
|
public class DotNetPipeLine : PipeLine
|
|
{
|
|
static Regex regexPackages = new Regex(".*(Successfully created package '(.*)').*");
|
|
|
|
public DotNetPipeLine()
|
|
{
|
|
AddStep(new RestoreStep());
|
|
AddStep(new CleanStep());
|
|
|
|
BuildStep buildStep = new BuildStep();
|
|
buildStep.OnCommandExited += FilterPackageFilenames;
|
|
AddStep(buildStep);
|
|
|
|
AddStep(new TestStep());
|
|
|
|
PackStep packStep = new PackStep();
|
|
packStep.OnCommandExited += FilterPackageFilenames;
|
|
AddStep(packStep);
|
|
|
|
AddStep(new PublishStep());
|
|
}
|
|
|
|
void FilterPackageFilenames(CommandStep commandStep, CIJob job, int exitCode)
|
|
{
|
|
Stream outStream = job.GetLogStream(commandStep.DefaultLogFileName);
|
|
outStream.Position = 0;
|
|
|
|
job.Logger.Log(LogLevel.INFO,"filterPackageFilenames(): started");
|
|
|
|
String consoleOutput = Encoding.UTF8.GetString(outStream.ReadToEnd());
|
|
|
|
MatchCollection matches = regexPackages.Matches(consoleOutput);
|
|
foreach (Match match in matches)
|
|
{
|
|
Logging.Log(LogLevel.INFO,"filterPackageFilenames(): {0}", match.Groups[2].Value);
|
|
job.ExtendVariable("DOTNET_PACKAGES", match.Groups[2].Value);
|
|
}
|
|
}
|
|
|
|
|
|
class CleanStep : CommandStep
|
|
{
|
|
public CleanStep():base("clean", "dotnet","clean"){ }
|
|
}
|
|
class RestoreStep : CommandStep
|
|
{
|
|
public RestoreStep():base("restore", "dotnet","restore"){ }
|
|
}
|
|
class TestStep : CommandStep
|
|
{
|
|
public TestStep():base("test", "dotnet","test"){ }
|
|
}
|
|
class BuildStep : CommandStep
|
|
{
|
|
public BuildStep():base("build", "dotnet","build"){ }
|
|
}
|
|
class PackStep : CommandStep
|
|
{
|
|
public PackStep():base("pack", "dotnet","pack"){ }
|
|
}
|
|
class PublishStep : CommandStep
|
|
{
|
|
public PublishStep():base("push", "dotnet","nuget", "push", "<filename>", "-s", "<source>", "-k", "<apikey>"){ }
|
|
|
|
public override int Run(CIJob job)
|
|
{
|
|
bool success = true;
|
|
|
|
CommandRunner.Arguments[4] = "http://nuget.l--n.de/nuget/l--n/v3/index.json";
|
|
CommandRunner.Arguments[6] = "3yAJPMxcaEhb_HP62dxK";
|
|
|
|
foreach (string package in job.GetVariable("DOTNET_PACKAGES","").Split(':',StringSplitOptions.RemoveEmptyEntries))
|
|
{
|
|
CommandRunner.Arguments[2] = package;
|
|
if (base.Run(job) != 0)
|
|
success = false;
|
|
}
|
|
return success ? 0 : -1;
|
|
}
|
|
}
|
|
|
|
|
|
}
|
|
|
|
} |