-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbuild.cake
119 lines (104 loc) · 2.4 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
/*
* Load additional tools
*/
#tool xunit.runner.console&version=2.3.1
#tool GitVersion.CommandLine&version=3.6.5
/*
* Commandline argument handling
*/
string target = Argument("target", "Default");
string configuration = Argument("configuration", "Release");
/*
* Constants, initial variables
*/
string projectName = "Extensions.Logging.Log4Net";
FilePath project = $"./src/{projectName}/{projectName}.csproj";
DirectoryPath artifacts = "./artifacts";
GitVersion version = GitVersion();
/*
* Helper: GetReleaseNotes
*
* Parses the git commits since the last tag to render some release notes
* that will be taken into account when publishing the repository.
*/
string[] GetReleaseNotes()
{
string tag = null;
try
{
StartProcess("git", new ProcessSettings
{
RedirectStandardOutput = true,
RedirectStandardError = true,
Silent = true,
Arguments = "describe --tags --abbrev=0 head~"
}, out IEnumerable<string> output);
tag = output.First();
} catch
{
// Ignore describe call. Maybe head~1 is not present.
}
string commitRange = !string.IsNullOrWhiteSpace(tag) ? $"{tag}..HEAD": null;
StartProcess("git", new ProcessSettings
{
RedirectStandardOutput = true,
Silent = true,
Arguments = $"log {commitRange} --no-merges --format=\"- [%h] %s\""
}, out IEnumerable<string> changes);
if (changes.Any())
{
changes = changes.Select(x => x.Replace("\"", "\\\""));
}
return changes.ToArray();
}
/*
* Task: Clean
*/
Task("Clean")
.Does(() =>
{
CleanDirectories($"./src/**/bin/{configuration}");
CleanDirectories("./src/**/obj");
CleanDirectory(artifacts);
});
/*
* Task: Build
*/
Task("Build")
.IsDependentOn("Clean")
.Does(() =>
{
DotNetCoreBuild(project.FullPath, new DotNetCoreBuildSettings {
Configuration = configuration
});
});
/*
* Task: Pack
*/
Task("Pack")
.IsDependentOn("Build")
.Does (() =>
{
var nugetDirectory = artifacts.Combine("nuget");
EnsureDirectoryExists(nugetDirectory);
DotNetCorePack(project.FullPath, new DotNetCorePackSettings {
Configuration = configuration,
IncludeSymbols = true,
NoBuild = true,
OutputDirectory = nugetDirectory,
ArgumentCustomization = args =>
{
return args
.Append($"/p:PackageVersion={version.NuGetVersion}")
.AppendQuoted("/p:PackageReleaseNotes=" + string.Join("\n", GetReleaseNotes()));
}
});
});
/*
* Task: Default
*/
Task("Default").IsDependentOn("Pack");
/*
* Script Execution
*/
RunTarget(target);