-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.cake
184 lines (153 loc) · 6.02 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
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
//////////////////////////////////////////////////////////////////////
// TOOLS
//////////////////////////////////////////////////////////////////////
#tool "nuget:?package=GitVersion.CommandLine&version=4.0.0-beta0011"
#tool "nuget:?package=ILRepack&version=2.0.13"
#addin "nuget:?package=SharpCompress&version=0.12.4"
#addin "nuget:?package=Cake.Npm&version=0.14.0"
#addin nuget:?package=Feedz.Client
#addin nuget:?package=Octodiff
using SharpCompress;
using SharpCompress.Common;
using SharpCompress.Writer;
//////////////////////////////////////////////////////////////////////
// ARGUMENTS
//////////////////////////////////////////////////////////////////////
var target = Argument("target", "Default");
var configuration = Argument("configuration", "Release");
///////////////////////////////////////////////////////////////////////////////
// GLOBAL VARIABLES
///////////////////////////////////////////////////////////////////////////////
var artifactsDir = "./artifacts/";
var publishDir = "./publish/";
GitVersion gitVersionInfo;
string nugetVersion;
///////////////////////////////////////////////////////////////////////////////
// SETUP / TEARDOWN
///////////////////////////////////////////////////////////////////////////////
Setup(context =>
{
gitVersionInfo = GitVersion(new GitVersionSettings {
OutputType = GitVersionOutput.Json
});
nugetVersion = gitVersionInfo.NuGetVersion;
if(BuildSystem.IsRunningOnAppVeyor)
BuildSystem.AppVeyor.UpdateBuildVersion(nugetVersion);
Information("Building Feedz.Console v{0}", nugetVersion);
Information("Informational Version {0}", gitVersionInfo.InformationalVersion);
});
Teardown(context =>
{
Information("Finished running tasks.");
});
//////////////////////////////////////////////////////////////////////
// PRIVATE TASKS
//////////////////////////////////////////////////////////////////////
Task("Clean")
.Does(() => {
CleanDirectory(artifactsDir);
CleanDirectory("./artifacts");
CleanDirectory("./publish");
CleanDirectories("./src/**/bin");
CleanDirectories("./src/**/obj");
});
Task("Restore")
.IsDependentOn("Clean")
.Does(() => {
DotNetCoreRestore("./src");
});
Task("Build")
.IsDependentOn("Restore")
.IsDependentOn("Clean")
.Does(() => {
DotNetCoreBuild("./src", new DotNetCoreBuildSettings
{
Configuration = configuration,
ArgumentCustomization = args => args.Append($"/p:Version={nugetVersion}")
});
});
Task("Publish")
.IsDependentOn("Build")
.Does(() => {
DotNetCorePublish("./src/Console", new DotNetCorePublishSettings
{
Configuration = configuration,
NoBuild = true,
OutputDirectory = $"{publishDir}\\netfx",
Framework = "net461",
ArgumentCustomization = args => args.Append($"/p:Version={nugetVersion}")
});
DotNetCorePublish("./src/Console", new DotNetCorePublishSettings
{
Configuration = configuration,
OutputDirectory = $"{publishDir}\\linux",
Framework = "netcoreapp2.1",
Runtime = "linux-x64",
ArgumentCustomization = args => args.Append($"/p:Version={nugetVersion}")
});
DotNetCorePublish("./src/Console", new DotNetCorePublishSettings
{
Configuration = configuration,
OutputDirectory = $"{publishDir}\\osx",
Framework = "netcoreapp2.1",
Runtime = "osx-x64",
ArgumentCustomization = args => args.Append($"/p:Version={nugetVersion}")
});
});
Task("MergeExe")
.IsDependentOn("Publish")
.Does(() => {
var inputFolder = $"{publishDir}/netfx";
var outputFolder = $"{publishDir}/netfx-merged";
CreateDirectory(outputFolder);
ILRepack(
$"{outputFolder}/Feedz.exe",
$"{inputFolder}/Feedz.exe",
System.IO.Directory.EnumerateFiles(inputFolder, "*.dll").Select(f => (FilePath) f),
new ILRepackSettings {
Internalize = true,
Parallel = true,
Libs = new List<DirectoryPath>() { inputFolder }
}
);
});
Task("Zip")
.IsDependentOn("MergeExe")
.Does(() => {
Zip(System.IO.Path.GetFullPath($"{publishDir}/netfx-merged"), $"{artifactsDir}/Feedz.Console.{nugetVersion}.zip");
TarGzip($"{publishDir}/linux", $"{artifactsDir}/Feedz.Console.linux.{nugetVersion}");
TarGzip($"{publishDir}/osx", $"{artifactsDir}/Feedz.Console.osx.{nugetVersion}");
});
Task("Push")
.IsDependentOn("Zip")
// .WithCriteria(BuildSystem.IsRunningOnAppVeyor)
.Does(async () => {
var repo = Feedz.Client.FeedzClient.Create(EnvironmentVariable("FeedzApiKey"))
.ScopeToRepository("feedz-io", "public");
await repo.Packages.Upload($"{artifactsDir}/Feedz.Console.{nugetVersion}.zip");
await repo.Packages.Upload($"{artifactsDir}/Feedz.Console.linux.{nugetVersion}.tgz");
await repo.Packages.Upload($"{artifactsDir}/Feedz.Console.osx.{nugetVersion}.tgz");
});
Task("Default")
.IsDependentOn("Push");
private void TarGzip(string path, string outputFile)
{
var outFile = $"{outputFile}.tgz";
Information("Creating TGZ file {0} from {1}", outFile, path);
using (var tarMemStream = new MemoryStream())
{
using (var tar = WriterFactory.Open(tarMemStream, ArchiveType.Tar, CompressionType.None, true))
{
tar.WriteAll(path, "*", SearchOption.AllDirectories);
}
tarMemStream.Seek(0, SeekOrigin.Begin);
using (Stream stream = System.IO.File.Open(outFile, FileMode.Create))
using (var zip = WriterFactory.Open(stream, ArchiveType.GZip, CompressionType.GZip))
zip.Write($"{outputFile}.tar", tarMemStream);
}
Information("Successfully created TGZ file: {0}", outFile);
}
//////////////////////////////////////////////////////////////////////
// EXECUTION
//////////////////////////////////////////////////////////////////////
RunTarget(target);