2017-04-15 16:42:24 +03:00
|
|
|
#tool nuget:?package=GitVersion.CommandLine
|
2017-08-15 23:04:47 +03:00
|
|
|
#tool nuget:?package=vswhere
|
2018-02-12 15:11:25 +03:00
|
|
|
#addin nuget:?package=Cake.Figlet
|
2018-01-31 23:04:47 +03:00
|
|
|
#addin nuget:?package=Cake.Incubator&version=1.7.1
|
2018-02-05 00:19:05 +03:00
|
|
|
#addin nuget:?package=Cake.Git&version=0.16.1
|
2017-12-12 22:54:57 +03:00
|
|
|
#addin nuget:?package=Polly
|
|
|
|
|
|
|
|
using Polly;
|
2017-01-19 22:18:02 +03:00
|
|
|
|
2018-04-02 15:35:05 +03:00
|
|
|
var solutionName = "MvvmCross";
|
|
|
|
var repoName = "mvvmcross/mvvmcross";
|
|
|
|
var sln = new FilePath("./" + solutionName + ".sln");
|
2018-01-31 23:04:47 +03:00
|
|
|
var outputDir = new DirectoryPath("./artifacts");
|
|
|
|
var nuspecDir = new DirectoryPath("./nuspec");
|
2017-01-19 22:18:02 +03:00
|
|
|
var target = Argument("target", "Default");
|
2018-01-15 23:49:39 +03:00
|
|
|
var configuration = Argument("configuration", "Release");
|
2018-03-14 21:53:05 +03:00
|
|
|
var verbosityArg = Argument("verbosity", "Minimal");
|
|
|
|
var verbosity = Verbosity.Minimal;
|
2017-01-19 22:18:02 +03:00
|
|
|
|
2017-01-22 18:39:32 +03:00
|
|
|
var isRunningOnAppVeyor = AppVeyor.IsRunningOnAppVeyor;
|
2018-02-12 15:11:25 +03:00
|
|
|
GitVersion versionInfo = null;
|
2017-01-22 18:39:32 +03:00
|
|
|
|
2018-02-12 15:11:25 +03:00
|
|
|
Setup(context => {
|
|
|
|
versionInfo = context.GitVersion(new GitVersionSettings {
|
2017-11-08 16:09:10 +03:00
|
|
|
UpdateAssemblyInfo = true,
|
|
|
|
OutputType = GitVersionOutput.Json
|
|
|
|
});
|
2017-01-19 22:18:02 +03:00
|
|
|
|
2018-02-12 15:11:25 +03:00
|
|
|
if (isRunningOnAppVeyor)
|
|
|
|
{
|
|
|
|
var buildNumber = AppVeyor.Environment.Build.Number;
|
|
|
|
AppVeyor.UpdateBuildVersion(versionInfo.InformationalVersion
|
|
|
|
+ "-" + buildNumber);
|
|
|
|
}
|
|
|
|
|
|
|
|
var cakeVersion = typeof(ICakeContext).Assembly.GetName().Version.ToString();
|
|
|
|
|
2018-04-02 15:35:05 +03:00
|
|
|
Information(Figlet(solutionName));
|
2018-02-12 15:11:25 +03:00
|
|
|
Information("Building version {0}, ({1}, {2}) using version {3} of Cake.",
|
|
|
|
versionInfo.SemVer,
|
|
|
|
configuration,
|
|
|
|
target,
|
|
|
|
cakeVersion);
|
|
|
|
|
|
|
|
Debug("Will push NuGet packages {0}",
|
|
|
|
ShouldPushNugetPackages(versionInfo.BranchName));
|
2018-03-14 21:53:05 +03:00
|
|
|
|
|
|
|
verbosity = (Verbosity) Enum.Parse(typeof(Verbosity), verbosityArg, true);
|
2017-01-19 22:18:02 +03:00
|
|
|
});
|
|
|
|
|
2018-02-12 15:11:25 +03:00
|
|
|
Task("Clean").Does(() =>
|
2017-01-22 18:39:32 +03:00
|
|
|
{
|
2018-02-12 15:11:25 +03:00
|
|
|
CleanDirectories("./**/bin");
|
|
|
|
CleanDirectories("./**/obj");
|
|
|
|
CleanDirectories(outputDir.FullPath);
|
|
|
|
|
|
|
|
EnsureDirectoryExists(outputDir);
|
2017-01-22 18:39:32 +03:00
|
|
|
});
|
|
|
|
|
2017-04-15 16:42:24 +03:00
|
|
|
FilePath msBuildPath;
|
|
|
|
Task("ResolveBuildTools")
|
2018-01-16 00:18:44 +03:00
|
|
|
.WithCriteria(() => IsRunningOnWindows())
|
2017-11-08 16:09:10 +03:00
|
|
|
.Does(() =>
|
2017-04-15 16:42:24 +03:00
|
|
|
{
|
2017-11-08 16:09:10 +03:00
|
|
|
var vsLatest = VSWhereLatest();
|
|
|
|
msBuildPath = (vsLatest == null)
|
|
|
|
? null
|
|
|
|
: vsLatest.CombineWithFilePath("./MSBuild/15.0/Bin/MSBuild.exe");
|
2017-04-15 16:42:24 +03:00
|
|
|
});
|
|
|
|
|
|
|
|
Task("Restore")
|
2017-11-08 16:09:10 +03:00
|
|
|
.IsDependentOn("ResolveBuildTools")
|
2018-03-16 10:10:08 +03:00
|
|
|
.Does(() =>
|
|
|
|
{
|
|
|
|
var settings = GetDefaultBuildSettings()
|
|
|
|
.WithTarget("Restore");
|
|
|
|
MSBuild(sln, settings);
|
2017-01-19 22:18:02 +03:00
|
|
|
});
|
|
|
|
|
2018-02-05 16:53:33 +03:00
|
|
|
Task("PatchBuildProps")
|
|
|
|
.Does(() =>
|
|
|
|
{
|
|
|
|
var buildProp = new FilePath("./Directory.build.props");
|
|
|
|
XmlPoke(buildProp, "//Project/PropertyGroup/Version", versionInfo.SemVer);
|
|
|
|
});
|
|
|
|
|
2017-01-19 22:18:02 +03:00
|
|
|
Task("Build")
|
2017-11-08 16:09:10 +03:00
|
|
|
.IsDependentOn("ResolveBuildTools")
|
|
|
|
.IsDependentOn("Clean")
|
2018-02-05 16:53:33 +03:00
|
|
|
.IsDependentOn("PatchBuildProps")
|
2017-11-08 16:09:10 +03:00
|
|
|
.IsDependentOn("Restore")
|
|
|
|
.Does(() => {
|
|
|
|
|
2018-03-16 10:10:08 +03:00
|
|
|
var settings = GetDefaultBuildSettings()
|
2018-01-15 23:49:39 +03:00
|
|
|
.WithProperty("DebugSymbols", "True")
|
|
|
|
.WithProperty("DebugType", "Embedded")
|
2018-02-05 16:53:33 +03:00
|
|
|
.WithProperty("Version", versionInfo.SemVer)
|
|
|
|
.WithProperty("PackageVersion", versionInfo.SemVer)
|
2018-02-05 00:19:05 +03:00
|
|
|
.WithProperty("InformationalVersion", versionInfo.InformationalVersion)
|
2018-01-15 23:49:39 +03:00
|
|
|
.WithProperty("NoPackageAnalysis", "True");
|
2017-11-08 16:09:10 +03:00
|
|
|
|
|
|
|
MSBuild(sln, settings);
|
2017-01-19 22:18:02 +03:00
|
|
|
});
|
|
|
|
|
2017-06-11 15:12:07 +03:00
|
|
|
Task("UnitTest")
|
2017-11-08 16:09:10 +03:00
|
|
|
.IsDependentOn("Build")
|
|
|
|
.Does(() =>
|
2017-06-11 15:12:07 +03:00
|
|
|
{
|
2018-01-31 23:04:47 +03:00
|
|
|
EnsureDirectoryExists(outputDir + "/Tests/");
|
2017-06-11 15:12:07 +03:00
|
|
|
|
2018-02-05 19:20:02 +03:00
|
|
|
var testPaths = GetFiles("./UnitTests/*.UnitTest/*.UnitTest.csproj");
|
2018-01-31 23:26:48 +03:00
|
|
|
var testsFailed = false;
|
2018-01-31 23:04:47 +03:00
|
|
|
foreach(var project in testPaths)
|
2018-01-30 23:59:55 +03:00
|
|
|
{
|
2018-01-31 23:04:47 +03:00
|
|
|
var projectName = project.GetFilenameWithoutExtension();
|
|
|
|
var testXml = new FilePath(outputDir + "/Tests/" + projectName + ".xml").MakeAbsolute(Context.Environment);
|
|
|
|
try
|
|
|
|
{
|
|
|
|
DotNetCoreTool(project,
|
|
|
|
"xunit", "-fxversion 2.0.0 --no-build -parallel none -configuration " +
|
|
|
|
configuration + " -xml \"" + testXml.FullPath + "\"");
|
|
|
|
}
|
|
|
|
catch
|
|
|
|
{
|
2018-01-31 23:26:48 +03:00
|
|
|
testsFailed = true;
|
2018-01-31 23:04:47 +03:00
|
|
|
}
|
|
|
|
}
|
2017-08-17 16:41:28 +03:00
|
|
|
|
|
|
|
if (isRunningOnAppVeyor)
|
|
|
|
{
|
2018-01-15 23:49:39 +03:00
|
|
|
foreach(var testResult in GetFiles(outputDir + "/Tests/*.xml"))
|
2018-01-30 23:59:55 +03:00
|
|
|
AppVeyor.UploadTestResults(testResult, AppVeyorTestResultsType.XUnit);
|
2017-11-08 16:09:10 +03:00
|
|
|
}
|
2018-01-31 23:26:48 +03:00
|
|
|
|
|
|
|
if (testsFailed)
|
|
|
|
throw new Exception("Tests failed :(");
|
2017-01-19 22:18:02 +03:00
|
|
|
});
|
|
|
|
|
2017-01-22 18:39:32 +03:00
|
|
|
Task("PublishPackages")
|
2017-04-23 21:58:54 +03:00
|
|
|
.WithCriteria(() => !BuildSystem.IsLocalBuild)
|
2018-04-02 15:35:05 +03:00
|
|
|
.WithCriteria(() => IsRepository(repoName))
|
2018-02-12 15:11:25 +03:00
|
|
|
.WithCriteria(() => ShouldPushNugetPackages(versionInfo.BranchName))
|
2017-01-22 18:39:32 +03:00
|
|
|
.Does (() =>
|
|
|
|
{
|
2017-11-08 16:09:10 +03:00
|
|
|
// Resolve the API key.
|
|
|
|
var nugetKeySource = GetNugetKeyAndSource();
|
|
|
|
var apiKey = nugetKeySource.Item1;
|
|
|
|
var source = nugetKeySource.Item2;
|
2017-01-22 18:39:32 +03:00
|
|
|
|
2018-04-02 15:35:05 +03:00
|
|
|
var nugetFiles = GetFiles(solutionName + "*/**/bin/" + configuration + "/**/*.nupkg");
|
2017-01-22 18:39:32 +03:00
|
|
|
|
2017-12-12 22:54:57 +03:00
|
|
|
var policy = Policy
|
2018-02-12 15:11:25 +03:00
|
|
|
.Handle<Exception>()
|
2018-01-15 23:49:39 +03:00
|
|
|
.WaitAndRetry(5, retryAttempt =>
|
|
|
|
TimeSpan.FromSeconds(Math.Pow(1.5, retryAttempt)));
|
2017-12-12 22:54:57 +03:00
|
|
|
|
2017-11-08 16:09:10 +03:00
|
|
|
foreach(var nugetFile in nugetFiles)
|
|
|
|
{
|
2017-12-12 22:54:57 +03:00
|
|
|
policy.Execute(() =>
|
|
|
|
NuGetPush(nugetFile, new NuGetPushSettings {
|
|
|
|
Source = source,
|
|
|
|
ApiKey = apiKey
|
|
|
|
})
|
|
|
|
);
|
2017-11-08 16:09:10 +03:00
|
|
|
}
|
2017-01-22 18:39:32 +03:00
|
|
|
});
|
|
|
|
|
2017-06-19 10:50:28 +03:00
|
|
|
Task("UploadAppVeyorArtifact")
|
2017-11-08 16:09:10 +03:00
|
|
|
.WithCriteria(() => isRunningOnAppVeyor)
|
2018-03-16 10:10:08 +03:00
|
|
|
.Does(() =>
|
|
|
|
{
|
2017-06-19 10:50:28 +03:00
|
|
|
|
2017-11-08 16:09:10 +03:00
|
|
|
Information("Artifacts Dir: {0}", outputDir.FullPath);
|
2017-06-19 10:50:28 +03:00
|
|
|
|
2017-12-12 23:07:20 +03:00
|
|
|
var uploadSettings = new AppVeyorUploadArtifactsSettings();
|
|
|
|
|
2018-04-02 15:35:05 +03:00
|
|
|
var artifacts = GetFiles(solutionName + "*/**/bin/" + configuration + "/**/*.nupkg")
|
2018-01-15 23:49:39 +03:00
|
|
|
+ GetFiles(outputDir.FullPath + "/**/*");
|
|
|
|
|
|
|
|
foreach(var file in artifacts) {
|
2017-11-08 16:09:10 +03:00
|
|
|
Information("Uploading {0}", file.FullPath);
|
2017-12-12 23:07:20 +03:00
|
|
|
|
2018-03-16 10:10:43 +03:00
|
|
|
if (file.GetExtension().Contains("nupkg"))
|
2017-12-12 23:07:20 +03:00
|
|
|
uploadSettings.ArtifactType = AppVeyorUploadArtifactType.NuGetPackage;
|
|
|
|
else
|
|
|
|
uploadSettings.ArtifactType = AppVeyorUploadArtifactType.Auto;
|
|
|
|
|
|
|
|
AppVeyor.UploadArtifact(file.FullPath, uploadSettings);
|
2017-11-08 16:09:10 +03:00
|
|
|
}
|
2017-06-19 10:50:28 +03:00
|
|
|
});
|
|
|
|
|
2017-01-19 22:18:02 +03:00
|
|
|
Task("Default")
|
2018-01-15 23:49:39 +03:00
|
|
|
.IsDependentOn("Build")
|
2018-01-30 23:59:55 +03:00
|
|
|
.IsDependentOn("UnitTest")
|
2017-11-08 16:09:10 +03:00
|
|
|
.IsDependentOn("PublishPackages")
|
|
|
|
.IsDependentOn("UploadAppVeyorArtifact")
|
|
|
|
.Does(() =>
|
2017-04-24 00:05:44 +03:00
|
|
|
{
|
2017-04-23 22:36:32 +03:00
|
|
|
});
|
2017-01-19 22:18:02 +03:00
|
|
|
|
|
|
|
RunTarget(target);
|
2017-04-23 20:48:55 +03:00
|
|
|
|
2018-03-16 10:10:08 +03:00
|
|
|
MSBuildSettings GetDefaultBuildSettings()
|
|
|
|
{
|
|
|
|
var settings = new MSBuildSettings
|
|
|
|
{
|
|
|
|
Configuration = configuration,
|
|
|
|
ToolPath = msBuildPath,
|
|
|
|
Verbosity = verbosity,
|
|
|
|
ArgumentCustomization = args => args.Append("/m")
|
|
|
|
};
|
|
|
|
|
|
|
|
return settings;
|
|
|
|
}
|
|
|
|
|
2018-02-12 15:11:25 +03:00
|
|
|
bool ShouldPushNugetPackages(string branchName)
|
|
|
|
{
|
|
|
|
if (StringComparer.OrdinalIgnoreCase.Equals(branchName, "develop"))
|
|
|
|
return true;
|
|
|
|
|
|
|
|
return IsMasterOrReleases(branchName) && IsTagged().Item1;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool IsMasterOrReleases(string branchName)
|
2017-04-24 21:17:04 +03:00
|
|
|
{
|
2018-02-12 13:35:05 +03:00
|
|
|
if (StringComparer.OrdinalIgnoreCase.Equals(branchName, "master"))
|
2017-11-08 16:09:10 +03:00
|
|
|
return true;
|
2017-04-24 21:17:04 +03:00
|
|
|
|
2018-02-12 13:35:05 +03:00
|
|
|
if (branchName.StartsWith("release/", StringComparison.OrdinalIgnoreCase) ||
|
|
|
|
branchName.StartsWith("releases/", StringComparison.OrdinalIgnoreCase))
|
2017-11-08 16:09:10 +03:00
|
|
|
return true;
|
2017-04-24 21:17:04 +03:00
|
|
|
|
2017-11-08 16:09:10 +03:00
|
|
|
return false;
|
2017-04-24 21:17:04 +03:00
|
|
|
}
|
|
|
|
|
2017-04-23 20:48:55 +03:00
|
|
|
bool IsRepository(string repoName)
|
|
|
|
{
|
2017-11-08 16:09:10 +03:00
|
|
|
if (isRunningOnAppVeyor)
|
|
|
|
{
|
|
|
|
var buildEnvRepoName = AppVeyor.Environment.Repository.Name;
|
|
|
|
Information("Checking repo name: {0} against build repo name: {1}", repoName, buildEnvRepoName);
|
|
|
|
return StringComparer.OrdinalIgnoreCase.Equals(repoName, buildEnvRepoName);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
|
|
|
var path = MakeAbsolute(sln).GetDirectory().FullPath;
|
|
|
|
using (var repo = new LibGit2Sharp.Repository(path))
|
|
|
|
{
|
|
|
|
var origin = repo.Network.Remotes.FirstOrDefault(
|
|
|
|
r => r.Name.ToLowerInvariant() == "origin");
|
|
|
|
return origin.Url.ToLowerInvariant() ==
|
|
|
|
"https://github.com/" + repoName.ToLowerInvariant();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
catch(Exception ex)
|
|
|
|
{
|
|
|
|
Information("Failed to lookup repository: {0}", ex);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
2017-04-23 20:48:55 +03:00
|
|
|
}
|
|
|
|
|
2018-02-12 15:11:25 +03:00
|
|
|
Tuple<bool, string> IsTagged()
|
2017-04-23 20:48:55 +03:00
|
|
|
{
|
2017-11-08 16:09:10 +03:00
|
|
|
var path = MakeAbsolute(sln).GetDirectory().FullPath;
|
|
|
|
using (var repo = new LibGit2Sharp.Repository(path))
|
|
|
|
{
|
|
|
|
var head = repo.Head;
|
|
|
|
var headSha = head.Tip.Sha;
|
|
|
|
|
|
|
|
var tag = repo.Tags.FirstOrDefault(t => t.Target.Sha == headSha);
|
|
|
|
if (tag == null)
|
|
|
|
{
|
2018-02-12 15:11:25 +03:00
|
|
|
Debug("HEAD is not tagged");
|
|
|
|
return Tuple.Create<bool, string>(false, null);
|
2017-11-08 16:09:10 +03:00
|
|
|
}
|
|
|
|
|
2018-02-12 15:11:25 +03:00
|
|
|
Debug("HEAD is tagged: {0}", tag.FriendlyName);
|
|
|
|
return Tuple.Create<bool, string>(true, tag.FriendlyName);
|
2017-11-08 16:09:10 +03:00
|
|
|
}
|
2017-04-23 20:48:55 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
Tuple<string, string> GetNugetKeyAndSource()
|
|
|
|
{
|
2017-11-08 16:09:10 +03:00
|
|
|
var apiKeyKey = string.Empty;
|
|
|
|
var sourceKey = string.Empty;
|
|
|
|
if (isRunningOnAppVeyor)
|
|
|
|
{
|
|
|
|
apiKeyKey = "NUGET_APIKEY";
|
|
|
|
sourceKey = "NUGET_SOURCE";
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (StringComparer.OrdinalIgnoreCase.Equals(versionInfo.BranchName, "develop"))
|
|
|
|
{
|
|
|
|
apiKeyKey = "NUGET_APIKEY_DEVELOP";
|
|
|
|
sourceKey = "NUGET_SOURCE_DEVELOP";
|
|
|
|
}
|
2018-02-12 15:11:25 +03:00
|
|
|
else if (IsMasterOrReleases(versionInfo.BranchName))
|
2017-11-08 16:09:10 +03:00
|
|
|
{
|
|
|
|
apiKeyKey = "NUGET_APIKEY_MASTER";
|
|
|
|
sourceKey = "NUGET_SOURCE_MASTER";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
var apiKey = EnvironmentVariable(apiKeyKey);
|
|
|
|
if (string.IsNullOrEmpty(apiKey))
|
|
|
|
throw new Exception(string.Format("The {0} environment variable is not defined.", apiKeyKey));
|
|
|
|
|
|
|
|
var source = EnvironmentVariable(sourceKey);
|
|
|
|
if (string.IsNullOrEmpty(source))
|
|
|
|
throw new Exception(string.Format("The {0} environment variable is not defined.", sourceKey));
|
|
|
|
|
|
|
|
return Tuple.Create(apiKey, source);
|
2017-04-26 10:35:19 +03:00
|
|
|
}
|