-
Notifications
You must be signed in to change notification settings - Fork 10
/
build.cake
128 lines (107 loc) · 3.68 KB
/
build.cake
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
#addin "Cake.FileHelpers"
/*
This should be a simple file. It is not because the new .Net Core
tooling does not support .Net 3.5
*/
//////////////////////////////////////////////////////////////////////
// ARGUMENTS
//////////////////////////////////////////////////////////////////////
var target = Argument("target", "Default");
var configuration = Argument("configuration", "Release");
var version = string.Format("0.7.{0}.{1}"
, (int)((DateTime.UtcNow - new DateTime(2000, 1, 1, 0, 0, 0, DateTimeKind.Utc)).TotalDays)
, (int)((DateTime.UtcNow - DateTime.UtcNow.Date).TotalSeconds / 2));
private string[] MergeCompileLines(string[] file, string[] newCompiles)
{
var first = int.MaxValue;
var last = int.MinValue;
for (var i = 0; i < file.Length; i++)
{
if (file[i].Trim().StartsWith("<Compile Include="))
{
first = Math.Min(first, i);
last = Math.Max(last, i);
}
}
return file.Take(first)
.Concat(newCompiles)
.Concat(file.Skip(last + 1))
.ToArray();
}
//////////////////////////////////////////////////////////////////////
// TASKS
//////////////////////////////////////////////////////////////////////
Task("Clean")
.Does(() =>
{
CleanDirectory(Directory("./src/BracketPipe/bin/" + configuration + "/"));
CleanDirectory(Directory("./publish/BracketPipe/lib/"));
CleanDirectory(Directory("./artifacts/"));
});
Task("Patch-Version")
.IsDependentOn("Clean")
.Does(() =>
{
CreateAssemblyInfo("./src/BracketPipe/AssemblyInfo.Version.cs"
, new AssemblyInfoSettings {
Version = version,
FileVersion = version
}
);
});
Task("Patch-Project-Files")
.IsDependentOn("Patch-Version")
.Does(() =>
{
var compileLines = FileReadLines("./src/BracketPipe/BracketPipe.csproj")
.Where(l => l.Trim().StartsWith("<Compile Include="))
.ToArray();
var newLines = MergeCompileLines(FileReadLines("./src/BracketPipe/BracketPipe.Net35.csproj"), compileLines);
FileWriteLines("./src/BracketPipe/BracketPipe.Net35.csproj", newLines);
});
Task("Restore-NuGet-Packages")
.IsDependentOn("Patch-Project-Files")
.Does(() =>
{
DeleteFiles("./**/project.json");
DeleteFiles("./**/project.lock.json");
DeleteFiles("./**/global.json");
NuGetRestore("./src/BracketPipe/BracketPipe.Net35.csproj");
DotNetCoreRestore("./src/BracketPipe/BracketPipe.NetCore.csproj");
});
Task("Build")
.IsDependentOn("Restore-NuGet-Packages")
.Does(() =>
{
DotNetBuild("./src/BracketPipe/BracketPipe.Net35.csproj", settings =>
settings.SetConfiguration(configuration));
DotNetCoreBuild("./src/BracketPipe/BracketPipe.NetCore.csproj", new DotNetCoreBuildSettings
{
Configuration = configuration
});
CopyFiles("./src/BracketPipe/bin/" + configuration + "/**/BracketPipe.*", "./publish/BracketPipe/lib/", true);
var files = GetFiles("./publish/BracketPipe/lib/**/*")
.Where(f => !f.ToString().EndsWith("BracketPipe.dll", StringComparison.OrdinalIgnoreCase)
&& !f.ToString().EndsWith("BracketPipe.xml", StringComparison.OrdinalIgnoreCase));
foreach (var file in files)
DeleteFile(file);
});
Task("NuGet-Pack")
.IsDependentOn("Build")
.Does(() =>
{
var nuGetPackSettings = new NuGetPackSettings {
Version = version,
OutputDirectory = "./artifacts/"
};
NuGetPack("./publish/BracketPipe/BracketPipe.nuspec", nuGetPackSettings);
});
//////////////////////////////////////////////////////////////////////
// TASK TARGETS
//////////////////////////////////////////////////////////////////////
Task("Default")
.IsDependentOn("NuGet-Pack");
//////////////////////////////////////////////////////////////////////
// EXECUTION
//////////////////////////////////////////////////////////////////////
RunTarget(target);