This repository has been archived by the owner on Jan 20, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 96
/
build.cake
121 lines (101 loc) · 3.86 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
//////////////////////////////////////////////////////////////////////
// TOOLS
//////////////////////////////////////////////////////////////////////
#tool "nuget:?package=GitVersion.CommandLine&version=4.0.0"
#tool "nuget:?package=NUnit.Runners&version=2.6.4"
#addin "Cake.FileHelpers&version=3.2.0"
using Path = System.IO.Path;
using IO = System.IO;
using Cake.Common.Xml;
//////////////////////////////////////////////////////////////////////
// ARGUMENTS
//////////////////////////////////////////////////////////////////////
var target = Argument("target", "Default");
var configuration = Argument("configuration", "Release");
///////////////////////////////////////////////////////////////////////////////
// GLOBAL VARIABLES
///////////////////////////////////////////////////////////////////////////////
var buildDir = "./build/";
var artifactsDir = "./artifacts/";
GitVersion gitVersionInfo;
string nugetVersion;
///////////////////////////////////////////////////////////////////////////////
// SETUP / TEARDOWN
///////////////////////////////////////////////////////////////////////////////
Setup(context =>
{
gitVersionInfo = GitVersion(new GitVersionSettings {
OutputType = GitVersionOutput.Json
});
if(BuildSystem.IsRunningOnTeamCity)
BuildSystem.TeamCity.SetBuildNumber(gitVersionInfo.NuGetVersion);
nugetVersion = gitVersionInfo.NuGetVersion;
Information("Building OctoPack v{0}", nugetVersion);
Information("Informational Version {0}", gitVersionInfo.InformationalVersion);
});
Teardown(context =>
{
Information("Finished running tasks.");
});
//////////////////////////////////////////////////////////////////////
// PRIVATE TASKS
//////////////////////////////////////////////////////////////////////
Task("Clean")
.Does(() =>
{
CleanDirectory(buildDir);
CleanDirectory(artifactsDir);
CleanDirectories("./source/**/bin");
CleanDirectories("./source/**/obj");
CleanDirectories("./source/**/TestResults");
});
Task("Restore")
.IsDependentOn("Clean")
.Does(() => {
DotNetCoreRestore("source");
});
Task("Build")
.IsDependentOn("Restore")
.IsDependentOn("Clean")
.Does(() => {
MSBuild("./source/OctoPack.sln", new MSBuildSettings
{
Configuration = configuration,
ArgumentCustomization = args => args.Append($"/p:Version={nugetVersion}")
});
});
Task("Test")
.IsDependentOn("Build")
.Does(() => {
var assemblies = GetFiles("./source/**/bin/**/*Tests.dll");
foreach (var assembly in assemblies) {
Information("Running test {0}", assembly.FullPath);
NUnit(assembly.FullPath);
}
});
Task("Package")
.IsDependentOn("Test")
.Does(() => {
CreateDirectory(buildDir);
CreateDirectory(Path.Combine(buildDir, "lib"));
CreateDirectory(Path.Combine(buildDir, "lib", "net35"));
CreateDirectory(Path.Combine(buildDir, "lib", "net40"));
CreateDirectory(Path.Combine(buildDir, "lib", "netcore45"));
CreateDirectory(artifactsDir);
CopyDirectory($"./source/OctoPack.Tasks/bin/{configuration}", Path.Combine(buildDir, "build"));
CopyDirectory(@"./source/build", Path.Combine(buildDir, "build"));
CopyDirectory(@"./source/tools", Path.Combine(buildDir, "tools"));
CopyFileToDirectory(@".\source\OctoPack.nuspec", buildDir);
CopyFileToDirectory(@".\license.txt", buildDir);
NuGetPack(Path.Combine(buildDir, "OctoPack.nuspec"), new NuGetPackSettings {
Version = nugetVersion,
OutputDirectory = artifactsDir,
NoPackageAnalysis = true
});
});
Task("Default")
.IsDependentOn("Package");
//////////////////////////////////////////////////////////////////////
// EXECUTION
//////////////////////////////////////////////////////////////////////
RunTarget(target);