forked from cake-contrib/Cake.Slack
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.cake
194 lines (170 loc) · 7.49 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
///////////////////////////////////////////////////////////////////////////////
// ARGUMENTS
///////////////////////////////////////////////////////////////////////////////
var target = Argument<string>("target", "Default");
var configuration = Argument<string>("configuration", "Release");
///////////////////////////////////////////////////////////////////////////////
// GLOBAL VARIABLES
///////////////////////////////////////////////////////////////////////////////
var slackChannel = "#cake";
var isLocalBuild = !AppVeyor.IsRunningOnAppVeyor;
var isPullRequest = AppVeyor.Environment.PullRequest.IsPullRequest;
var solutions = GetFiles("./**/*.sln");
var solutionPaths = solutions.Select(solution => solution.GetDirectory());
var releaseNotes = ParseReleaseNotes("./ReleaseNotes.md");
var version = releaseNotes.Version.ToString();
var binDir = "./src/Cake.Slack/bin/" + configuration;
var nugetRoot = "./nuget/";
var semVersion = isLocalBuild
? version
: string.Concat(version, "-build-", AppVeyor.Environment.Build.Number);
var assemblyInfo = new AssemblyInfoSettings {
Title = "Cake.Slack",
Description = "Cake Slack AddIn",
Product = "Cake.Slack",
Company = "WCOM AB",
Version = version,
FileVersion = version,
InformationalVersion = semVersion,
Copyright = string.Format("Copyright © WCOM AB {0}", DateTime.Now.Year),
CLSCompliant = true
};
var nuGetPackSettings = new NuGetPackSettings {
Id = assemblyInfo.Product,
Version = assemblyInfo.InformationalVersion,
Title = assemblyInfo.Title,
Authors = new[] {assemblyInfo.Company},
Owners = new[] {assemblyInfo.Company},
Description = assemblyInfo.Description,
Summary = "Cake AddIn that extends Cake with Slack messaging features",
ProjectUrl = new Uri("https://github.com/WCOMAB/Cake.Slack/"),
IconUrl = new Uri("https://cdn.rawgit.com/cake-contrib/graphics/a5cf0f881c390650144b2243ae551d5b9f836196/png/cake-contrib-medium.png"),
LicenseUrl = new Uri("https://github.com/WCOMAB/Cake.Slack/blob/master/LICENSE"),
Copyright = assemblyInfo.Copyright,
ReleaseNotes = releaseNotes.Notes.ToArray(),
Tags = new [] {"Cake", "Script", "Build", "Slack"},
RequireLicenseAcceptance= false,
Symbols = false,
NoPackageAnalysis = true,
Files = new [] {
new NuSpecContent {Source = "Cake.Slack.dll", Target = "lib\\net46"},
new NuSpecContent {Source = "Cake.Slack.pdb", Target = "lib\\net46"},
new NuSpecContent {Source = "Cake.Slack.xml", Target = "lib\\net46"}
},
BasePath = binDir,
OutputDirectory = nugetRoot
};
if (!isLocalBuild)
{
AppVeyor.UpdateBuildVersion(semVersion);
}
///////////////////////////////////////////////////////////////////////////////
// SETUP / TEARDOWN
///////////////////////////////////////////////////////////////////////////////
Setup(context =>
{
// Executed BEFORE the first task.
Information("Running tasks...");
var buildStartMessage = string.Format(
"Building version {0} of {1} ({2}).",
version,
assemblyInfo.Product,
semVersion
);
Information(buildStartMessage);
});
Teardown(context =>
{
// Executed AFTER the last task.
Information("Finished running tasks.");
});
///////////////////////////////////////////////////////////////////////////////
// TASK DEFINITIONS
///////////////////////////////////////////////////////////////////////////////
Task("Clean")
.Does(() =>
{
// Clean solution directories.
foreach(var path in solutionPaths)
{
Information("Cleaning {0}", path);
CleanDirectories(path + "/**/bin/" + configuration);
CleanDirectories(path + "/**/obj/" + configuration);
}
});
Task("Restore")
.Does(() =>
{
// Restore all NuGet packages.
foreach(var solution in solutions)
{
Information("Restoring {0}...", solution);
NuGetRestore(solution);
}
});
Task("SolutionInfo")
.IsDependentOn("Clean")
.IsDependentOn("Restore")
.Does(() =>
{
var file = "./src/SolutionInfo.cs";
CreateAssemblyInfo(file, assemblyInfo);
});
Task("Build")
.IsDependentOn("Clean")
.IsDependentOn("Restore")
.IsDependentOn("SolutionInfo")
.Does(() =>
{
// Build all solutions.
foreach(var solution in solutions)
{
Information("Building {0}", solution);
MSBuild(solution, settings =>
settings.SetPlatformTarget(PlatformTarget.MSIL)
.WithProperty("TreatWarningsAsErrors","true")
.WithTarget("Build")
.SetConfiguration(configuration));
}
});
Task("Create-NuGet-Package")
.IsDependentOn("Build")
.Does(() =>
{
if (!DirectoryExists(nugetRoot))
{
CreateDirectory(nugetRoot);
}
NuGetPack(nuGetPackSettings);
});
Task("Publish-MyGet")
.IsDependentOn("Create-NuGet-Package")
.WithCriteria(() => !isLocalBuild)
.WithCriteria(() => !isPullRequest)
.Does(() =>
{
// Resolve the API key.
var apiKey = EnvironmentVariable("MYGET_API_KEY");
if(string.IsNullOrEmpty(apiKey)) {
throw new InvalidOperationException("Could not resolve MyGet API key.");
}
var source = EnvironmentVariable("MYGET_SOURCE");
if(string.IsNullOrEmpty(apiKey)) {
throw new InvalidOperationException("Could not resolve MyGet source.");
}
// Get the path to the package.
var package = nugetRoot + "Cake.Slack." + semVersion + ".nupkg";
// Push the package.
NuGetPush(package, new NuGetPushSettings {
Source = source,
ApiKey = apiKey
});
});
Task("Default")
.IsDependentOn("Create-NuGet-Package");
Task("AppVeyor")
.IsDependentOn("Publish-MyGet");
///////////////////////////////////////////////////////////////////////////////
// EXECUTION
///////////////////////////////////////////////////////////////////////////////
RunTarget(target);