This repository has been archived by the owner on Feb 20, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 24
/
Copy pathbuild.cake
140 lines (119 loc) · 4.22 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
#addin "nuget:?package=Cake.ExtendedNuGet&version=1.0.0.27"
#addin "nuget:?package=NuGet.Core"
#addin "nuget:?package=Cake.Codecov"
#addin "nuget:?package=Cake.Figlet"
#tool "nuget:?package=xunit.runner.console"
#tool "nuget:?package=JetBrains.dotCover.CommandLineTools"
#tool "nuget:?package=Codecov"
#l "common.cake"
using NuGet;
//////////////////////////////////////////////////////////////////////
// ARGUMENTS
//////////////////////////////////////////////////////////////////////
var projectName = "EPPlus.Core.Extensions";
var solution = "./" + projectName + ".sln";
var testProject = GetFiles($"./test/**/*{projectName}.Tests.csproj").First();
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 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
//////////////////////////////////////////////////////////////////////
Setup(context =>
{
Information(Figlet(projectName));
});
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(() =>
{
DotNetCoreRestore(solution);
});
Task("Build")
.IsDependentOn("Restore-NuGet-Packages")
.Does(() =>
{
DotNetCoreBuild(solution, new DotNetCoreBuildSettings{Configuration = configuration});
});
Task("Run-Unit-Tests")
.IsDependentOn("Build")
.Does(() =>
{
DotCoverAnalyse(tool =>
tool.DotNetCoreTest(testProject.FullPath, new DotNetCoreTestSettings { Configuration = configuration }),
new FilePath("./coverage.xml"),
new DotCoverAnalyseSettings { ReportType = DotCoverReportType.DetailedXML }
.WithFilter("+:EPPlus.Core.Extensions")
.WithFilter("-:EPPlus.Core.Extensions.Tests")
);
});
Task("Upload-Coverage")
.IsDependentOn("Run-Unit-Tests")
.WithCriteria(() => !AppVeyor.Environment.PullRequest.IsPullRequest)
.Does(() =>
{
Codecov(new CodecovSettings {
Files = new[] { "./coverage.xml" },
Token = EnvironmentVariable("COVERALLS_REPO_TOKEN"),
Branch = branch
});
});
Task("Pack")
.IsDependentOn("Upload-Coverage")
.WithCriteria(() => branch == "master" && !AppVeyor.Environment.PullRequest.IsPullRequest)
.Does(() =>
{
var nupkgFiles = GetFiles(nupkgRegex);
MoveFiles(nupkgFiles, nupkgPath);
});
Task("NugetPublish")
.IsDependentOn("Pack")
.WithCriteria(() => branch == "master" && !AppVeyor.Environment.PullRequest.IsPullRequest)
.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);