static void Run(CLOptions opts) { var version = ReadVersion(opts); Console.WriteLine(); Console.WriteLine("File: {0}", opts.FromFile); Console.WriteLine("Found Version: {0}", version); Console.WriteLine(); Console.Out.WriteLine($"::set-output name={opts.OutputVariable}::{version}"); if (!string.IsNullOrWhiteSpace(opts.EnvironmentFile)) { Directory.CreateDirectory(Path.GetDirectoryName(opts.EnvironmentFile)); File.AppendAllLines(opts.EnvironmentFile, new string[] { $"{opts.OutputVariable}={version}" }); } }
static Version ReadVersion(CLOptions opts) { try { var doc = XDocument.Load(opts.FromFile); return(new Version(doc.Descendants("Version").First().Value)); } catch { if (opts.ZeroOnFail) { return(new Version()); } throw; } }