-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbuild.cake
97 lines (82 loc) · 2.32 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
#tool "nuget:?package=GitVersion.CommandLine"
#addin nuget:?package=Newtonsoft.Json
using Newtonsoft.Json;
var target = Argument("target", "Default");
var configuration = Argument("configuration", "Release");
var artifactsDirectory = MakeAbsolute(Directory("./artifacts"));
Setup(context =>
{
CleanDirectory(artifactsDirectory);
});
Task("Build")
.Does(() =>
{
foreach(var project in GetFiles("./src/**/*.csproj"))
{
DotNetCoreBuild(
project.GetDirectory().FullPath,
new DotNetCoreBuildSettings()
{
Configuration = configuration
});
}
});
Task("Test")
.IsDependentOn("Build")
.Does(() =>
{
foreach(var project in GetFiles("./test/**/*.csproj"))
{
DotNetCoreTest(
project.GetDirectory().FullPath,
new DotNetCoreTestSettings()
{
Configuration = configuration
});
}
});
Task("Create-Nuget-Package")
.IsDependentOn("Test")
.WithCriteria(ShouldRunRelease())
.Does(() =>
{
var version = GetPackageVersion();
foreach (var project in GetFiles("./src/**/*.csproj"))
{
DotNetCorePack(
project.GetDirectory().FullPath,
new DotNetCorePackSettings()
{
Configuration = configuration,
OutputDirectory = artifactsDirectory,
ArgumentCustomization = args => args.Append($"/p:Version={version}")
});
}
});
Task("Push-Nuget-Package")
.IsDependentOn("Create-Nuget-Package")
.WithCriteria(ShouldRunRelease())
.Does(() =>
{
var apiKey = EnvironmentVariable("NUGET_API_KEY");
foreach (var package in GetFiles($"{artifactsDirectory}/*.nupkg"))
{
NuGetPush(package,
new NuGetPushSettings {
Source = "https://www.nuget.org/api/v2/package",
ApiKey = apiKey
});
}
});
Task("Default")
.IsDependentOn("Push-Nuget-Package");
RunTarget(target);
private bool ShouldRunRelease() => AppVeyor.IsRunningOnAppVeyor && AppVeyor.Environment.Repository.Tag.IsTag;
private string GetPackageVersion()
{
var gitVersion = GitVersion(new GitVersionSettings {
RepositoryPath = "."
});
Information($"Git Semantic Version: {JsonConvert.SerializeObject(gitVersion)}");
return gitVersion.NuGetVersionV2;
}