This repository has been archived by the owner on Dec 29, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.cake
106 lines (93 loc) · 3.57 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
#tool "nuget:?package=xunit.runner.console"
#tool "nuget:?package=OctopusTools"
#addin "Cake.FileHelpers"
/*************************************************************
Change project, product, and description to fit your project
*************************************************************/
var solution = "ConsulClient"; // Your solution name
var project = "ConsulClient"; // Your project name
var product = "Consul"; // The product this project is for
var description = ".Net client for the Consul service registry"; // A description of the product
var version = string.Format("{0}.{1}", FindRegexMatchInFile("VERSION", @"\d+(?:\.\d+)+", System.Text.RegularExpressions.RegexOptions.None), EnvironmentVariable("CI_PIPELINE_ID") ?? "0");
var buildDir = Directory("./build");
var target = Argument("target", "Default");
var configuration = Argument("configuration", "Debug");
var built = Argument("built", false);
var pushNuget = Argument("pushNuget", false);
var buildOctoPackage = Argument("buildOctoPackage", false);
Task("Clean")
.WithCriteria(() => !built)
.Does(() => {
CleanDirectory(buildDir);
});
Task("RestoreNuGetPackages")
.WithCriteria(() => !built)
.Does(() => {
NuGetRestore(string.Format("{0}.sln", solution));
});
Task("CreateAssemblyInfo")
.WithCriteria(() => !built)
.Does(() => {
EnsureDirectoryExists(string.Format("./{0}/Properties", project));
CreateAssemblyInfo(string.Format("./{0}/Properties/AssemblyInfo.cs", project), new AssemblyInfoSettings {
Product = product,
Version = version,
FileVersion = version,
Description = description
});
});
Task("Build")
.WithCriteria(() => !built)
.IsDependentOn("CreateAssemblyInfo")
.IsDependentOn("Clean")
.IsDependentOn("RestoreNuGetPackages")
.Does(() => {
built = true;
var settings = new MSBuildSettings();
settings.SetConfiguration(configuration)
.WithProperty("outdir", MakeAbsolute(buildDir).ToString())
.SetPlatformTarget(PlatformTarget.MSIL);
if(buildOctoPackage){
settings
.WithProperty("RunOctoPack", "true")
.WithProperty("OctoPackPackageVersion", version);
}
MSBuild(string.Format("./{0}.sln", solution), settings);
});
Task("RunUnitTests")
.IsDependentOn("Build")
.Does(() =>{
XUnit2("./build/*.Tests.dll");
});
Task("PackNuGet")
.IsDependentOn("Build")
.Does(() => {
NuGetPack(string.Format("./{0}/{0}.csproj", project), new NuGetPackSettings{
OutputDirectory = buildDir,
Properties = new Dictionary<string,string>{{"OutDir", MakeAbsolute(buildDir).ToString()}}
});
if(pushNuget){
var nuGetPath = configuration == "Release" ? "http://nuget.eftdomain.net/api/" : EnvironmentVariable("USERPROFILE")+"\\NuGet";
NuGetPush(GetFiles(string.Format("{0}/*.nupkg", buildDir)), new NuGetPushSettings{
Source = nuGetPath
});
}
});
Task("Octo-Push")
.WithCriteria(() => built)
.Does(() => {
var files = GetFiles(string.Format("{0}/*.nupkg", buildDir));
if(files.Count() == 0)
throw new Exception("Nothing to push.");
NuGetPush(files, new NuGetPushSettings{
Source = "http://klondike.eftdomain.net/api/",
ApiKey = "bebca02d-4193-40fe-9040-0023ea43982f"
});
});
Task("Default")
.IsDependentOn("CreateAssemblyInfo")
.Does(() =>{
Console.ForegroundColor = ConsoleColor.Cyan;
Console.WriteLine(string.Format("{0} is configured and ready to build.", solution));
});
RunTarget(target);