-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.cake
100 lines (84 loc) · 2.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
#l "utilities.cake"
var target = Argument<string>("target", "Build");
var configuration = Argument<string>("configuration", "Debug");
var release = Argument<bool>("release", false);
var assemblyInfoFile = "Source/Bender/Properties/AssemblyInfo.cs";
var outputDirectory = "Output";
var buildVersionFile = $"{outputDirectory}/VERSION";
var buildPreleaseFile = $"{outputDirectory}/PRELEASE";
var buildChangeLogFile = $"{outputDirectory}/CHANGELOG";
var buildDirectory = Directory($"{outputDirectory}/Build/{configuration}");
Task("CleanBuild")
.Does(() =>
{
CleanDirectories(new DirectoryPath[] { buildDirectory });
});
Task("Restore")
.Does(() =>
{
NuGetRestore(GetSolution());
});
Task("BuildVersionInfo")
.Does(() =>
{
SemVer buildVersion;
var changeLog = GetChangeLog();
var version = changeLog.LatestVersion;
var rev = GetGitRevision(useShort: true);
if (rev != null && !release)
{
if (version.Build == null)
{
buildVersion = new SemVer(version.Major, version.Minor, version.Patch, version.Pre, rev);
}
else
{
throw new Exception($"ChangeLog already contains build metadata.");
}
}
else
{
buildVersion = version;
}
System.IO.File.WriteAllText(buildVersionFile, buildVersion);
System.IO.File.WriteAllText(buildPreleaseFile, (buildVersion.Pre != null).ToString().ToLower());
System.IO.File.WriteAllText(buildChangeLogFile, changeLog.LatestChanges);
});
Task("BuildAssemblyInfo")
.IsDependentOn("BuildVersionInfo")
.Does(() =>
{
var version = GetBuildVersion();
var output = TransformTextFile($"{assemblyInfoFile}.in")
.WithToken("VERSION", version)
.WithToken("VERSION.MAJOR", version.Major)
.WithToken("VERSION.MINOR", version.Minor)
.WithToken("VERSION.PATCH", version.Patch)
.WithToken("VERSION.PRE", version.Pre)
.WithToken("VERSION.BUILD", version.Build)
.ToString();
System.IO.File.WriteAllText(assemblyInfoFile, output);
});
Task("Build")
.IsDependentOn("CleanBuild")
.IsDependentOn("Restore")
.IsDependentOn("BuildAssemblyInfo")
.Does(() =>
{
MSBuild(GetSolution(), s => { s.Configuration = configuration; });
});
Task("Version")
.Does(() =>
{
Information(GetVersion());
});
Task("ChangeLog")
.Does(() =>
{
Information(GetChangeLog().LatestChanges);
});
RunTarget(target);
private SemVer GetBuildVersion()
{
return new SemVer(System.IO.File.ReadAllText(buildVersionFile));
}