This repository has been archived by the owner on Mar 31, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathbuild.cake
175 lines (144 loc) · 4.97 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
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
#addin "nuget:?package=Cake.ExtendedNuGet&version=1.0.0.22"
#addin "nuget:?package=NuGet.Core&version=2.12.0"
#addin "nuget:?package=Cake.FileHelpers&version=1.0.4"
//////////////////////////////////////////////////////////////////////
// ARGUMENTS
//////////////////////////////////////////////////////////////////////
var target = Argument("target", "Default");
var configuration = Argument("configuration", "Release");
//////////////////////////////////////////////////////////////////////
// VERSION
//////////////////////////////////////////////////////////////////////
var version = "3.8.0";
var displayVersion = "3.8.0";
//////////////////////////////////////////////////////////////////////
// NUGET PACKAGES
//////////////////////////////////////////////////////////////////////
var CONSOLE_PACKAGES = new []
{
"NUnit.ConsoleRunner"
};
var EXTENSION_PACKAGES = new []
{
"NUnit.Extension.VSProjectLoader",
"NUnit.Extension.NUnitProjectLoader",
"NUnit.Extension.NUnitV2Driver",
"NUnit.Extension.NUnitV2ResultWriter",
"NUnit.Extension.TeamCityEventListener"
};
//////////////////////////////////////////////////////////////////////
// FILE PATHS
//////////////////////////////////////////////////////////////////////
var ROOT_DIR = Context.Environment.WorkingDirectory.FullPath + "/";
var WIX_PROJ = ROOT_DIR + "nunit/nunit.wixproj";
var RESOURCES_DIR = ROOT_DIR + "resources/";
var RUNNER_PACKAGES_DIR = ROOT_DIR + "runner-packages/";
var EXTENSION_PACKAGES_DIR = ROOT_DIR + "extension-packages/";
var DISTRIBUTION_DIR = ROOT_DIR + "distribution/";
var IMAGE_DIR = ROOT_DIR + "image/";
var IMAGE_ADDINS_DIR = IMAGE_DIR + "addins/";
var ZIP_FILE = string.Format("{0}NUnit.Console-{1}.zip", DISTRIBUTION_DIR, version);
var COMPONENTS_FILE_PATH = IMAGE_DIR + "COMPONENTS.txt";
//////////////////////////////////////////////////////////////////////
// TASK
//////////////////////////////////////////////////////////////////////
Task("Clean")
.Does(() =>
{
CleanDirectory(RUNNER_PACKAGES_DIR);
CleanDirectory(EXTENSION_PACKAGES_DIR);
CleanDirectory(IMAGE_DIR);
CleanDirectory(IMAGE_ADDINS_DIR);
CleanDirectory(DISTRIBUTION_DIR);
});
Task("FetchPackages")
.IsDependentOn("Clean")
.Does(() =>
{
foreach(var package in CONSOLE_PACKAGES)
{
NuGetInstall(package, new NuGetInstallSettings {
OutputDirectory = RUNNER_PACKAGES_DIR
});
}
foreach(var package in EXTENSION_PACKAGES)
{
NuGetInstall(package, new NuGetInstallSettings {
OutputDirectory = EXTENSION_PACKAGES_DIR
});
}
});
Task("CreateImage")
.IsDependentOn("Clean")
.IsDependentOn("FetchPackages")
.Does(() =>
{
CopyDirectory(RESOURCES_DIR, IMAGE_DIR);
foreach(var packageDir in GetAllDirectories(RUNNER_PACKAGES_DIR))
CopyPackageContents(packageDir, IMAGE_DIR);
foreach(var packageDir in GetAllDirectories(EXTENSION_PACKAGES_DIR))
CopyPackageContents(packageDir, IMAGE_ADDINS_DIR);
});
Task("WriteComponentsFile")
.IsDependentOn("Clean")
.IsDependentOn("FetchPackages")
.Does(context =>
{
List<string> lines = new List<string> { "This package contains the following components:", "" };
var packageDirs = new [] { RUNNER_PACKAGES_DIR, EXTENSION_PACKAGES_DIR };
foreach (var packageDir in packageDirs)
{
foreach(var nupkgPath in GetFiles(packageDir + "*/*.nupkg"))
{
var nupkg = new ZipPackage(nupkgPath.MakeAbsolute(context.Environment).FullPath);
lines.Add(string.Format("{0} - {1}{2}{3}{2}", nupkg.Id, nupkg.Version, Environment.NewLine, nupkg.Summary));
}
}
FileWriteLines(COMPONENTS_FILE_PATH, lines.ToArray());
});
Task("PackageMsi")
.IsDependentOn("WriteComponentsFile")
.IsDependentOn("CreateImage")
.Does(() =>
{
MSBuild(WIX_PROJ, new MSBuildSettings()
.WithTarget("Rebuild")
.SetConfiguration(configuration)
.WithProperty("Version", version)
.WithProperty("DisplayVersion", displayVersion)
.WithProperty("OutDir", DISTRIBUTION_DIR)
.WithProperty("Image", IMAGE_DIR)
.SetMSBuildPlatform(MSBuildPlatform.x86)
.SetNodeReuse(false)
);
});
Task("PackageZip")
.IsDependentOn("WriteComponentsFile")
.IsDependentOn("CreateImage")
.Does(() =>
{
Zip(IMAGE_DIR, ZIP_FILE);
});
Task("PackageAll")
.IsDependentOn("PackageMsi")
.IsDependentOn("PackageZip");
Task("Appveyor")
.IsDependentOn("PackageAll");
Task("Default")
.IsDependentOn("PackageAll");
//////////////////////////////////////////////////////////////////////
// HELPER METHODS
//////////////////////////////////////////////////////////////////////
public string[] GetAllDirectories(string dirPath)
{
return System.IO.Directory.GetDirectories(dirPath);
}
public void CopyPackageContents(DirectoryPath packageDir, DirectoryPath outDir)
{
var files = GetFiles(packageDir + "/tools/*");
CopyFiles(files.Where(f => f.GetExtension() != ".addins"), outDir);
}
//////////////////////////////////////////////////////////////////////
// EXECUTION
//////////////////////////////////////////////////////////////////////
RunTarget(target);