forked from OctopusDeploy/Octodiff
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.cake
174 lines (152 loc) · 5.6 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
//////////////////////////////////////////////////////////////////////
// TOOLS
//////////////////////////////////////////////////////////////////////
#tool "nuget:?package=GitVersion.CommandLine&version=4.0.0-beta0007"
#addin "MagicChunks"
//////////////////////////////////////////////////////////////////////
// ARGUMENTS
//////////////////////////////////////////////////////////////////////
var target = Argument("target", "Default");
var configuration = Argument("configuration", "Release");
///////////////////////////////////////////////////////////////////////////////
// GLOBAL VARIABLES
///////////////////////////////////////////////////////////////////////////////
var artifactsDir = "./artifacts";
var globalAssemblyFile = "./Octodiff/Properties/AssemblyInfo.cs";
var projectsToPackage = new []{"./source/Octodiff"};
var isContinuousIntegrationBuild = !BuildSystem.IsLocalBuild;
var gitVersionInfo = GitVersion(new GitVersionSettings {
OutputType = GitVersionOutput.Json
});
var nugetVersion = isContinuousIntegrationBuild ? gitVersionInfo.NuGetVersion : "0.0.0";
///////////////////////////////////////////////////////////////////////////////
// SETUP / TEARDOWN
///////////////////////////////////////////////////////////////////////////////
Setup(context =>
{
Information("Building Octodiff v{0}", nugetVersion);
});
Teardown(context =>
{
Information("Finished running tasks.");
});
//////////////////////////////////////////////////////////////////////
// PRIVATE TASKS
//////////////////////////////////////////////////////////////////////
Task("__Default")
.IsDependentOn("__Clean")
.IsDependentOn("__Restore")
.IsDependentOn("__UpdateAssemblyVersionInformation")
.IsDependentOn("__Build")
.IsDependentOn("__Test")
.IsDependentOn("__UpdateProjectJsonVersion")
.IsDependentOn("__Pack")
.IsDependentOn("__Publish");
Task("__Clean")
.Does(() =>
{
CleanDirectory(artifactsDir);
CleanDirectories("./**/bin");
CleanDirectories("./**/obj");
});
Task("__Restore")
.Does(() => DotNetCoreRestore());
Task("__UpdateAssemblyVersionInformation")
.WithCriteria(isContinuousIntegrationBuild)
.Does(() =>
{
GitVersion(new GitVersionSettings {
UpdateAssemblyInfo = true,
UpdateAssemblyInfoFilePath = globalAssemblyFile
});
Information("AssemblyVersion -> {0}", gitVersionInfo.AssemblySemVer);
Information("AssemblyFileVersion -> {0}", $"{gitVersionInfo.MajorMinorPatch}.0");
Information("AssemblyInformationalVersion -> {0}", gitVersionInfo.InformationalVersion);
});
Task("__Build")
.Does(() =>
{
DotNetCoreBuild("**/project.json", new DotNetCoreBuildSettings
{
Configuration = configuration
});
});
Task("__Test")
.Does(() =>
{
GetFiles("**/*Tests/project.json")
.ToList()
.ForEach(testProjectFile =>
{
DotNetCoreTest(testProjectFile.ToString(), new DotNetCoreTestSettings
{
Configuration = configuration
});
});
});
Task("__UpdateProjectJsonVersion")
.WithCriteria(isContinuousIntegrationBuild)
.Does(() =>
{
foreach(var projectToPackage in projectsToPackage)
{
var projectToPackagePackageJson = $"{projectToPackage}/project.json";
Information("Updating {0} version -> {1}", projectToPackagePackageJson, nugetVersion);
TransformConfig(projectToPackagePackageJson, projectToPackagePackageJson, new TransformationCollection {
{ "version", nugetVersion }
});
};
});
Task("__Pack")
.Does(() =>
{
foreach(var projectToPackage in projectsToPackage)
{
DotNetCorePack(projectToPackage, new DotNetCorePackSettings
{
Configuration = configuration,
OutputDirectory = artifactsDir,
NoBuild = true
});
};
});
Task("__Publish")
.WithCriteria(isContinuousIntegrationBuild)
.Does(() =>
{
var isPullRequest = !String.IsNullOrEmpty(EnvironmentVariable("APPVEYOR_PULL_REQUEST_NUMBER"));
var isMasterBranch = EnvironmentVariable("APPVEYOR_REPO_BRANCH") == "master" && !isPullRequest;
var shouldPushToMyGet = !BuildSystem.IsLocalBuild;
var shouldPushToNuGet = !BuildSystem.IsLocalBuild && isMasterBranch;
if (shouldPushToMyGet)
{
NuGetPush("artifacts/Octodiff." + nugetVersion + ".nupkg", new NuGetPushSettings {
Source = "https://octopus.myget.org/F/octopus-dependencies/api/v3/index.json",
ApiKey = EnvironmentVariable("MyGetApiKey")
});
NuGetPush("artifacts/Octodiff." + nugetVersion + ".symbols.nupkg", new NuGetPushSettings {
Source = "https://octopus.myget.org/F/octopus-dependencies/api/v3/index.json",
ApiKey = EnvironmentVariable("MyGetApiKey")
});
}
// if (shouldPushToNuGet)
// {
// NuGetPush("artifacts/Octodiff." + nugetVersion + ".nupkg", new NuGetPushSettings {
// Source = "https://www.nuget.org/api/v2/package",
// ApiKey = EnvironmentVariable("NuGetApiKey")
// });
// NuGetPush("artifacts/Octodiff." + nugetVersion + ".symbols.nupkg", new NuGetPushSettings {
// Source = "https://www.nuget.org/api/v2/package",
// ApiKey = EnvironmentVariable("NuGetApiKey")
// });
// }
});
//////////////////////////////////////////////////////////////////////
// TASKS
//////////////////////////////////////////////////////////////////////
Task("Default")
.IsDependentOn("__Default");
//////////////////////////////////////////////////////////////////////
// EXECUTION
//////////////////////////////////////////////////////////////////////
RunTarget(target);