-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.cake
154 lines (127 loc) · 4.59 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
#tool nuget:?package=NUnit.ConsoleRunner&version=3.4.0
//////////////////////////////////////////////////////////////////////
// ARGUMENTS
//////////////////////////////////////////////////////////////////////
var target = Argument("target", "Default");
var configuration = Argument("configuration", "Release");
//////////////////////////////////////////////////////////////////////
// PREPARATION
//////////////////////////////////////////////////////////////////////
var projectName = "Metrics.Serilog";
// Define directories.
var sourceDir = Directory("./src");
var projectDir = sourceDir + Directory(projectName);
var buildDir = projectDir + Directory("bin") + Directory(configuration);
var testDir = Directory("./test/" + projectName + ".Tests/bin") + Directory(configuration);
var artifactsDir = Directory("./artifacts");
// Define files.
var solutionFile = File("./" + projectName + ".sln");
var projectFile = projectDir + File(projectName + ".csproj");
var testResultFile = artifactsDir + File("TestResults.xml");
// Get environmental information.
var local = BuildSystem.IsLocalBuild;
var isRunningOnAppVeyor = AppVeyor.IsRunningOnAppVeyor;
var isPullRequest = AppVeyor.Environment.PullRequest.IsPullRequest;
// Define version information.
var build = isRunningOnAppVeyor ? AppVeyor.Environment.Build.Number : 1;
var version = "0.1." + build;
var packageVersion = version + "-alpha";
///////////////////////////////////////////////////////////////////////////////
// SETUP / TEARDOWN
///////////////////////////////////////////////////////////////////////////////
Setup(context =>
{
Information("Target: " + target);
Information("Configuration: " + configuration);
Information("Local Build: " + local);
Information("AppVeyor Build: " + isRunningOnAppVeyor);
Information("Pull Request: " + isPullRequest);
Information("Build Number: " + build);
Information("Version: " + version);
Information("Package Version: " + packageVersion);
});
//////////////////////////////////////////////////////////////////////
// TASKS
//////////////////////////////////////////////////////////////////////
Task("Clean")
.Does(() =>
{
foreach (var dir in new[] {buildDir, testDir, artifactsDir})
{
CleanDirectory(dir);
}
});
Task("Update-Version")
.IsDependentOn("Clean")
.Does(() =>
{
var versionFile = projectDir + Directory("Properties") + File("VersionInfo.cs");
Information("Updating version file: " + versionFile);
CreateAssemblyInfo(versionFile, new AssemblyInfoSettings {
Version = version,
FileVersion = version,
InformationalVersion = packageVersion
});
});
Task("Update-AppVeyor-Version")
.IsDependentOn("Update-Version")
.WithCriteria(() => isRunningOnAppVeyor)
.Does(() =>
{
Information("Updating AppVeyor build version: " + packageVersion);
AppVeyor.UpdateBuildVersion(packageVersion);
});
Task("Restore-NuGet-Packages")
.IsDependentOn("Update-AppVeyor-Version")
.Does(() =>
{
NuGetRestore(solutionFile);
});
Task("Build")
.IsDependentOn("Restore-NuGet-Packages")
.Does(() =>
{
MSBuild(solutionFile, settings => settings.SetConfiguration(configuration));
});
Task("Run-Unit-Tests")
.IsDependentOn("Build")
.Does(() =>
{
var settings = new NUnit3Settings { Results = testResultFile };
NUnit3("./test/**/bin/" + configuration + "/*.Tests.dll", settings);
});
Task("Pack-NuGet-Packages")
.IsDependentOn("Run-Unit-Tests")
.Does(() =>
{
var settings = new NuGetPackSettings
{
OutputDirectory = artifactsDir,
Properties = new Dictionary<string, string> {{ "Configuration", configuration }}
};
CreateDirectory(artifactsDir);
NuGetPack(projectFile, settings);
});
Task("Upload-AppVeyor-Artifacts")
.IsDependentOn("Pack-NuGet-Packages")
.WithCriteria(() => isRunningOnAppVeyor)
.Does(() =>
{
var artifacts = GetFiles(artifactsDir.Path + "/**/*.nupkg");
foreach(var artifact in artifacts)
{
Information("Uploading NuGet package: " + artifact);
AppVeyor.UploadArtifact(artifact);
}
Information("Uploading unit test results: " + testResultFile);
AppVeyor.UploadTestResults(testResultFile, AppVeyorTestResultsType.NUnit3);
});
//////////////////////////////////////////////////////////////////////
// TASK TARGETS
//////////////////////////////////////////////////////////////////////
Task("Default")
.IsDependentOn("Upload-AppVeyor-Artifacts");
//////////////////////////////////////////////////////////////////////
// EXECUTION
//////////////////////////////////////////////////////////////////////
RunTarget(target);