forked from mwhelan/Specify
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.cake
117 lines (98 loc) · 3.22 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
#tool "nuget:?package=GitReleaseNotes"
#tool "nuget:?package=GitVersion.CommandLine"
#tool "nuget:?package=gitlink"
var target = Argument("target", "Default");
var outputDir = "./artifacts/";
var solutionPath = "./src/Specify.sln";
var specifyProjectJson = "./src/app/Specify/project.json";
var specifyAutofacProjectJson = "./src/app/Specify.Autofac/project.json";
Task("Clean")
.Does(() => {
if (DirectoryExists(outputDir))
{
DeleteDirectory(outputDir, recursive:true);
}
CreateDirectory(outputDir);
});
Task("Restore")
.Does(() => {
DotNetCoreRestore("src");
});
GitVersion versionInfo = null;
Task("Version")
.Does(() => {
GitVersion(new GitVersionSettings{
UpdateAssemblyInfo = true,
OutputType = GitVersionOutput.BuildServer
});
versionInfo = GitVersion(new GitVersionSettings{ OutputType = GitVersionOutput.Json });
// Update project.json
VersionProject(specifyProjectJson, versionInfo);
VersionProject(specifyAutofacProjectJson, versionInfo);
});
Task("Build")
.IsDependentOn("Clean")
.IsDependentOn("Version")
.IsDependentOn("Restore")
.Does(() => {
MSBuild(solutionPath, new MSBuildSettings
{
Verbosity = Verbosity.Minimal,
ToolVersion = MSBuildToolVersion.VS2015,
Configuration = "Release",
PlatformTarget = PlatformTarget.MSIL
});
});
Task("Test")
.IsDependentOn("Build")
.Does(() => {
DotNetCoreTest("./src/tests/Specify.Tests");
DotNetCoreTest("./src/tests/Specify.IntegrationTests");
DotNetCoreTest("./src/Samples/Specify.Samples");
});
Task("Package")
.IsDependentOn("Test")
.Does(() => {
//GitLink("./", new GitLinkSettings { ArgumentCustomization = args => args.Append("-include Specify,Specify.Autofac") });
GenerateReleaseNotes();
PackageProject("Specify");
PackageProject("Specify.Autofac");
if (AppVeyor.IsRunningOnAppVeyor)
{
foreach (var file in GetFiles(outputDir + "**/*"))
AppVeyor.UploadArtifact(file.FullPath);
}
});
private void VersionProject(string projectJsonPath, GitVersion versionInfo)
{
var updatedProjectJson = System.IO.File.ReadAllText(projectJsonPath)
.Replace("1.0.0-*", versionInfo.NuGetVersion);
System.IO.File.WriteAllText(projectJsonPath, updatedProjectJson);
}
private void PackageProject(string projectName)
{
var settings = new NuGetPackSettings
{
OutputDirectory = outputDir,
Version = versionInfo.NuGetVersion
};
var nuspec = "nuget/" + projectName + ".nuspec";
NuGetPack(nuspec, 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);