// Copyright Epic Games, Inc. All Rights Reserved. using System.Collections.Generic; using System.Threading.Tasks; using System.Xml; using EpicGames.Core; namespace AutomationTool.Tasks { /// /// Parameters for a Git task /// public class GitTaskParameters { /// /// Git command line arguments /// [TaskParameter(Optional = true)] public string Arguments { get; set; } /// /// Base directory for running the command /// [TaskParameter(Optional = true)] public string BaseDir { get; set; } /// /// The minimum exit code, which is treated as an error. /// [TaskParameter(Optional = true)] public int ErrorLevel { get; set; } = 1; } /// /// Spawns Git and waits for it to complete. /// [TaskElement("Git", typeof(GitTaskParameters))] public class GitTask : BgTaskImpl { readonly GitTaskParameters _parameters; /// /// Construct a Git task /// /// Parameters for the task public GitTask(GitTaskParameters parameters) { _parameters = parameters; } /// /// ExecuteAsync the task. /// /// Information about the current job /// Set of build products produced by this node. /// Mapping from tag names to the set of files they include public override Task ExecuteAsync(JobContext job, HashSet buildProducts, Dictionary> tagNameToFileSet) { FileReference toolFile = CommandUtils.FindToolInPath("git"); if (toolFile == null) { throw new AutomationException("Unable to find path to Git. Check you have it installed, and it is on your PATH."); } IProcessResult result = CommandUtils.Run(toolFile.FullName, _parameters.Arguments, WorkingDir: _parameters.BaseDir); if (result.ExitCode < 0 || result.ExitCode >= _parameters.ErrorLevel) { throw new AutomationException("Git terminated with an exit code indicating an error ({0})", result.ExitCode); } return Task.CompletedTask; } /// /// Output this task out to an XML writer. /// public override void Write(XmlWriter writer) { Write(writer, _parameters); } /// /// Find all the tags which are used as inputs to this task /// /// The tag names which are read by this task public override IEnumerable FindConsumedTagNames() { yield break; } /// /// Find all the tags which are modified by this task /// /// The tag names which are modified by this task public override IEnumerable FindProducedTagNames() { yield break; } } }