-
Notifications
You must be signed in to change notification settings - Fork 5
/
build.cake
109 lines (94 loc) · 2.95 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
#addin "Cake.Git"
#tool "nuget:?package=GitVersion.CommandLine"
var args = new
{
Target = Argument("target", "Default"),
OutputDirectory = Argument("output", "build"),
RepositoryPath = Argument("repositoryPath", "."),
Configuration = Argument("configuration", "Release"),
AddCommitToDescription = Argument("addCommitToDescription", false),
Version = GitVersion(new GitVersionSettings{UpdateAssemblyInfo = false}),
Nuget = new
{
Source = Argument("nugetSource", "https://www.nuget.org/api/v2/package"),
ApiKey = Argument("nugetApiKey", ""),
},
};
var buildDirectory = MakeAbsolute(Directory(args.OutputDirectory));
Task("Clean").Does(() =>
{
CleanDirectories(args.OutputDirectory);
CleanDirectories("./**/bin");
CleanDirectories("./**/obj");
});
Task("PrintArguments").Does(() =>
{
Information($"Arguments:");
Information($" * Target: {args.Target}");
Information($" * AddCommitToDescription: {args.AddCommitToDescription}");
Information($" * Configuration: {args.Configuration}");
Information($" * Version: {args.Version}");
Information($" * RepositoryPath: {args.RepositoryPath}");
Information($" * OutputDirectory: {args.OutputDirectory}");
Information($" * NugetApiKey: <*>");
});
Task("Build")
.IsDependentOn("Clean")
.Does(() =>
{
var sln = "ObviousAwait.sln";
NuGetRestore(sln);
MSBuild(sln, c =>
{
c.Configuration = args.Configuration;
c.MSBuildPlatform = Cake.Common.Tools.MSBuild.MSBuildPlatform.x86;
});
});
Task("Pack")
.IsDependentOn("Build")
.Does(() =>
{
if(!DirectoryExists(buildDirectory.FullPath))
CreateDirectory(buildDirectory.FullPath);
var nuspecFiles = GetFiles("*.nuspec");
foreach(var nuspec in nuspecFiles)
{
var wd = MakeAbsolute(nuspec).GetDirectory();
var settings = new NuGetPackSettings
{
Version = args.Version.FullSemVer,
OutputDirectory = buildDirectory.FullPath,
BasePath = wd,
};
if(args.AddCommitToDescription)
{
// Extract description from nuspec and concat current commit hash and datetime
var description = XmlPeek(nuspec, $"/package/metadata/description");
var lastCommit = GitLogTip(args.RepositoryPath);
description = $"{description}\n\nCommit : {lastCommit.Sha}, {lastCommit.Author?.When}";
Information($"Updated package description : {description}");
settings.Description = description;
}
NuGetPack(nuspec, settings);
}
});
Task("Push")
.IsDependentOn("PrintArguments")
.IsDependentOn("Pack")
.Does(() =>
{
if(string.IsNullOrEmpty(args.Nuget.ApiKey))
{
throw new ArgumentException("Missing 'nugetApiKey' arguments");
}
var packages = GetFiles($"**/*.{args.Version}.nupkg");
NuGetPush(packages, new NuGetPushSettings
{
Source = args.Nuget.Source,
ApiKey = args.Nuget.ApiKey,
});
});
Task("Default")
.IsDependentOn("PrintArguments")
.IsDependentOn("Pack");
RunTarget(args.Target);