forked from Marusyk/grok.net
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.cake
148 lines (130 loc) Β· 4.01 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
#addin nuget:?package=Cake.Coveralls&version=1.1.0
#addin nuget:?package=Cake.Coverlet&version=3.0.4
#addin nuget:?package=Cake.Powershell&version=2.0.0&loaddependencies=true
#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");
var psNugetApiKey = EnvironmentVariable("PS_NUGET_API_KEY");
DirectoryPath artifactsDir = Directory("./artifacts/");
var testResultsDir = artifactsDir.Combine("test-results");
var psModuleDir = artifactsDir.Combine("Grok");
var testCoverageOutputFilePath = testResultsDir.CombineWithFilePath("OpenCover.xml");
var projectFileMain = File("./src/Grok.Net/Grok.Net.csproj");
var projectFilePowerShell = File("./src/Grok.Net.PowerShell/Grok.Net.PowerShell.csproj");
Task("Clean")
.Does(() =>
{
CleanDirectory(artifactsDir);
CleanDirectories(GetDirectories("./**/obj") + GetDirectories("./**/bin"));
});
Task("Restore")
.IsDependentOn("Clean")
.Does(() =>
{
DotNetRestore(projectFileMain);
DotNetRestore(projectFilePowerShell);
});
Task("Build")
.IsDependentOn("Restore")
.Does(() =>
{
var settings = new DotNetBuildSettings
{
Configuration = configuration,
NoRestore = true,
NoLogo = true
};
DotNetBuild(projectFileMain, settings);
DotNetBuild(projectFilePowerShell, settings);
});
Task("Test")
.IsDependentOn("Build")
.Does(() =>
{
var settings = new DotNetTestSettings
{
Configuration = configuration,
NoLogo = true
};
DotNetTest("./src/Grok.Net.Tests/Grok.Net.Tests.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))
.WithCriteria((context) => !BuildSystem.IsPullRequest)
.WithCriteria((context) => !BuildSystem.IsLocalBuild)
.Does(() =>
{
CoverallsIo(testCoverageOutputFilePath, new CoverallsIoSettings
{
RepoToken = coverallsRepoToken,
Debug = true
});
});
Task("NuGetPack")
.IsDependentOn("Test")
.Does(() =>
{
DotNetPack(projectFileMain, new DotNetPackSettings
{
Configuration = configuration,
NoRestore = true,
NoBuild = true,
NoLogo = true,
OutputDirectory = artifactsDir
});
});
Task("NuGetPush")
.IsDependentOn("NuGetPack")
.WithCriteria(!string.IsNullOrWhiteSpace(nugetApiUrl))
.WithCriteria(!string.IsNullOrWhiteSpace(nugetApiKey))
.Does(() =>
{
var packages = GetFiles(string.Concat(artifactsDir, "/", "*.nupkg"));
DotNetNuGetPush(packages.First(), new DotNetNuGetPushSettings
{
Source = nugetApiUrl,
ApiKey = nugetApiKey
});
});
Task("PsModulePack")
.IsDependentOn("Test")
.Does(() =>
{
DotNetPublish(projectFilePowerShell, new DotNetPublishSettings
{
Configuration = configuration,
NoRestore = true,
NoBuild = true,
NoLogo = true,
OutputDirectory = psModuleDir
});
});
Task("PsModulePush")
.IsDependentOn("PsModulePack")
.WithCriteria(!string.IsNullOrWhiteSpace(psNugetApiKey))
.Does(() =>
{
StartPowershellScript("Publish-Module", new PowershellSettings()
.WithModule("PowerShellGet")
.BypassExecutionPolicy()
.WithArguments(args =>
{
args.Append("Path", psModuleDir.FullPath)
.AppendSecret("NuGetApiKey", psNugetApiKey)
.Append("Force", "");
}));
});
Task("Default")
.IsDependentOn("Test");
RunTarget(target);