forked from chuongmep/CadPythonShell
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBuild.Installer.cs
More file actions
78 lines (73 loc) · 3.08 KB
/
Build.Installer.cs
File metadata and controls
78 lines (73 loc) · 3.08 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
using JetBrains.Annotations;
using Nuke.Common;
using Nuke.Common.Git;
using Serilog;
using System.Diagnostics;
using System.Text;
using System.Text.RegularExpressions;
internal partial class Build
{
private readonly Regex StreamRegex = new("'(.+?)'", RegexOptions.Compiled);
private Target CreateInstaller => _ => _
.TriggeredBy(Compile)
.OnlyWhenStatic(() => IsLocalBuild || GitRepository.IsOnMainOrMasterBranch())
.Executes(() =>
{
Console.WriteLine("Start Create Installer");
var installerProject = BuilderExtensions.GetProject(Solution, InstallerProject);
Console.WriteLine($"Installer Project :{installerProject.Path}");
var buildDirectories = GetBuildDirectories();
var configurations = GetConfigurations(InstallerConfiguration);
foreach (var directoryGroup in buildDirectories)
{
Console.WriteLine($"Directory Group :{directoryGroup.Key}");
var directories = directoryGroup.ToList();
var exeArguments = BuildExeArguments(directories.Select(info => info.FullName).ToList());
var exeFile = installerProject.GetExecutableFile(configurations, directories);
Console.WriteLine($"Path Execute create installer: {exeFile}");
if (string.IsNullOrEmpty(exeFile))
{
Log.Warning("No installer executable was found for these packages:\n {Directories}", string.Join("\n", directories));
continue;
}
var proc = new Process();
proc.StartInfo.FileName = exeFile;
proc.StartInfo.Arguments = exeArguments;
proc.StartInfo.RedirectStandardOutput = true;
proc.Start();
while (!proc.StandardOutput.EndOfStream) ParseProcessOutput(proc.StandardOutput.ReadLine());
proc.WaitForExit();
if (proc.ExitCode != 0) throw new Exception("The installer creation failed.");
}
});
private void ParseProcessOutput([CanBeNull] string value)
{
if (value is null) return;
var matches = StreamRegex.Matches(value);
if (matches.Count > 0)
{
var parameters = matches.Select(match => match.Value
.Substring(1, match.Value.Length - 2))
.Cast<object>()
.ToArray();
var line = StreamRegex.Replace(value, match => $"{{Parameter{match.Index}}}");
Log.Information(line, parameters);
}
else
{
Log.Debug(value);
}
}
private static string BuildExeArguments(IReadOnlyList<string> args)
{
var argumentBuilder = new StringBuilder();
for (var i = 0; i < args.Count; i++)
{
if (i > 0) argumentBuilder.Append(' ');
var value = args[i];
if (value.Contains(' ')) value = $"\"{value}\"";
argumentBuilder.Append(value);
}
return argumentBuilder.ToString();
}
}