using System; using System.IO; using Jint.Native.Function; using ln.build.repositories; using ln.logging; namespace ln.build.pipeline { public class ReleaseCommand : StageCommand { public string[] Arguments { get; } public ReleaseCommand(string args) :base("RELEASE") { Arguments = args.Split(); } public override void Run(Stage stage) { if (stage.CommandEnvironment.Get("REPO_EVENT","").Equals("release")) { Repository repository = stage.CommandEnvironment.CIJob?.Repository; if (repository != null) { Release release = repository.GetRelease(int.Parse(stage.CommandEnvironment.Get("RELEASE_ID"))); foreach (string arg in Arguments) { string localPath, remoteFileName; int ie = arg.IndexOf('='); if (ie == -1) { localPath = Path.Combine(stage.CommandEnvironment.WorkingDirectory, arg); remoteFileName = Path.GetFileName(arg); } else { localPath = Path.Combine(stage.CommandEnvironment.WorkingDirectory, arg.Substring(0, ie)); remoteFileName = arg.Substring(ie + 1); } stage.CommandEnvironment.Logger.Log(LogLevel.INFO, "Adding {0} to release as {1}", localPath, remoteFileName); release.AddAttachement(localPath, remoteFileName); } } else { stage.CommandEnvironment.Logger.Log(LogLevel.ERROR, "RELEASE: no repository interface found!"); throw new Exception("Respository needed!"); } } else { stage.CommandEnvironment.Logger.Log(LogLevel.INFO, "RELEASE: build is no release build. Ignoring."); } } } }