forked from cake-contrib/Cake.Yarn
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.cake
139 lines (121 loc) · 2.55 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
/*
* Load additional cake addins
*/
#addin Cake.Git&version=0.22.0
/*
* Load additional tools
*/
#tool xunit.runner.console&version=2.4.1
#tool GitVersion.CommandLine&version=5.6.3
/*
* Commandline argument handling
*/
string target = Argument("target", "Default");
string configuration = Argument("configuration", "Release");
/*
* Constants, initial variables
*/
string projectName = "Cake.Yarn";
string testProjectName = "Cake.Yarn.Tests";
FilePath project = $"./src/{projectName}/{projectName}.csproj";
FilePath testProject = $"./src/{testProjectName}/{testProjectName}.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()
{
IEnumerable<string> changes;
string tag;
try
{
tag = GitDescribe(".", "HEAD~1", false, GitDescribeStrategy.Tags, 0);
}
catch(Exception)
{
return new string[0];
}
string commitRange = tag + "..HEAD";
StartProcess("git", new ProcessSettings
{
RedirectStandardOutput = true,
Silent = true,
Arguments = $"log {commitRange} --no-merges --format=\"[%h] %s\""
}, out changes);
return changes.ToArray();
}
/*
* Task: Clean
*/
Task("Clean")
.Does(() =>
{
CleanDirectories($"./src/**/bin/{configuration}");
CleanDirectories("./src/**/obj");
CleanDirectory(artifacts);
});
/*
* Task: Restore
*/
Task("Restore")
.Does(() =>
{
DotNetCoreRestore(testProject.FullPath);
});
/*
* Task: Build
*/
Task("Build")
.IsDependentOn("Clean")
.Does(() =>
{
DotNetCoreBuild(project.FullPath, new DotNetCoreBuildSettings {
Configuration = configuration
});
});
/*
* Task: Test
*/
Task("Test")
.IsDependentOn("Clean")
.IsDependentOn("Restore")
.Does(() =>
{
DotNetCoreTest(testProject.FullPath);
});
/*
* Task: Pack
*/
Task("Pack")
.IsDependentOn("Clean")
.IsDependentOn("Build")
.IsDependentOn("Test")
.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);