-
Notifications
You must be signed in to change notification settings - Fork 7
/
build.cake
140 lines (123 loc) · 4.11 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
// ARGUMENTS
var target = Argument("Target", "Default");
var configuration = Argument("Configuration", "Release");
var nugetApiKey = Argument("NugetApiKey", "");
// GLOBAL VARIABLES
var artifactsDirectory = Directory("./artifacts");
var solutionFile = "./Simple.HttpPatch.sln";
var solutionFileBackup = solutionFile + ".build.backup";
var isRunningOnWindows = IsRunningOnWindows();
var IsOnAppVeyorAndNotPR = AppVeyor.IsRunningOnAppVeyor && !AppVeyor.Environment.PullRequest.IsPullRequest;
Setup(_ =>
{
StartProcess("dotnet", new ProcessSettings { Arguments = "--info" });
if(!isRunningOnWindows)
{
StartProcess("mono", new ProcessSettings { Arguments = "--version" });
// create solution backup
CopyFile(solutionFile, solutionFileBackup);
}
});
Teardown(_ =>
{
if(!isRunningOnWindows && BuildSystem.IsLocalBuild)
{
if(FileExists(solutionFileBackup)) // Revert back solution file
{
DeleteFile(solutionFile);
MoveFile(solutionFileBackup, solutionFile);
}
}
});
Task("Clean")
.Does(() =>
{
CleanDirectory(artifactsDirectory);
if(BuildSystem.IsLocalBuild)
{
CleanDirectories(GetDirectories("./**/obj") + GetDirectories("./**/bin"));
}
});
Task("Restore")
.IsDependentOn("Clean")
.Does(() =>
{
DotNetCoreRestore(solutionFile);
});
Task("Build")
.IsDependentOn("Restore")
.Does(() =>
{
var buildSettings = new MSBuildSettings()
.SetConfiguration(configuration)
.WithTarget("Rebuild")
.SetVerbosity(Verbosity.Minimal)
.UseToolVersion(MSBuildToolVersion.Default)
.SetMSBuildPlatform(MSBuildPlatform.Automatic)
.SetPlatformTarget(PlatformTarget.MSIL) // Any CPU
.SetNodeReuse(true);
if(!isRunningOnWindows)
{
// hack for Linux bug - missing MSBuild path
if(new CakePlatform().Family == PlatformFamily.Linux)
{
var monoVersion = GetMonoVersionMoniker();
var isMSBuildSupported = monoVersion != null && System.Text.RegularExpressions.Regex.IsMatch(monoVersion,@"([5-9]|\d{2,})\.\d+\.\d+(\.\d+)?");
if(isMSBuildSupported)
{
buildSettings.ToolPath = new FilePath(@"/usr/lib/mono/msbuild/15.0/bin/MSBuild.dll");
Information(string.Format("Mono supports MSBuild. Override ToolPath value with `{0}`", buildSettings.ToolPath));
}
}
}
var path = MakeAbsolute(new DirectoryPath(solutionFile));
MSBuild(path.FullPath, buildSettings);
});
Task("Pack")
.IsDependentOn("Restore")
.WithCriteria(IsOnAppVeyorAndNotPR || !string.IsNullOrEmpty(nugetApiKey))
.Does(() =>
{
var settings = new DotNetCorePackSettings
{
Configuration = configuration,
OutputDirectory = artifactsDirectory
};
var projects = GetFiles("./src/**/*.csproj");
foreach(var project in projects)
{
DotNetCorePack(project.FullPath, settings);
}
});
Task("Publish")
.IsDependentOn("Pack")
.WithCriteria(IsOnAppVeyorAndNotPR || !string.IsNullOrEmpty(nugetApiKey))
.Does(() =>
{
var dir = string.Concat(artifactsDirectory, @"\*.nupkg");
NuGetPush(GetFiles(dir).First(), new NuGetPushSettings {
Source = "https://www.nuget.org/api/v2/package",
ApiKey = nugetApiKey
});
});
Task("Default")
.IsDependentOn("Clean")
.IsDependentOn("Restore")
.IsDependentOn("Build")
.IsDependentOn("Pack")
.IsDependentOn("Publish");
RunTarget(target);
// HELPERS
private string GetMonoVersionMoniker()
{
var type = Type.GetType("Mono.Runtime");
if (type != null)
{
var displayName = type.GetMethod("GetDisplayName", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Static);
if (displayName != null)
{
return displayName.Invoke(null, null).ToString();
}
}
return null;
}