This repository has been archived by the owner on Apr 30, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 54
/
build.cake
146 lines (122 loc) · 4.23 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
#module nuget:https://api.nuget.org/v3/index.json?package=Cake.DotNetTool.Module&version=0.4.0
#tool dotnet:https://api.nuget.org/v3/index.json?package=GitVersion.Tool&version=5.3.7
#tool nuget:https://api.nuget.org/v3/index.json?package=vswhere&version=2.8.4
#addin nuget:https://api.nuget.org/v3/index.json?package=Cake.Figlet&version=1.3.1
var sln = new FilePath("./Cheesebaron.MvxPlugins.sln");
var outputDirArg = Argument("outputDir", "./artifacts");
var outputDir = new DirectoryPath(outputDirArg);
var target = Argument("target", "Default");
var configuration = Argument("configuration", "Release");
var verbosityArg = Argument("verbosity", "Minimal");
var verbosity = Verbosity.Minimal;
var gitVersionLog = new FilePath("./gitversion.log");
var isRunningOnPipelines = AzurePipelines.IsRunningOnAzurePipelines || AzurePipelines.IsRunningOnAzurePipelinesHosted;
GitVersion versionInfo = null;
Setup(context =>
{
versionInfo = context.GitVersion(new GitVersionSettings {
UpdateAssemblyInfo = true,
OutputType = GitVersionOutput.Json,
LogFilePath = gitVersionLog.MakeAbsolute(context.Environment)
});
if (isRunningOnPipelines)
{
var buildNumber = versionInfo.InformationalVersion + "-" + AzurePipelines.Environment.Build.Number;
buildNumber = buildNumber.Replace("/", "-");
AzurePipelines.Commands.UpdateBuildNumber(buildNumber);
}
var cakeVersion = typeof(ICakeContext).Assembly.GetName().Version.ToString();
Information(Figlet("MvxPlugins"));
Information("Building version {0}, ({1}, {2}) using version {3} of Cake.",
versionInfo.SemVer,
configuration,
target,
cakeVersion);
verbosity = (Verbosity) Enum.Parse(typeof(Verbosity), verbosityArg, true);
});
Task("Clean")
.Does(() =>
{
CleanDirectories("./**/bin");
CleanDirectories("./**/obj");
CleanDirectories(outputDir.FullPath);
EnsureDirectoryExists(outputDir);
});
FilePath msBuildPath;
Task("ResolveBuildTools")
.WithCriteria(() => IsRunningOnWindows())
.Does(() =>
{
var vsWhereSettings = new VSWhereLatestSettings
{
IncludePrerelease = true,
Requires = "Component.Xamarin"
};
var vsLatest = VSWhereLatest(vsWhereSettings);
msBuildPath = (vsLatest == null)
? null
: vsLatest.CombineWithFilePath("./MSBuild/Current/Bin/MSBuild.exe");
if (msBuildPath != null)
Information("Found MSBuild at {0}", msBuildPath.ToString());
});
Task("Restore")
.IsDependentOn("ResolveBuildTools")
.Does(() =>
{
var settings = GetDefaultBuildSettings()
.WithTarget("Restore");
MSBuild(sln, settings);
});
Task("Build")
.IsDependentOn("ResolveBuildTools")
.IsDependentOn("Clean")
.IsDependentOn("Restore")
.Does(() =>
{
var settings = GetDefaultBuildSettings()
.WithProperty("Version", versionInfo.SemVer)
.WithProperty("PackageVersion", versionInfo.SemVer)
.WithProperty("InformationalVersion", versionInfo.InformationalVersion)
.WithProperty("NoPackageAnalysis", "True")
.WithTarget("Build");
MSBuild(sln, settings);
});
Task("CopyArtifacts")
.IsDependentOn("Build")
.Does(() =>
{
var nugetFiles = GetFiles("*/bin/" + configuration + "/**/*.nupkg");
CopyFiles(nugetFiles, outputDir);
CopyFileToDirectory(gitVersionLog, outputDir);
});
Task("UploadArtifacts")
.IsDependentOn("CopyArtifacts")
.WithCriteria(() => isRunningOnPipelines)
.Does(() =>
{
AzurePipelines.Commands.UploadArtifactDirectory(outputDir);
});
Task("Default")
.IsDependentOn("Clean")
.IsDependentOn("ResolveBuildTools")
.IsDependentOn("Restore")
.IsDependentOn("Build")
.IsDependentOn("UploadArtifacts");
RunTarget(target);
MSBuildSettings GetDefaultBuildSettings()
{
var settings = new MSBuildSettings
{
Configuration = configuration,
ToolPath = msBuildPath,
Verbosity = verbosity,
ToolVersion = MSBuildToolVersion.VS2019
};
if (isRunningOnPipelines)
{
var javaSdkDir = EnvironmentVariable("JAVA_HOME_8_X64");
Information("Setting JavaSdkDirectory to: " + javaSdkDir);
settings = settings.WithProperty("JavaSdkDirectory", javaSdkDir);
}
return settings;
}