-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.cake
121 lines (93 loc) · 3.6 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
#tool "nuget:?package=GitReleaseNotes"
#tool "nuget:?package=GitVersion.CommandLine"
#tool "nuget:?package=gitlink"
// Based on -> http://www.michael-whelan.net/continuous-delivery-github-cake-gittools-appveyor/
//Main target to run the cake script
var target = Argument("target", "Default");
//Output directory. This will necessary to the AppVeyor
var outputDir = "./artifacts/";
//Solution file path
var solutionPath = "./SampleCore/SampleCore.sln";
//Main project path. We need is because of the versioning and packing to Nuget.
var mainProjectJson = "./SampleCore/src/SampleCore/project.json";
Task("Clean")
.Does(() => {
if (DirectoryExists(outputDir))
{
DeleteDirectory(outputDir, recursive:true);
}
CreateDirectory(outputDir);
});
Task("Restore")
.Does(() => {
DotNetCoreRestore("SampleCore");
});
GitVersion versionInfo = null;
Task("Version")
.Does(() => {
GitVersion(new GitVersionSettings{
UpdateAssemblyInfo = true,
OutputType = GitVersionOutput.BuildServer
});
versionInfo = GitVersion(new GitVersionSettings{ OutputType = GitVersionOutput.Json });
var updatedProjectJson = System.IO.File.ReadAllText(mainProjectJson)
.Replace("1.0.0-*", versionInfo.NuGetVersion);
System.IO.File.WriteAllText(mainProjectJson, updatedProjectJson);
});
Task("Build")
.IsDependentOn("Clean")
.IsDependentOn("Version")
.IsDependentOn("Restore")
.Does(() => {
MSBuild(solutionPath);
});
Task("Test")
.IsDependentOn("Build")
.Does(() => {
var directories = GetDirectories("./SampleCore/tests/*");
Information("Test project count : {0}", directories.Count());
foreach(var directory in directories)
{
Information("Start running tests in project: {0}", directory);
DotNetCoreTest(directory.FullPath);
Information("Test run finished in project: {0}", directory);
}
});
Task("Package")
.IsDependentOn("Test")
.Does(() => {
GitLink("./", new GitLinkSettings { ArgumentCustomization = args => args.Append("-include Specify,Specify.Autofac") });
GenerateReleaseNotes();
PackageProject("SampleCore", mainProjectJson);
if (AppVeyor.IsRunningOnAppVeyor)
{
foreach (var file in GetFiles(outputDir + "**/*"))
AppVeyor.UploadArtifact(file.FullPath);
}
});
private void PackageProject(string projectName, string projectJsonPath)
{
var settings = new DotNetCorePackSettings
{
OutputDirectory = outputDir,
NoBuild = true
};
DotNetCorePack(projectJsonPath, settings);
System.IO.File.WriteAllLines(outputDir + "artifacts", new[]{
"nuget:" + projectName + "." + versionInfo.NuGetVersion + ".nupkg",
"nugetSymbols:" + projectName + "." + versionInfo.NuGetVersion + ".symbols.nupkg",
"releaseNotes:releasenotes.md"
});
}
private void GenerateReleaseNotes()
{
var releaseNotesExitCode = StartProcess(
@"tools\GitReleaseNotes\tools\gitreleasenotes.exe",
new ProcessSettings { Arguments = ". /o artifacts/releasenotes.md" });
if (string.IsNullOrEmpty(System.IO.File.ReadAllText("./artifacts/releasenotes.md")))
System.IO.File.WriteAllText("./artifacts/releasenotes.md", "No issues closed since last release");
if (releaseNotesExitCode != 0) throw new Exception("Failed to generate release notes");
}
Task("Default")
.IsDependentOn("Package");
RunTarget(target);