forked from apereo/dotnet-cas-client
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.cake
192 lines (162 loc) · 5.97 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
#tool "nuget:?package=NUnit.ConsoleRunner&version=3.4.0"
#tool "nuget:?package=GitVersion.CommandLine&version=4.0.0"
#addin "nuget:?package=Cake.Incubator&version=4.0.2"
//////////////////////////////////////////////////////////////////////
// ARGUMENTS
//////////////////////////////////////////////////////////////////////
var target = Argument("target", "Default");
var configuration = Argument("configuration", "Release");
//////////////////////////////////////////////////////////////////////
// PREPARATION
//////////////////////////////////////////////////////////////////////
// Define directories.
var buildDir = Directory("./DotNetCasClient/bin/" + configuration);
var artifactDir = Directory("./artifacts");
// Define project metadata properties.
var projectOwners = "Apereo Foundation";
var projectName = "Apereo .NET CAS Client";
var projectDescription = ".NET client for the Apereo Central Authentication Service (CAS)";
var copyright = string.Format("Copyright (c) 2007-{0} Apereo. All rights reserved.", DateTime.Now.Year);
// Get/set version information.
var versionInfo = GitVersion();
var buildNumber = AppVeyor.Environment.Build.Number.ToString();
var buildNumberPadded = AppVeyor.Environment.Build.Number.ToString("00000");
var isAppveyorBuild = BuildSystem.IsRunningOnAppVeyor;
var assemblyVersion = string.Concat(new string[]{
versionInfo.Major.ToString(),
".",
versionInfo.Minor.ToString(),
".0.0"
});
var assemblyFileVersion = string.Concat(new string[]{
versionInfo.MajorMinorPatch,
".",
buildNumber
});
var assemblyInformationalVersion = versionInfo.InformationalVersion;
// Set NuGet version.
var nugetPackageVersion = "";
if (isAppveyorBuild)
{
// AppVeyor build.
var tag = AppVeyor.Environment.Repository.Tag;
if (tag.IsTag)
{
// Tag build. Used for stable and pre-release NuGet packages.
nugetPackageVersion = versionInfo.NuGetVersion;
}
else
{
// Regular commit build.
nugetPackageVersion = versionInfo.MajorMinorPatch + "-ci-" + buildNumberPadded;
if (AppVeyor.Environment.PullRequest.IsPullRequest)
{
nugetPackageVersion += "-pr-" + AppVeyor.Environment.PullRequest.Number;
}
}
AppVeyor.UpdateBuildVersion(nugetPackageVersion);
}
else
{
// Local developer machine build.
nugetPackageVersion = versionInfo.MajorMinorPatch + "-local-" + versionInfo.CommitsSinceVersionSource.Value.ToString().PadLeft(5, '0');
}
//////////////////////////////////////////////////////////////////////
// TASKS
//////////////////////////////////////////////////////////////////////
Task("Clean")
.Does(() =>
{
CleanDirectory(buildDir);
CleanDirectory(artifactDir);
});
Task("Version")
.IsDependentOn("Clean")
.Does(() =>
{
Information("Is AppVeyor Build: {0}", isAppveyorBuild);
if (isAppveyorBuild)
{
var tag = AppVeyor.Environment.Repository.Tag;
Information("Is AppVeyor Tag Build: {0}", tag.IsTag);
if (tag.IsTag)
{
Information("Tag Name: {0}", tag.Name);
}
}
Information("Assembly Version: {0}", assemblyVersion);
Information("Assembly File Version: {0}", assemblyFileVersion);
Information("Assembly Informational Version: {0}", assemblyInformationalVersion);
Information("Build Number: {0}", buildNumber);
Information("NuGet Version: {0}", nugetPackageVersion);
Information("VCS Revision: {0}", versionInfo.Sha);
Information("VCS Branch Name: {0}", versionInfo.BranchName);
Information("GitVersion Info:\r\n{0}", versionInfo.Dump());
var file = "./DotNetCasClient/Properties/AutoGeneratedAssemblyInfo.cs";
CreateAssemblyInfo(file, new AssemblyInfoSettings{
Product = projectName,
Title = projectName,
Description = projectDescription,
Company = projectOwners,
Version = assemblyVersion,
FileVersion = assemblyFileVersion,
InformationalVersion = assemblyInformationalVersion,
Copyright = copyright
});
});
Task("Restore-NuGet-Packages")
.IsDependentOn("Version")
.Does(() =>
{
NuGetRestore("./DotNetCasClient.sln");
});
Task("Build")
.IsDependentOn("Restore-NuGet-Packages")
.Does(() =>
{
if(IsRunningOnWindows())
{
// Use MSBuild
MSBuild("./DotNetCasClient.sln", settings =>
settings.SetConfiguration(configuration));
}
else
{
// Use XBuild
XBuild("./DotNetCasClient.sln", settings =>
settings.SetConfiguration(configuration));
}
});
Task("Pack")
.IsDependentOn("Build")
.Does(() =>
{
// Parse release notes.
var latestReleaseNote = ParseReleaseNotes("./ReleaseNotes.md");
var releaseNotes = new StringBuilder();
releaseNotes.AppendFormat("Version: {0}", latestReleaseNote.Version);
foreach(var note in latestReleaseNote.Notes)
{
releaseNotes.AppendFormat("\t{0}", note);
}
// Configure NuGet Pack settings.
var nuGetPackSettings = new NuGetPackSettings {
Version = nugetPackageVersion,
Title = projectName,
Owners = new []{projectOwners},
Copyright = copyright,
Description = projectDescription,
ReleaseNotes = new []{releaseNotes.ToString()},
OutputDirectory = artifactDir
};
NuGetPack("./DotNetCasClient/DotNetCasClient.nuspec", nuGetPackSettings);
});
//////////////////////////////////////////////////////////////////////
// TASK TARGETS
//////////////////////////////////////////////////////////////////////
Task("Default")
.IsDependentOn("Pack");
//////////////////////////////////////////////////////////////////////
// EXECUTION
//////////////////////////////////////////////////////////////////////
RunTarget(target);