-
-
Notifications
You must be signed in to change notification settings - Fork 4
/
build.csx
159 lines (139 loc) · 5.3 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
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
//////////////////////////////////////////////////////////////////////
// DEPENDENCIES
//////////////////////////////////////////////////////////////////////
#r "nuget: Cake.Bridge, 0.0.21-alpha"
//////////////////////////////////////////////////////////////////////
// NAMESPACE IMPORTS
//////////////////////////////////////////////////////////////////////
using Cake.Common;
using Cake.Common.Build;
using Cake.Common.Diagnostics;
using Cake.Common.IO;
using Cake.Common.Tools.DotNet;
using Cake.Common.Tools.DotNet.Build;
using Cake.Common.Tools.DotNet.MSBuild;
using Cake.Common.Tools.DotNet.Pack;
using Cake.Core;
using Cake.Core.IO;
using System;
using System.Linq;
using static CakeBridge;
//////////////////////////////////////////////////////////////////////
// ARGUMENTS
//////////////////////////////////////////////////////////////////////
var target = Context.Argument<string>("target", "Default");
//////////////////////////////////////////////////////////////////////
// SETUP / TEARDOWN
//////////////////////////////////////////////////////////////////////
Setup(context =>
{
context.Information("Setting up...");
var releaseNotes = Context.ParseReleaseNotes("./ReleaseNotes.md");
var releaseVersion =releaseNotes.Version.ToString();
var buildData = new BuildData(
Context.MakeAbsolute(Context.Directory("./nuget")),
Context.GetFiles("./src/*.sln")
.FirstOrDefault()
?? throw new Exception("Failed to find solution"),
releaseVersion + "-alpha",
releaseVersion,
releaseVersion,
string.Join("\n", releaseNotes.Notes.ToArray()).Replace("\"", "\"\""),
Context.Argument<string>("configuration", "Release"));
context.Information("Executing build {0} ({1})...", buildData.SemVersion, buildData.Configuration);
return buildData;
});
Teardown(context =>
{
context.Information("Tearing down...");
});
//////////////////////////////////////////////////////////////////////
// TASKS
//////////////////////////////////////////////////////////////////////
var clean = Task("Clean")
.Does<BuildData>(buildData =>
{
Context.CleanDirectories("./src/**/bin/" + buildData.Configuration);
Context.CleanDirectories("./src/**/obj/" + buildData.Configuration);
Context.CleanDirectory(buildData.NugetRoot);
});
var restore = Task("Restore")
.IsDependentOn(clean)
.Does<BuildData>(buildData =>
{
Context.DotNetRestore(buildData.Solution.FullPath);
});
var build = Task("Build")
.IsDependentOn(restore)
.Does<BuildData>(buildData =>
{
Context.DotNetBuild(buildData.Solution.FullPath, new DotNetBuildSettings {
Configuration = buildData.Configuration,
MSBuildSettings = buildData.MSBuildSettings
});
});
var pack = Task("Pack")
.IsDependentOn(build)
.Does<BuildData>(buildData =>
{
if (!Context.DirectoryExists(buildData.NugetRoot))
{
Context.CreateDirectory(buildData.NugetRoot);
}
foreach(var project in Context
.GetFiles("./src/**/Cake.*.csproj")
.Where(file=>!file.FullPath.EndsWith("Tests")))
{
Context.DotNetPack(project.FullPath, new DotNetPackSettings {
Configuration = buildData.Configuration,
OutputDirectory = buildData.NugetRoot,
NoBuild = true,
MSBuildSettings = buildData.MSBuildSettings
});
}
});
Task("Default")
.IsDependentOn(pack);
//////////////////////////////////////////////////////////////////////
// Shared Build Data helper class
//////////////////////////////////////////////////////////////////////
public class BuildData
{
public DirectoryPath NugetRoot { get; }
public FilePath Solution { get; }
public string SemVersion { get; }
public string AssemblyVersion { get; }
public string FileVersion { get; }
public string ReleaseNotes { get; }
public string Configuration { get; }
public DotNetMSBuildSettings MSBuildSettings { get; }
public BuildData(
DirectoryPath nugetRoot,
FilePath solution,
string semVersion,
string assemblyVersion,
string fileVersion,
string releaseNotes,
string configuration
)
{
NugetRoot = nugetRoot;
Solution = solution;
SemVersion = semVersion;
AssemblyVersion = assemblyVersion;
FileVersion = fileVersion;
ReleaseNotes = releaseNotes;
Configuration = configuration;
MSBuildSettings = new DotNetMSBuildSettings()
.WithProperty("Version", SemVersion)
.WithProperty("AssemblyVersion", AssemblyVersion)
.WithProperty("FileVersion", FileVersion)
.WithProperty("PackageReleaseNotes", string.Concat("\"", ReleaseNotes, "\""))
.WithProperty("EmbedUntrackedSources", "true")
.WithProperty("ContinuousIntegrationBuild", !Context.BuildSystem().IsLocalBuild ? "true" : "false");
}
}
//////////////////////////////////////////////////////////////////////
// EXECUTION
//////////////////////////////////////////////////////////////////////
RunTarget(target);