-
Notifications
You must be signed in to change notification settings - Fork 146
/
build.cake
150 lines (123 loc) · 4.51 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
#tool nuget:?package=GitVersion.CommandLine&version=5.7.0
using System.Text.RegularExpressions;
//////////////////////////////////////////////////////////////////////
// ARGUMENTS
//////////////////////////////////////////////////////////////////////
var target = Argument("target", "Default");
var configuration = Argument("configuration", "Release");
var pushPackages = Argument("PushPackages", "false") == "true";
bool isPrerelease = false;
GitVersion versionInfo = null;
var projectsToBuild = new string[]{
"./src/Cofoundry.Core/Cofoundry.Core.csproj",
"./src/Cofoundry.Domain/Cofoundry.Domain.csproj",
"./src/Cofoundry.Web/Cofoundry.Web.csproj",
"./src/Cofoundry.Web.Admin/Cofoundry.Web.Admin.csproj"
};
//////////////////////////////////////////////////////////////////////
// PREPARATION
//////////////////////////////////////////////////////////////////////
//GitVersion versionInfo = null;
var nugetPackageDir = Directory("./artifacts");
//////////////////////////////////////////////////////////////////////
// TASKS
//////////////////////////////////////////////////////////////////////
Task("Clean")
.Does(() =>
{
CleanDirectory(nugetPackageDir);
CleanDirectories("./src/**/bin/" + configuration);
CleanDirectories("./src/**/obj/" + configuration);
});
Task("Patch-Assembly-Version")
.IsDependentOn("Clean")
.Does(() =>
{
versionInfo = GitVersion(new GitVersionSettings{
UpdateAssemblyInfo = false
});
Information("Building version {0} of Cofoundry.", versionInfo.InformationalVersion);
isPrerelease = versionInfo.PreReleaseNumber.HasValue;
// Patch the version number so it's picked up when dependent projects are references
// as nuget dependencies. Can't find a better way to do this.
// Also this needs to run before DotNetCoreRestore for some reason (cached?)
var file = MakeAbsolute(File("./src/Directory.Build.props"));
var xml = System.IO.File.ReadAllText(file.FullPath, Encoding.UTF8);
xml = Regex.Replace(xml, @"(<Version>)(.+)(<\/Version>)", "${1}" + versionInfo.NuGetVersion +"${3}");
System.IO.File.WriteAllText(file.FullPath, xml, Encoding.UTF8);
});
Task("Restore-NuGet-Packages")
.IsDependentOn("Patch-Assembly-Version")
.Does(() =>
{
foreach (var projectToBuild in projectsToBuild)
{
DotNetCoreRestore(projectToBuild);
}
});
Task("Build")
.IsDependentOn("Restore-NuGet-Packages")
.Does(() =>
{
var settings = new DotNetCoreBuildSettings
{
Configuration = configuration,
ArgumentCustomization = args => args
.Append("/p:NuGetVersion=" + versionInfo.NuGetVersion)
.Append("/p:AssemblyVersion=" + versionInfo.AssemblySemVer)
.Append("/p:FileVersion=" + versionInfo.MajorMinorPatch + ".0")
.Append("/p:InformationalVersion=" + versionInfo.InformationalVersion)
.Append("/p:Copyright=" + "\"Copyright © Cofoundry Technologies Ltd " + DateTime.Now.Year + "\"")
};
foreach (var projectToBuild in projectsToBuild)
{
DotNetCoreBuild(projectToBuild, settings);
}
});
Task("Pack")
.IsDependentOn("Build")
.Does(() =>
{
var settings = new DotNetCorePackSettings
{
Configuration = configuration,
OutputDirectory = "./artifacts/",
NoBuild = true
};
foreach (var projectToBuild in projectsToBuild)
{
DotNetCorePack(projectToBuild, settings);
}
});
Task("PushNuGetPackage")
.IsDependentOn("Pack")
.Does(() =>
{
var nugets = GetFiles("./artifacts/*.nupkg");
if (pushPackages)
{
Information("Pushing packages");
if (isPrerelease)
{
NuGetPush(nugets, new NuGetPushSettings {
Source = "https://www.myget.org/F/cofoundry/api/v2/package",
ApiKey = EnvironmentVariable("MYGET_API_KEY")
});
}
else
{
NuGetPush(nugets, new NuGetPushSettings {
Source = "https://nuget.org/",
ApiKey = EnvironmentVariable("NUGET_API_KEY")
});
}
}
});
//////////////////////////////////////////////////////////////////////
// TASK TARGETS
//////////////////////////////////////////////////////////////////////
Task("Default").IsDependentOn("PushNuGetPackage");
//////////////////////////////////////////////////////////////////////
// EXECUTION
//////////////////////////////////////////////////////////////////////
RunTarget(target);