forked from Dalmirog-zz/OctoPosh
-
Notifications
You must be signed in to change notification settings - Fork 3
/
PowershellModule_Build.cake
221 lines (190 loc) · 7.58 KB
/
PowershellModule_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
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
#tool nuget:?package=NUnit.ConsoleRunner&version=3.7.0
#tool nuget:?package=Cake.CoreCLR&version=0.21.1
#addin "Cake.Powershell"
//////////////////////////////////////////////////////////////////////
// ARGUMENTS
//////////////////////////////////////////////////////////////////////
var target = Argument("target", "Default");
var configuration = Argument("configuration", "Release");
var ConfigFile = Argument("ConfigFile","");
var BinaryVersion = Argument("BinaryVersion","");
var RemoveOctopusInstanceAtBeggining = Argument("RemoveOctopusInstanceAtBeggining", false);
var CreateOctopusInstance = Argument("CreateOctopusInstance", false);
var RemoveOctopusInstanceAtEnd = Argument("RemoveOctopusInstanceAtEnd", false);
var GenerateTestData = Argument("GenerateTestData", false);
//////////////////////////////////////////////////////////////////////
// PREPARATION
//////////////////////////////////////////////////////////////////////
// Define directories.
//The compiled module will be sent to modulePublishDir
var modulePublishDir = MakeAbsolute(Directory("./Octoposh/Publish/")).FullPath;
var testDataGeneratorPublishDir = MakeAbsolute(Directory("./Octoposh.TestDataGenerator/Publish/")).FullPath;
var testOutputDir = MakeAbsolute(Directory("./Octoposh.Tests/Publish")).FullPath;
var pathsToClean = new string[]{modulePublishDir,testDataGeneratorPublishDir,testOutputDir};
var ManifestPath = Directory(modulePublishDir) + Directory("Octoposh.psd1");
//////////////////////////////////////////////////////////////////////
// TASKS
//////////////////////////////////////////////////////////////////////
Task("Clean")
.Does(() =>
{
//Add the path to clean to pathstoClean
foreach(var dir in pathsToClean){
CleanDirectory(dir);
}
});
Task("Restore-NuGet-Packages")
.IsDependentOn("Clean")
.Does(() =>
{
NuGetRestore("Octoposh.sln");
});
Task("Replace-Test-Project-App-Settings")
.IsDependentOn("Restore-NuGet-Packages")
.Description("Replace appconfig files on projects so they are run against the Octopus Instance that's being created by this build.")
.Does(() =>
{
StartPowershellFile("Octoposh.Tests/Scripts/replaceAppSettings.ps1", new PowershellSettings()
.SetFormatOutput()
.SetLogOutput()
.WithArguments(args=>
{
args.Append("ConfigFile",ConfigFile);
}));
StartPowershellFile("Octoposh.TestDataGenerator/Scripts/replaceAppSettings.ps1", new PowershellSettings()
.SetFormatOutput()
.SetLogOutput()
.WithArguments(args=>
{
args.Append("ConfigFile",ConfigFile);
}));
});
Task("Build")
.IsDependentOn("Replace-Test-Project-App-Settings")
.Does(() =>
{
//Build PS Module
Information("Running MSBuild for Octoposh.csproj...");
MSBuild("Octoposh/Octoposh.csproj", settings =>
settings.SetConfiguration(configuration)
.WithProperty("OutDir", modulePublishDir));
//Build Tests
Information("Running MSBuild for Octoposh.Tests.csproj...");
MSBuild("Octoposh.Tests/Octoposh.Tests.csproj", settings =>
settings.SetConfiguration(configuration));
//Build website
var testDataGeneratorSettings = new DotNetCorePublishSettings
{
Framework = "netcoreapp2.0",
Configuration = "Release",
OutputDirectory = testDataGeneratorPublishDir
};
Information("Running dotnet publish for Octoposh.TestDataGenerator.csproj...");
DotNetCorePublish("./Octoposh.TestDataGenerator/Octoposh.TestDataGenerator.csproj", testDataGeneratorSettings);
});
Task("Update-Module-Manifest")
.IsDependentOn("Build")
.Description("Updates the module mainfest")
.Does(() =>
{
StartPowershellFile("Scripts/UpdateModuleManifest.ps1", new PowershellSettings()
.SetFormatOutput()
.SetLogOutput()
.WithArguments(args=>
{
args.Append("Version",BinaryVersion);
args.Append("ManifestPath",ManifestPath);
}));
});
Task("Remove-Octopus-Instance-At-Beggining")
.IsDependentOn("Update-Module-Manifest")
.WithCriteria(RemoveOctopusInstanceAtBeggining == true)
.Description("Removes the Octopus Test instance")
.Does(() =>
{
StartPowershellFile("Scripts/OctopusServer.ps1", new PowershellSettings()
.SetFormatOutput()
.SetLogOutput()
.WithArguments(args=>
{
args.Append("Action","RemoveInstance");
args.Append("ConfigFile",ConfigFile);
}));
});
Task("Create-Octopus-Instance")
.IsDependentOn("Remove-Octopus-Instance-At-Beggining")
.WithCriteria(CreateOctopusInstance == true)
.Description("Creates the test Octopus instance. If an instance with that name already exists, it won't be re-created but its data will be restored sing the backup in Source Control")
.Does(() =>
{
StartPowershellFile("Scripts/OctopusServer.ps1", new PowershellSettings()
.SetFormatOutput()
.SetLogOutput()
.WithArguments(args=>
{
args.Append("Action","CreateInstance");
args.Append("ConfigFile",ConfigFile);
}));
});
Task("Start-Octopus-Server")
.IsDependentOn("Create-Octopus-Instance")
.Description("Make sure the Octopus Server is started before running tests")
.Does(() =>
{
StartPowershellFile("Scripts/OctopusServer.ps1", new PowershellSettings()
.SetFormatOutput()
.SetLogOutput()
.WithArguments(args=>
{
args.Append("Action","StartService");
}));
});
Task("Run-TestDatagenerator")
.IsDependentOn("Start-Octopus-Server")
.WithCriteria(GenerateTestData == true)
.Description("Runs the TestDataGenerator console to create all the Octopus resources needed for the tests to run ")
.Does(() =>
{
StartPowershellFile("Scripts/OctopusServer.ps1", new PowershellSettings()
.SetFormatOutput()
.SetLogOutput()
.WithArguments(args=>
{
args.Append("Action","GenerateTestData");
args.Append("ConfigFile",ConfigFile);
}));
});
Task("Run-Unit-Tests")
.IsDependentOn("Run-TestDatagenerator")
.Does(() =>
{
NUnit3("./Octoposh.Tests/bin/" + configuration + "/*.Tests.dll", new NUnit3Settings {
NoResults = false, //Needs to be "true" for NUnit to create TestResult.xml
WorkingDirectory = testOutputDir //TestResult.xml will be dropped under "WorkingDirectory"
});
});
Task("Remove-Octopus-Instance-At-End")
.IsDependentOn("Run-Unit-Tests")
.WithCriteria(RemoveOctopusInstanceAtEnd == true)
.Description("Removes the Octopus Test instance")
.Does(() =>
{
StartPowershellFile("Scripts/OctopusServer.ps1", new PowershellSettings()
.SetFormatOutput()
.SetLogOutput()
.WithArguments(args=>
{
args.Append("Action","RemoveInstance");
args.Append("ConfigFile",ConfigFile);
}));
});
//////////////////////////////////////////////////////////////////////
// TASK TARGETS
//////////////////////////////////////////////////////////////////////
Task("Default")
//.IsDependentOn("testDelete");
.IsDependentOn("Remove-Octopus-Instance-At-End");
//////////////////////////////////////////////////////////////////////
// EXECUTION
//////////////////////////////////////////////////////////////////////
RunTarget(target);