-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathbuild.cake
More file actions
93 lines (78 loc) · 2.44 KB
/
build.cake
File metadata and controls
93 lines (78 loc) · 2.44 KB
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
#addin nuget:?package=Cake.Incubator&version=1.5.0
#addin nuget:?package=Cake.Git&version=0.16.1
#addin nuget:?package=Newtonsoft.Json
using Newtonsoft.Json;
var target = Argument<string>("Target");
var config = Argument<string>("Configuration");
//nuget
var nugetKey = EnvironmentVariable("NUGET_KEY");
var nugetSource = EnvironmentVariable("NUGET_SOURCE", "https://www.nuget.org/api/v2/package");
var version = GitDescribe(".", false, GitDescribeStrategy.Tags, 0)?.ToLower().TrimStart('v') ?? "debug";
Information("Building {0}...", $"v{version}");
//CI Environment vars
var isOnTravis = EnvironmentVariable<bool>("TRAVIS", false);
var prNumber = EnvironmentVariable("TRAVIS_PULL_REQUEST");
var branch = EnvironmentVariable("TRAVIS_BRANCH");
var isPR = int.TryParse(prNumber, out var _);
Task("tests")
.Does(() =>
{
var testProjects = GetFiles("./tests/**/*Tests.csproj");
foreach(var file in testProjects)
{
DotNetCoreTest(file.FullPath);
}
});
Task("pack")
.Does(() =>
{
var msBuildSettings = new DotNetCoreMSBuildSettings();
msBuildSettings.SetVersion(version);
var settings = new DotNetCorePackSettings
{
Configuration = config,
OutputDirectory = "./artifacts/",
MSBuildSettings = msBuildSettings,
IncludeSource = true,
ToolTimeout = TimeSpan.FromMinutes(5)
};
Information(
"Packing version '{0}' with this settings: {1}{2}"
, version
, Environment.NewLine
, JsonConvert.SerializeObject(settings, Formatting.Indented)
);
DotNetCorePack("./src/JsonFluentMap/JsonFluentMap.csproj", settings);
});
Task("nuget-push")
.Does(() =>
{
Information("Publishing package to nuget.org");
var settings = new DotNetCoreNuGetPushSettings
{
Source = nugetSource,
ApiKey = nugetKey
};
DotNetCoreNuGetPush($"./artifacts/JsonFluentMap.{version}.nupkg", settings);
});
Task("travis")
.IsDependentOn("pack")
.Does(() =>
{
if (isOnTravis)
{
Information("Build running on travis! branch: {0}", branch);
Information("Pull Request {0}", $"#{prNumber}");
//if the branch equals to a version
//it means that the script is building a git tag (release)
if(branch.ToLower().TrimStart('v') == version && !isPR)
{
RunTarget("nuget-push");
}
}
else
{
Information("Build is NOT running on travis!");
}
});
RunTarget(target);