-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild.cake
More file actions
188 lines (158 loc) · 4.87 KB
/
build.cake
File metadata and controls
188 lines (158 loc) · 4.87 KB
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
185
186
187
188
// Install addins
#addin "Cake.Git"
// Install tools
#tool "nuget:?package=GitVersion.CommandLine"
#tool "nuget:?package=OctopusTools"
//#tool "nuget:?package=gitlink"
// Load other scripts.
#load "./build-parameters.cake";
using Path = System.IO.Path;
//////////////////////////////////////////////////////////////////////
// PARAMETERS
//////////////////////////////////////////////////////////////////////
BuildParameters parameters = BuildParameters.GetParameters(Context);
var outputDirectory = "./output/";
var solutionPath = "./NetSmith.AspNetCore.CustomViewLocation.sln";
var testFolder = "./test";
///////////////////////////////////////////////////////////////////////////////
// SETUP / TEARDOWN
///////////////////////////////////////////////////////////////////////////////
Setup(context =>
{
parameters.Initialize(context);
});
//////////////////////////////////////////////////////////////////////
// PRIVATE TASKS
//////////////////////////////////////////////////////////////////////
Task("__Clean")
.Does(() =>
{
if (DirectoryExists(outputDirectory))
{
DeleteDirectory(outputDirectory, recursive:true);
}
CreateDirectory(outputDirectory);
});
Task("__Restore")
.Does(() =>
{
DotNetCoreRestore();
});
Task("__Build")
.Does(() =>
{
DotNetCoreBuild(solutionPath, new DotNetCoreBuildSettings
{
Configuration = parameters.Configuration,
ArgumentCustomization = args => args.Append("/p:SemVer=" + parameters.Version.GitVersionInfo.NuGetVersion)
});
});
Task("__Test")
.Does(() =>
{
var files = GetFiles(Path.Combine(testFolder, "*/*.csproj"));
foreach(var file in files)
{
DotNetCoreTest(file.FullPath, new DotNetCoreTestSettings
{
Configuration = parameters.Configuration,
});
}
});
Task("__GitLink")
.Does(() =>
{
//GitLink("./");
});
Task("__Pack")
.IsDependentOn("__GitLink")
.Does(() =>
{
DotNetCorePack("./src/NetSmith.AspNetCore.CustomViewLocation/NetSmith.AspNetCore.CustomViewLocation.csproj", new DotNetCorePackSettings
{
Configuration = parameters.Configuration,
OutputDirectory = outputDirectory,
NoBuild = true,
ArgumentCustomization = args => args.Append("/p:SemVer=" + parameters.Version.GitVersionInfo.NuGetVersion)
});
});
Task("__PublishMyGet")
.WithCriteria(() => parameters.ShouldPublishToMyGet)
.Does(() =>
{
// Resolve the API key.
var apiKey = EnvironmentVariable("MYGET_API_KEY");
if(string.IsNullOrEmpty(apiKey)) {
throw new InvalidOperationException("Could not resolve MyGet API key.");
}
// Resolve the API url.
var apiUrl = EnvironmentVariable("MYGET_API_URL");
if(string.IsNullOrEmpty(apiUrl)) {
throw new InvalidOperationException("Could not resolve MyGet API url.");
}
PublishPackages(apiUrl, apiKey);
});
Task("__Publish")
.WithCriteria(() => parameters.ShouldPublish)
.Does(() =>
{
// Resolve the API key.
var apiKey = EnvironmentVariable("NUGET_API_KEY");
if(string.IsNullOrEmpty(apiKey)) {
throw new InvalidOperationException("Could not resolve NuGet API key.");
}
// Resolve the API url.
var apiUrl = EnvironmentVariable("NUGET_API_URL");
if(string.IsNullOrEmpty(apiUrl)) {
throw new InvalidOperationException("Could not resolve NuGet API url.");
}
PublishPackages(apiUrl, apiKey);
})
.OnError(exception =>
{
Information("Publish to NuGet failed, but continuing with next Task...");
});
Task("__Tag")
.WithCriteria(() => parameters.Version.IsProduction)
.Does(() =>
{
Information($"Tagging with milestone {parameters.Version.Milestone}");
GitTag(".", parameters.Version.Milestone);
GitPushRef(".", parameters.GitUser, "", "origin",
parameters.Version.Milestone);
})
.OnError(exception =>
{
Information("Tagging failed, but continuing with next Task...");
});
//////////////////////////////////////////////////////////////////////
// HELPER
//////////////////////////////////////////////////////////////////////
private void PublishPackages(string url, string key)
{
foreach (var file in GetFiles(outputDirectory + "**/*"))
{
AppVeyor.UploadArtifact(file.FullPath);
// Push the package.
NuGetPush(file.FullPath, new NuGetPushSettings {
ApiKey = key,
Source = url
});
}
}
//////////////////////////////////////////////////////////////////////
// TASKS
//////////////////////////////////////////////////////////////////////
Task("Default")
.IsDependentOn("__Clean")
.IsDependentOn("__Restore")
.IsDependentOn("__Build")
.IsDependentOn("__Test")
.IsDependentOn("__Pack")
.IsDependentOn("__PublishMyGet")
.IsDependentOn("__Publish")
.IsDependentOn("__Tag");
//////////////////////////////////////////////////////////////////////
// EXECUTION
//////////////////////////////////////////////////////////////////////
RunTarget(parameters.Target);