-
Notifications
You must be signed in to change notification settings - Fork 20
/
Copy pathbuild.cake
106 lines (92 loc) · 2.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
#addin nuget:?package=Cake.Coveralls&version=1.0.0
#addin nuget:?package=Cake.Coverlet&version=2.5.4
#tool nuget:?package=coveralls.io&version=1.4.2
var target = Argument("Target", "Default");
var configuration = Argument("Configuration", "Release");
var coverallsRepoToken = EnvironmentVariable("COVERALLS_REPO_TOKEN");
var nugetApiKey = EnvironmentVariable("NUGET_API_KEY");
var nugetApiUrl = EnvironmentVariable("NUGET_API_URL");
DirectoryPath artifactsDirectory = Directory("./artifacts");
var projectFile = File("./src/BinaryTree/BinaryTree.csproj");
var testResultsDir = artifactsDirectory.Combine("test-results");
var testCoverageOutputFilePath = testResultsDir.CombineWithFilePath("OpenCover.xml");
Task("Clean")
.Does(() =>
{
CleanDirectory(artifactsDirectory);
CleanDirectories(GetDirectories("./**/obj") + GetDirectories("./**/bin"));
});
Task("Restore")
.IsDependentOn("Clean")
.Does(() =>
{
DotNetRestore(projectFile);
});
Task("Build")
.IsDependentOn("Restore")
.Does(() =>
{
DotNetBuild(projectFile, new DotNetCoreBuildSettings
{
Configuration = configuration,
NoRestore = true,
NoLogo = true
});
});
Task("Test")
.IsDependentOn("Build")
.Does(() =>
{
var settings = new DotNetCoreTestSettings
{
Configuration = configuration,
NoLogo = true
};
DotNetCoreTest("./tests/BinaryTreeTest/BinaryTreeTest.csproj", settings, new CoverletSettings
{
CollectCoverage = true,
CoverletOutputFormat = CoverletOutputFormat.opencover,
CoverletOutputDirectory = testResultsDir,
CoverletOutputName = testCoverageOutputFilePath.GetFilename().ToString()
});
});
Task("UploadTestReport")
.IsDependentOn("Test")
.WithCriteria((context) => FileExists(testCoverageOutputFilePath))
.WithCriteria(!string.IsNullOrWhiteSpace(coverallsRepoToken))
.Does(() =>
{
CoverallsIo(testCoverageOutputFilePath, new CoverallsIoSettings
{
RepoToken = coverallsRepoToken,
Debug = true
});
});
Task("NuGetPack")
.IsDependentOn("UploadTestReport")
.Does(() =>
{
DotNetPack(projectFile, new DotNetCorePackSettings
{
Configuration = configuration,
NoRestore = true,
NoBuild = true,
NoLogo = true,
OutputDirectory = artifactsDirectory
});
});
Task("NuGetPush")
.IsDependentOn("NuGetPack")
.WithCriteria(!string.IsNullOrWhiteSpace(nugetApiUrl))
.WithCriteria(!string.IsNullOrWhiteSpace(nugetApiKey))
.Does(() =>
{
DotNetNuGetPush(artifactsDirectory.CombineWithFilePath("*.nupkg").FullPath, new DotNetCoreNuGetPushSettings
{
Source = nugetApiUrl,
ApiKey = nugetApiKey
});
});
Task("Default")
.IsDependentOn("Test");
RunTarget(target);