-
Notifications
You must be signed in to change notification settings - Fork 52
/
build.cake
175 lines (154 loc) · 5.34 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
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
///////////////////////////////////////////////////////////////////////////////
// ARGUMENTS
///////////////////////////////////////////////////////////////////////////////
var target = Argument("target", "Default");
var configuration = Argument("configuration", "Release");
///////////////////////////////////////////////////////////////////////////////
// TOOLS / ADDINS
///////////////////////////////////////////////////////////////////////////////
#tool "nuget:?package=xunit.runner.console&version=2.3.1"
#tool "nuget:?package=GitVersion.CommandLine&version=5.0.1"
#addin "nuget:?package=Cake.Incubator&version=5.1.0"
#addin "nuget:?package=Cake.Coverlet&version=2.3.4"
///////////////////////////////////////////////////////////////////////////////
// TASKS
///////////////////////////////////////////////////////////////////////////////
var isGitHubAction = !string.IsNullOrWhiteSpace(EnvironmentVariable("GITHUB_ACTION"));
var githubEventName = EnvironmentVariable("GITHUB_EVENT_NAME");
var githubRef = EnvironmentVariable("GITHUB_REF");
var githubBaseRef = EnvironmentVariable("GITHUB_BASE_REF");
var isPullRequest = githubEventName == "pull_request";
var isTag = githubEventName == "push" && githubRef.StartsWith("refs/tags/v");
Information($"EventName: {githubEventName}, Ref: {githubRef}, BaseRef: {githubBaseRef}, IsTag: {isTag}, IsGithubAction: {isGitHubAction}");
GitVersion gitVersion = null;
Task("Default")
.IsDependentOn("Build")
.IsDependentOn("Test")
.IsDependentOn("Deploy");
Task("Version")
.Does(() =>
{
gitVersion = GitVersion(new GitVersionSettings {
UpdateAssemblyInfo = true
});
Information(gitVersion.FullSemVer);
});
Task("Clean")
.Does(() =>
{
var settings = new DeleteDirectorySettings { Recursive = true };
DeleteDirectories(GetDirectories($"src/**/bin/{configuration}/"), settings);
DeleteDirectories(GetDirectories($"src/**/obj/{configuration}/"), settings);
});
Task("Restore")
.Does(() =>
{
NuGetRestore("src/Slack.Webhooks.sln", new NuGetRestoreSettings {
Verbosity = NuGetVerbosity.Quiet
});
});
Task("Build")
.IsDependentOn("Version")
.IsDependentOn("Clean")
.IsDependentOn("Restore")
.Does(() =>
{
DotNetCoreBuild("src/Slack.Webhooks.sln", new DotNetCoreBuildSettings
{
Configuration = configuration
});
});
Task("Pack")
.IsDependentOn("Build")
.Does(() =>
{
var nuGetPackSettings = new NuGetPackSettings {
Version = gitVersion.NuGetVersionV2,
OutputDirectory = "./artifacts"
};
NuGetPack("src/Slack.Webhooks/Slack.Webhooks.nuspec", nuGetPackSettings);
if(isGitHubAction)
{
var packageName = $"Slack.Webhooks.{gitVersion.NuGetVersionV2}";
Information($"##[set-output name=nupkg_name;]{packageName}");
Information($"##[set-output name=nupkg;]artifacts/{packageName}.nupkg");
}
});
Task("Deploy")
.IsDependentOn("DeployGPR")
.IsDependentOn("DeployNuGet");
Task("DeployGPR")
.IsDependentOn("Pack")
.Does(() =>
{
if(isGitHubAction && !isPullRequest)
{
Information($"DeployGPR. IsGitHubAction: {isGitHubAction}, IsPullRequest: {isPullRequest}");
var settings = new NuGetSourcesSettings
{
UserName = "mrb0nj",
Password = EnvironmentVariable("GITHUB_TOKEN"),
IsSensitiveSource = true,
Verbosity = NuGetVerbosity.Detailed
};
NuGetAddSource("GPR", "https://nuget.pkg.github.com/mrb0nj/index.json", settings);
NuGetPush($"artifacts/Slack.Webhooks.{gitVersion.NuGetVersionV2}.nupkg", new NuGetPushSettings {
Source = "GPR",
SkipDuplicate = true
});
}
else
{
Information($"Skipping DeployGPR. IsGitHubAction: {isGitHubAction}, IsPullRequest: {isPullRequest}");
}
});
Task("DeployNuGet")
.IsDependentOn("Pack")
.Does(() =>
{
if(isGitHubAction && isTag)
{
Information($"DeployNuget. IsGitHubAction: {isGitHubAction}, IsTag: {isTag}");
var settings = new NuGetPushSettings
{
Source = "https://api.nuget.org/v3/index.json",
ApiKey = EnvironmentVariable("NUGET_TOKEN")
};
NuGetPush($"artifacts/Slack.Webhooks.{gitVersion.NuGetVersionV2}.nupkg", settings);
}
else
{
Information($"Skipping DeployNuget. IsGitHubAction: {isGitHubAction}, IsTag: {isTag}");
}
});
Task("Test")
.IsDependentOn("TestFramework")
.IsDependentOn("TestCore");
Task("TestFramework")
.IsDependentOn("Build")
.Does(() =>
{
var testAssemblies = GetFiles($"./src/**/bin/{configuration}/net45/*.Tests.dll");
XUnit2(testAssemblies, new XUnit2Settings {
Parallelism = ParallelismOption.All,
NoAppDomain = true
});
});
Task("TestCore")
.IsDependentOn("Build")
.Does(() =>
{
var coverletSettings = new CoverletSettings {
CollectCoverage = true,
CoverletOutputFormat = CoverletOutputFormat.opencover,
CoverletOutputDirectory = Directory(@".\artifacts\"),
CoverletOutputName = $"coverlet-output"
};
DotNetCoreTest("./src/Slack.Webhooks.Tests/Slack.Webhooks.Tests.csproj", new DotNetCoreTestSettings
{
NoBuild = true,
Framework = "netcoreapp2",
Configuration = configuration
}, coverletSettings);
});
RunTarget(target);