This repository has been archived by the owner on Apr 18, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
build.cake
139 lines (119 loc) · 4.02 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
#tool "nuget:?package=xunit.runner.console"
#addin "nuget:?package=Cake.Nuget"
#addin "nuget:?package=NuGet.Core"
#addin "nuget:?package=Cake.ExtendedNuGet"
//////////////////////////////////////////////////////////////////////
// ARGUMENTS
//////////////////////////////////////////////////////////////////////
var projectName = "Cake.OctoVariapus";
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 targetTestFramework = "netcoreapp1.0";
var testFileRegex = $"**/bin/{configuration}/{targetTestFramework}/*Tests*.dll";
var testProjectNames = new List<string>()
{
"Cake.OctoVariapus.Tests"
};
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"));
CleanDirectories("./src/**/bin");
CleanDirectories("./src/**/obj");
CleanDirectory(nupkgPath);
});
Task("Restore-NuGet-Packages")
.IsDependentOn("Clean")
.Does(() =>
{
NuGetRestore(solution, new NuGetRestoreSettings
{
NoCache = true,
Verbosity = NuGetVerbosity.Detailed,
ToolPath = nugetPath
});
});
Task("Build")
.IsDependentOn("Restore-NuGet-Packages")
.Does(() =>
{
DotNetBuild(solution, c=> c.Configuration = configuration);
});
Task("Run-Unit-Tests")
.IsDependentOn("Build")
.Does(() =>
{
// foreach(var testProject in testProjectNames)
// {
// var testFile = GetFiles($"**/bin/{configuration}/{targetTestFramework}/{testProject}*.dll").First();
// Information(testFile);
// XUnit2(testFile.ToString(), new XUnit2Settings { });
// }
});
Task("Coverage")
.IsDependentOn("Run-Unit-Tests")
.Does(()=>
{
Information("Coverage...");
});
Task("Analyse")
.IsDependentOn("Coverage")
.Does(()=>
{
Information("Sonar running!...");
});
Task("Pack")
.IsDependentOn("Analyse")
.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);