This repository has been archived by the owner on May 7, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 37
/
build.cake
144 lines (126 loc) · 5.5 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
#tool "nuget:?package=xunit.runner.console&version=2.3.0-beta4-build3742"
#addin "nuget:?package=NuGet.Core"
#addin "nuget:?package=Cake.ExtendedNuGet"
//////////////////////////////////////////////////////////////////////
// ARGUMENTS
//////////////////////////////////////////////////////////////////////
var projectName = "Stove";
var solution = "./" + projectName + ".sln";
var target = Argument("target", "Default");
var configuration = Argument("configuration", "Release");
var toolpath = Argument("toolpath", @"tools");
var branch = Argument("branch", EnvironmentVariable("APPVEYOR_REPO_BRANCH"));
var nugetApiKey = EnvironmentVariable("nugetApiKey");
var isRelease = EnvironmentVariable("APPVEYOR_REPO_TAG") == "true";
var testProjects = new List<Tuple<string, string[]>>
{
new Tuple<string, string[]>("Stove.EntityFramework.Tests", new[] { "net461" }),
new Tuple<string, string[]>("Stove.EntityFrameworkCore.Dapper.Tests", new[] { "netcoreapp2.0" }),
new Tuple<string, string[]>("Stove.Mapster.Tests", new[] { "netcoreapp2.0" }),
new Tuple<string, string[]>("Stove.NLog.Tests", new[] { "netcoreapp2.0" }),
new Tuple<string, string[]>("Stove.RabbitMQ.Tests", new[] { "netcoreapp2.0" }),
new Tuple<string, string[]>("Stove.RavenDB.Tests", new[] { "net461" }),
new Tuple<string, string[]>("Stove.Redis.Tests", new[] { "netcoreapp2.0" }),
new Tuple<string, string[]>("Stove.Tests", new[] { "netcoreapp2.0" }),
new Tuple<string, string[]>("Stove.Tests.SampleApplication", new[] { "net461" }),
new Tuple<string, string[]>("Stove.Dapper.Tests", new[] { "net461" }),
new Tuple<string, string[]>("Stove.Hangfire.Tests", new[] { "netcoreapp2.0" }),
new Tuple<string, string[]>("Stove.NHibernate.Tests", new[] { "net461" }),
new Tuple<string, string[]>("Stove.EntityFrameworkCore.Tests", new[] { "netcoreapp2.0" }),
new Tuple<string, string[]>("Stove.Serilog.Tests", new[] { "netcoreapp2.0" })
};
var nupkgPath = "nupkg";
var nupkgRegex = $"**/{projectName}*.nupkg";
var nugetPath = toolpath + "/nuget.exe";
var nugetQueryUrl = "https://www.nuget.org/api/v2/";
var nugetPushUrl = "https://www.nuget.org/api/v2/package";
var NUGET_PUSH_SETTINGS = new NuGetPushSettings
{
ToolPath = File(nugetPath),
Source = nugetPushUrl,
ApiKey = nugetApiKey
};
//////////////////////////////////////////////////////////////////////
// TASKS
//////////////////////////////////////////////////////////////////////
Task("Clean")
.Does(() =>
{
Information("Current Branch is:" + EnvironmentVariable("APPVEYOR_REPO_BRANCH"));
Information($"IsRelase: {isRelease}");
CleanDirectories("./src/**/bin");
CleanDirectories("./src/**/obj");
CleanDirectory(nupkgPath);
});
Task("Restore-NuGet-Packages")
.IsDependentOn("Clean")
.Does(() =>
{
DotNetCoreRestore(solution);
});
Task("Build")
.IsDependentOn("Restore-NuGet-Packages")
.Does(() =>
{
MSBuild(solution, new MSBuildSettings(){Configuration = configuration}
.WithProperty("SourceLinkCreate","true"));
});
Task("Run-Unit-Tests")
.IsDependentOn("Build")
.Does(() =>
{
foreach (Tuple<string, string[]> testProject in testProjects)
{
foreach (string targetFramework in testProject.Item2)
{
if(targetFramework == "net461")
{
var testFile = GetFiles($"**/bin/{configuration}/{targetFramework}/{testProject.Item1}*.dll").First();
Information(testFile);
XUnit2(testFile.ToString(), new XUnit2Settings { });
}
else
{
var testProj = GetFiles($"./test/**/*{testProject.Item1}.csproj").First();
DotNetCoreTest(testProj.FullPath, new DotNetCoreTestSettings { Configuration = "Release", Framework = targetFramework });
}
}
}
});
Task("Pack")
.IsDependentOn("Run-Unit-Tests")
.Does(() =>
{
var nupkgFiles = GetFiles(nupkgRegex);
MoveFiles(nupkgFiles, nupkgPath);
});
Task("NugetPublish")
.IsDependentOn("Pack")
.WithCriteria(() => branch == "master")
.Does(()=>
{
foreach(var nupkgFile in GetFiles(nupkgRegex))
{
if(!IsNuGetPublished(nupkgFile, nugetQueryUrl))
{
Information("Publishing... " + nupkgFile);
NuGetPush(nupkgFile, NUGET_PUSH_SETTINGS);
}
else
{
Information("Already published, skipping... " + nupkgFile);
}
}
});
//////////////////////////////////////////////////////////////////////
// TASK TARGETS
//////////////////////////////////////////////////////////////////////
Task("Default")
.IsDependentOn("Build")
.IsDependentOn("Run-Unit-Tests")
.IsDependentOn("Pack")
.IsDependentOn("NugetPublish");
//////////////////////////////////////////////////////////////////////
// EXECUTION
//////////////////////////////////////////////////////////////////////
RunTarget(target);