-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.cake
108 lines (92 loc) · 2.81 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
#load "./scripts/version.cake"
var target = Argument<string>("target", "Default");
var config = Argument<string>("configuration", "Release");
var version = new BuildVersion("0.1.0", "local");
var solutionPath = File("./src/Dotbot.Telegram.sln");
var solution = ParseSolution(solutionPath);
var projects = solution.Projects.Where(p => p.Type != "{2150E333-8FDC-42A3-9474-1A3956D46DE8}");
var projectPaths = projects.Select(p => p.Path.GetDirectory());
var isRunningOnAppVeyor = BuildSystem.AppVeyor.IsRunningOnAppVeyor;
var isPullRequest = BuildSystem.AppVeyor.Environment.PullRequest.IsPullRequest;
Setup(context =>
{
// Calculate semantic version.
version = GetVersion(context);
// Output some information.
Information("Version: {0}", version.GetSemanticVersion());
Information("Pull Request: {0}", isPullRequest);
});
Task("Clean")
.Does(() =>
{
CleanDirectory("./.artifacts");
});
Task("Restore")
.IsDependentOn("Clean")
.Does(() =>
{
DotNetCoreRestore(solutionPath, new DotNetCoreRestoreSettings
{
Verbose = false,
Sources = new [] { "https://api.nuget.org/v3/index.json" }
});
});
Task("Build")
.IsDependentOn("Clean")
.IsDependentOn("Restore")
.Does(() =>
{
// Build
DotNetCoreBuild(solutionPath, new DotNetCoreBuildSettings
{
Configuration = config,
ArgumentCustomization = args => args.Append("/p:Version={0}", version.GetSemanticVersion())
});
});
Task("Pack")
.IsDependentOn("Build")
.Does(() =>
{
// Publish
foreach(var project in projects)
{
Information("\nPacking {0}...", project.Path);
DotNetCorePack(project.Path.FullPath, new DotNetCorePackSettings
{
Configuration = config,
OutputDirectory = "./.artifacts",
VersionSuffix = version.Suffix,
NoBuild = true,
Verbose = false,
ArgumentCustomization = args => args
.Append("/p:Version={0}", version.GetSemanticVersion())
.Append("--include-symbols --include-source")
});
}
});
Task("Publish")
.WithCriteria(isRunningOnAppVeyor && !isPullRequest)
.IsDependentOn("Pack")
.Does(() =>
{
var apiKey = EnvironmentVariable("NUGET_API_KEY");
if(string.IsNullOrWhiteSpace(apiKey))
{
throw new CakeException("NuGet API key was not provided.");
}
// Get the file paths.
var packageVersion = version.GetSemanticVersion();
var files = GetFiles("./.artifacts/*." + packageVersion + ".nupkg");
foreach(var file in files)
{
NuGetPush(file, new NuGetPushSettings() {
Source = "https://nuget.org/api/v2/package",
ApiKey = apiKey
});
}
});
Task("AppVeyor")
.IsDependentOn("Publish");
Task("Default")
.IsDependentOn("Pack");
RunTarget(target);