forked from Inumedia/SlackAPI
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.cake
195 lines (163 loc) · 5.67 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
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
#tool "nuget:?package=GitVersion.CommandLine&version=5.1.3"
#addin "Cake.FileHelpers&version=3.2.1"
#addin "Cake.Incubator&version=5.1.0"
using System.Text.RegularExpressions;
var configuration = Argument("configuration", "Release");
var target = Argument("target", "Default");
var project = File("./SlackAPI/SlackApi.csproj");
var testProject = File("./SlackAPI.Tests/SlackApi.Tests.csproj");
var testConfig = File("./SlackAPI.Tests/Configuration/config.json");
var projects = new[] { project, testProject };
var artifactsDirectory = "./artifacts";
GitVersion gitVersion = null;
var isReleaseBuild = false;
Task("Clean")
.Does(() =>
{
CleanDirectory(artifactsDirectory);
});
Task("Configure")
.Does(() =>
{
gitVersion = GitVersion();
GitVersion(new GitVersionSettings {
UpdateAssemblyInfo = true,
UpdateAssemblyInfoFilePath = "GlobalAssemblyInfo.cs"
});
isReleaseBuild = AppVeyor.IsRunningOnAppVeyor
? AppVeyor.Environment.Repository.Branch == "master"
: false;
Information("Is release build: '{0}'", isReleaseBuild);
Information("GitVersion details:\n{0}", gitVersion.Dump());
if (AppVeyor.IsRunningOnAppVeyor)
{
var buildVersion = gitVersion.SemVer + ".ci." + AppVeyor.Environment.Build.Number;
Information("Using build version: {0}", buildVersion);
AppVeyor.UpdateBuildVersion(buildVersion);
}
});
Task("Build")
.IsDependentOn("Configure")
.Does(() =>
{
foreach(var project in projects)
{
DotNetCoreBuild(
project,
new DotNetCoreBuildSettings
{
Configuration = configuration
}
);
}
});
Task("ConfigureTest")
.Does(() =>
{
if (AppVeyor.IsRunningOnAppVeyor)
{
FileWriteText(testConfig, $@"
{{
""slack"":
{{
""userAuthToken"": ""{EnvironmentVariable("userAuthToken")}"",
""botAuthToken"": ""{EnvironmentVariable("botAuthToken")}"",
""testChannel"": ""{EnvironmentVariable("testChannel")}"",
""directMessageUser"": ""{EnvironmentVariable("directMessageUser")}"",
""clientId"": ""{EnvironmentVariable("clientId")}"",
""clientSecret"": ""{EnvironmentVariable("clientSecret")}"",
""redirectUrl"": ""{EnvironmentVariable("redirectUrl")}"",
""authUsername"": ""{EnvironmentVariable("authUsername")}"",
""authPassword"": ""{EnvironmentVariable("authPassword")}"",
""authWorkspace"": ""{EnvironmentVariable("authWorkspace")}""
}}
}}");
}
});
Task("Test")
.IsDependentOn("ConfigureTest")
.IsDependentOn("Build")
.Does(() =>
{
// AppVeyor is unable to differentiate tests from multiple frameworks
// To push all test results on AppVeyor:
// - disable builtin AppVeyor push from XUnit
// - generate MSTest report
// - replace assembly name in test report
// - manualy push test result
foreach (var framework in new[] { "net452", "netcoreapp2.1"})
{
DotNetCoreTest(
testProject,
new DotNetCoreTestSettings
{
Configuration = configuration,
Framework = framework,
ArgumentCustomization = args => args.Append("--logger \"trx;LogFileName=result_" + framework + ".trx\""),
EnvironmentVariables = new Dictionary<string, string>{
{ "APPVEYOR_API_URL", null }
}
}
);
if (AppVeyor.IsRunningOnAppVeyor)
{
var testResult = File("./SlackAPI.Tests/TestResults/result_" + framework + ".trx");
ReplaceRegexInFiles(
testResult,
@"slackapi\.tests\.dll",
"SlackAPI.Tests." + framework + ".dll",
RegexOptions.IgnoreCase);
AppVeyor.UploadTestResults(testResult, AppVeyorTestResultsType.MSTest);
}
}
});
Task("Package")
.IsDependentOn("Clean")
.IsDependentOn("Build")
.IsDependentOn("Test")
.Does(() =>
{
DotNetCorePack(
project,
new DotNetCorePackSettings
{
Configuration = configuration,
OutputDirectory = artifactsDirectory,
IncludeSymbols = !isReleaseBuild,
IncludeSource = !isReleaseBuild,
ArgumentCustomization = args => args.Append("/p:Version=\"" + gitVersion.NuGetVersion + "\"")
}
);
});
Task("Publish")
.IsDependentOn("Package")
.WithCriteria(() => AppVeyor.IsRunningOnAppVeyor && !AppVeyor.Environment.PullRequest.IsPullRequest, "Publishing is supported only from CI for non PR")
.Does(() =>
{
// Publish on Nuget if it's a release build or on MyGet for others builds
var mapping = new Dictionary<bool, (string token, string provider, string source)>
{
{ true, ("NUGET_APITOKEN", "NuGet", "https://nuget.org/api/v2/package") },
{ false, ("MYGET_APITOKEN", "MyGet", "https://www.myget.org/F/slackapi/api/v2") },
};
var config = mapping[isReleaseBuild];
var apiToken = EnvironmentVariable(config.token);
if (string.IsNullOrEmpty(apiToken))
{
Warning("{0} environment variable not found. Unable to push package on {1}", config.token, config.provider);
}
else
{
var packages = GetFiles(artifactsDirectory + "/**/*.nupkg");
NuGetPush(packages, new NuGetPushSettings
{
Source = config.source,
ApiKey = apiToken,
Verbosity = NuGetVerbosity.Detailed,
});
}
});
Task("Default")
.IsDependentOn("Package")
.IsDependentOn("Publish");
RunTarget(target);