forked from config-r/config-r
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.csx
131 lines (110 loc) · 4.57 KB
/
build.csx
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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
#load "packages/simple-targets-csx.6.0.0/contentFiles/csx/any/simple-targets.csx"
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using static SimpleTargets;
// version
var versionSuffix = Environment.GetEnvironmentVariable("VERSION_SUFFIX") ?? "-adhoc";
var buildNumber = Environment.GetEnvironmentVariable("BUILD_NUMBER") ?? "000000";
var buildNumberSuffix = versionSuffix == "" ? "" : "-build" + buildNumber;
var version = File.ReadAllText("src/CommonAssemblyInfo.cs")
.Split(new[] { "AssemblyInformationalVersion(\"" }, 2, StringSplitOptions.RemoveEmptyEntries)[1]
.Split('\"').First() + versionSuffix + buildNumberSuffix;
// locations
var solution = "./ConfigR.sln";
var logs = "./artifacts/logs";
var vswhere = "packages/vswhere.2.2.11/tools/vswhere.exe";
string msBuild;
var nuspecs = new[] { "./src/ConfigR/ConfigR.nuspec", "./src/ConfigR.Roslyn.CSharp/ConfigR.Roslyn.CSharp.nuspec", };
var output = "./artifacts/output";
var nuget = "./.nuget/v4.3.0/NuGet.exe";
var acceptanceTests = Path.GetFullPath("./tests/ConfigR.Tests.Acceptance.Roslyn.CSharp/bin/Release/ConfigR.Tests.Acceptance.Roslyn.CSharp.dll");
var xunit = "./packages/xunit.runner.console.2.1.0/tools/xunit.console.exe";
// targets
var targets = new TargetDictionary();
targets.Add("default", DependsOn("pack", "accept"));
targets.Add("logs", () => Directory.CreateDirectory(logs));
targets.Add("restore", () => Cmd(nuget, $"restore {solution}"));
targets.Add(
"find-msbuild",
() => msBuild = $"{ReadCmd(vswhere, "-latest -requires Microsoft.Component.MSBuild -property installationPath").Trim()}/MSBuild/15.0/Bin/MSBuild.exe");
targets.Add(
"build",
DependsOn("restore", "logs", "find-msbuild"),
() => Cmd(
msBuild,
$"{solution} /p:Configuration=Release /nologo /m /v:m /nr:false " +
$"/fl /flp:LogFile={logs}/msbuild.log;Verbosity=Detailed;PerformanceSummary"));
targets.Add("output", () => Directory.CreateDirectory(output));
targets.Add(
"pack",
DependsOn("build", "output"),
() =>
{
foreach (var nuspec in nuspecs)
{
var originalNuspec = $"{nuspec}.original";
File.Move(nuspec, originalNuspec);
var originalContent = File.ReadAllText(originalNuspec);
var content = originalContent.Replace("[0.0.0]", $"[{version}]");
File.WriteAllText(nuspec, content);
try
{
Cmd(nuget, $"pack {nuspec} -Version {version} -OutputDirectory {output} -NoPackageAnalysis");
}
finally
{
File.Delete(nuspec);
File.Move(originalNuspec, nuspec);
}
}
});
targets.Add(
"accept",
DependsOn("build"),
() => Cmd(
xunit, $"{acceptanceTests} -html {acceptanceTests}.TestResults.html -xml {acceptanceTests}.TestResults.xml"));
Run(Args, targets);
// helper
public static void Cmd(string fileName, string args)
{
using (var process = new Process())
{
process.StartInfo = new ProcessStartInfo { FileName = $"\"{fileName}\"", Arguments = args, UseShellExecute = false, };
Console.WriteLine($"Running '{process.StartInfo.FileName} {process.StartInfo.Arguments}'...");
process.Start();
process.WaitForExit();
if (process.ExitCode != 0)
{
throw new InvalidOperationException($"The command exited with code {process.ExitCode}.");
}
}
}
public static string ReadCmd(string fileName, string args)
{
var output = new StringBuilder();
using (var process = new Process())
{
process.StartInfo = new ProcessStartInfo {
FileName = $"\"{fileName}\"",
Arguments = args,
UseShellExecute = false,
RedirectStandardOutput = true,
RedirectStandardError = true,
};
process.OutputDataReceived += (sender, e) => output.AppendLine(e.Data);
process.ErrorDataReceived += (sender, e) => output.AppendLine(e.Data);
Console.WriteLine($"Running '{process.StartInfo.FileName} {process.StartInfo.Arguments}'...");
process.Start();
process.BeginOutputReadLine();
process.BeginErrorReadLine();
process.WaitForExit();
if (process.ExitCode != 0)
{
throw new InvalidOperationException($"The command exited with code {process.ExitCode}. {output.ToString()}");
}
}
return output.ToString();
}