-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathbuild.cake
155 lines (121 loc) · 3.78 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
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
using System.Text.RegularExpressions;
// ARGUMENTS
var target = Argument("target", "Default");
var configuration = Argument("configuration", "Release");
var source = Argument<string>("source", null);
var apiKey = Argument<string>("apikey", null);
var version = Argument<string>("targetversion", null);
var output = Directory("build");
var outputNuGet = output + Directory("nuget");
Task("Clean")
.Does(() =>
{
CleanDirectories(new DirectoryPath[] {
output,
outputNuGet
});
CleanDirectories("./src/**/" + configuration);
});
// TASKS
Task("Publish")
.IsDependentOn("Run-Tests")
.IsDependentOn("Prepare-Release")
.IsDependentOn("Publish-NuGet");
Task("Publish-Local")
.IsDependentOn("Run-Tests")
.IsDependentOn("Update-Version")
.IsDependentOn("Package-Nuget");
Task("Restore-Packages")
.IsDependentOn("Clean")
.Does(() =>
{
NuGetRestore("./EsiNet.sln");
});
Task("Build")
.IsDependentOn("Restore-Packages")
.Does(() =>
{
MSBuild("./EsiNet.sln", settings =>
settings.SetConfiguration(configuration));
});
Task("Run-Tests")
.IsDependentOn("Build")
.Does(() =>
{
StartProcess("dotnet", new ProcessSettings {
Arguments = "test ./src/Tests/Tests.csproj"
});
});
Task("Package-NuGet")
.IsDependentOn("Build")
.Does(() =>
{
foreach(var project in GetFiles("./src/**/EsiNet*.csproj"))
{
Information("Packaging " + project.GetFilename().FullPath);
var content = System.IO.File.ReadAllText(project.FullPath, Encoding.UTF8);
DotNetCorePack(project.GetDirectory().FullPath, new DotNetCorePackSettings {
Configuration = configuration,
OutputDirectory = outputNuGet
});
}
});
Task("Publish-NuGet")
.IsDependentOn("Package-Nuget")
.Does(() =>
{
if(string.IsNullOrWhiteSpace(apiKey))
{
throw new CakeException("No NuGet API key provided. You need to pass in --apikey=\"xyz\"");
}
var packages =
GetFiles(outputNuGet.Path.FullPath + "/*.nupkg") -
GetFiles(outputNuGet.Path.FullPath + "/*.symbols.nupkg");
foreach(var package in packages)
{
NuGetPush(package, new NuGetPushSettings {
Source = source,
ApiKey = apiKey
});
}
});
Task("Prepare-Release")
.IsDependentOn("Update-Version")
.Does(() =>
{
// Add
var buildFile = MakeAbsolute(File("./src/Directory.Build.props"));
Git($"add {buildFile.FullPath}");
// Commit
Git($"commit -m \"Updated version to {version}\"");
// Tag
Git($"tag \"v{version}\"");
//Push
Git("push");
Git("push --tags");
void Git(string command)
{
StartProcess("git", new ProcessSettings {
Arguments = command
});
}
});
Task("Update-Version")
.Does(() =>
{
Information("Setting version to " + version);
if(string.IsNullOrWhiteSpace(version))
{
throw new CakeException("No version specified! You need to pass in -targetversion=\"x.y.z\"");
}
var buildFile = MakeAbsolute(File("./src/Directory.Build.props"));
Information("Updating version in " + buildFile.GetFilename().FullPath);
var content = System.IO.File.ReadAllText(buildFile.FullPath, Encoding.UTF8);
var versionRegex = new Regex(@"<Version>.+<\/Version>");
content = versionRegex.Replace(content, $"<Version>{version}</Version>");
System.IO.File.WriteAllText(buildFile.FullPath, content, Encoding.UTF8);
});
Task("Default")
.IsDependentOn("Run-Tests");
// EXECUTION
RunTarget(target);