-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathbuild.cake
132 lines (112 loc) · 4.21 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
#addin nuget:?package=Cake.Git
using System.Text.RegularExpressions;
//////////////////////////////////////////////////////////////////////
// ARGUMENTS
//////////////////////////////////////////////////////////////////////
var target = Argument("target", "Default");
var configuration = Argument("configuration", "Release");
//////////////////////////////////////////////////////////////////////
// PREPARATION
//////////////////////////////////////////////////////////////////////
// Define directories.
var buildDir = Directory("./src/Syncromatics.Clients.WaySine/bin") + Directory(configuration);
var testDir = Directory("./tests/Syncromatics.Clients.WaySine.IntegrationTests/bin") + Directory(configuration);
//////////////////////////////////////////////////////////////////////
// TASKS
//////////////////////////////////////////////////////////////////////
var version = "";
var semVersion = "";
Task("GetVersion")
.Does(() =>
{
var repositoryPath = Directory(".");
var travisTag = EnvironmentVariable("TRAVIS_TAG");
if (!string.IsNullOrEmpty(travisTag))
{
Information($"GetVersion: Current tag is {travisTag}");
version = semVersion = travisTag;
}
else
{
var travisPullRequest = EnvironmentVariable("TRAVIS_PULL_REQUEST");
var travisBranch = EnvironmentVariable("TRAVIS_BRANCH");
var branch = !string.IsNullOrEmpty(travisPullRequest) && travisPullRequest != "false"
? $"pr-{travisPullRequest}-{EnvironmentVariable("TRAVIS_PULL_REQUEST_BRANCH")}"
: !string.IsNullOrEmpty(travisBranch)
? travisBranch
: GitBranchCurrent(repositoryPath).FriendlyName;
Information($"GetVersion: Current branch is {branch}");
var prereleaseTag = Regex.Replace(branch, @"\W+", "-");
var describe = GitDescribe(repositoryPath, GitDescribeStrategy.Tags);
var isMaster = prereleaseTag == "master" || prereleaseTag == "-no-branch-";
version = string.Join(".", describe.Split(new[] { '-' }, 3).Take(2));
semVersion = version + (isMaster ? "" : $"-{prereleaseTag}");
}
Information($"Version: {semVersion}");
});
Task("Clean")
.Does(() =>
{
CleanDirectory(buildDir);
CleanDirectory(testDir);
});
Task("Build")
.IsDependentOn("InnerTest");
Task("Package")
.IsDependentOn("InnerPackage");
Task("Publish")
.IsDependentOn("GetVersion")
.IsDependentOn("Package")
.Does(() =>
{
var package = $"./Syncromatics.Clients.WaySine.{semVersion}.nupkg";
NuGetPush(package, new NuGetPushSettings
{
Source = "https://www.nuget.org/api/v2/package",
ApiKey = EnvironmentVariable("NUGET_API_KEY")
});
});
Task("InnerRestore")
.IsDependentOn("Clean")
.Does(() =>
{
DotNetCoreRestore();
});
Task("InnerBuild")
.IsDependentOn("InnerRestore")
.Does(() =>
{
var settings = new DotNetCoreBuildSettings
{
Configuration = configuration,
};
DotNetCoreBuild("./", settings);
});
Task("InnerTest")
.IsDependentOn("InnerBuild")
.Does(() =>
{
DotNetCoreTool("./tests/Syncromatics.Clients.WaySine.IntegrationTests/Syncromatics.Clients.WaySine.IntegrationTests.csproj", "xunit");
});
Task("InnerPackage")
.IsDependentOn("GetVersion")
.IsDependentOn("InnerTest")
.Does(() =>
{
var packageSettings = new DotNetCorePackSettings
{
Configuration = configuration,
OutputDirectory = "./",
ArgumentCustomization = args => args.Append($"/p:Version={semVersion}")
};
DotNetCorePack(File("./src/Syncromatics.Clients.WaySine/Syncromatics.Clients.WaySine.csproj"), packageSettings);
});
//////////////////////////////////////////////////////////////////////
// TASK TARGETS
//////////////////////////////////////////////////////////////////////
Task("Default")
.IsDependentOn("Build");
//////////////////////////////////////////////////////////////////////
// EXECUTION
//////////////////////////////////////////////////////////////////////
RunTarget(target);