-
Notifications
You must be signed in to change notification settings - Fork 1
/
build.cake
138 lines (120 loc) · 3.89 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
133
134
135
136
137
138
#addin "Cake.Git"
var args = new
{
OutputDirectory = Argument("output", "build"),
Target = Argument("target", "Default"),
RepositoryPath = Argument("repositoryPath", "."),
AddCommitToDescription = Argument("addCommitToDescription", true),
Configuration = Argument("configuration", "Release"),
Version = Argument<string>("packageVersion"),
Nuget = new
{
Source = Argument("nugetSource", "https://www.nuget.org/api/v2/package"),
ApiKey = Argument("nugetApiKey", ""),
},
};
var buildDirectory = MakeAbsolute(Directory(args.OutputDirectory));
Task("Tools.PrintArguments").Does(() =>
{
Information($"Arguments:");
Information($" * Target: {args.Target}");
Information($" * AddCommitToDescription: {args.AddCommitToDescription}");
Information($" * OutputDirectory: {args.OutputDirectory}");
Information($" * Configuration: {args.Configuration}");
Information($" * Version: {args.Version}");
Information($" * RepositoryPath: {args.RepositoryPath}");
Information($" * NugetApiKey: <*>");
});
Task("Tools.Clean").Does(() =>
{
CleanDirectories(args.OutputDirectory);
CleanDirectories("./**/bin");
CleanDirectories("./**/obj");
});
Task("Build.Solutions")
.IsDependentOn("Tools.Clean")
.Does(() =>
{
var slnFiles = GetFiles("**/*.sln");
foreach(var sln in slnFiles)
{
NuGetRestore(sln);
MSBuild(sln, c =>
{
c.Configuration = args.Configuration;
c.MSBuildPlatform = Cake.Common.Tools.MSBuild.MSBuildPlatform.x86;
});
}
});
Task("Nuget.Pack.Sources")
.IsDependentOn("Build.Solutions")
.Does(() =>
{
var sourceFiles = GetFiles("src/Transform/**/*.cs");
var content = new System.Text.StringBuilder();
content.AppendLine("// INCLUDED FILE, DO NOT MODIFY IT");
content.AppendLine("// (from nuget package 'Transform.Sources')\n\n");
foreach(var source in sourceFiles)
{
var path = MakeAbsolute(source).FullPath;
if(System.IO.Path.GetFileName(path) != "AssemblyInfo.cs")
{
Information($"Appending {source}");
var sourceContent = System.IO.File.ReadAllText(path);
content.AppendLine(sourceContent);
}
}
var output = (Directory(buildDirectory.FullPath) + File("Transform.cs")).Path;
System.IO.File.WriteAllText(output.ToString(), content.ToString());
});
Task("Nuget.Pack")
.IsDependentOn("Build.Solutions")
.IsDependentOn("Nuget.Pack.Sources")
.Does(() =>
{
if(!DirectoryExists(buildDirectory.FullPath))
{
CreateDirectory(buildDirectory.FullPath);
}
var nuspecFiles = GetFiles("nuget/**/*.nuspec");
foreach(var nuspec in nuspecFiles)
{
var wd = MakeAbsolute(nuspec).GetDirectory();
var settings = new NuGetPackSettings
{
Version = args.Version,
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("Nuget.Push")
.IsDependentOn("Tools.PrintArguments")
.IsDependentOn("Nuget.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("Tools.PrintArguments")
.IsDependentOn("Nuget.Pack");
RunTarget(args.Target);