-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathbuild.cake
170 lines (145 loc) · 6.35 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
/*****************************************************************************
* Usings
*****************************************************************************/
using System;
using System.Collections.Generic;
using System.Linq;
using System.Xml.Linq;
/*****************************************************************************
* Arguments
*****************************************************************************/
var target = Argument("target", "Default");
var platform = Argument("platform", "AnyCPU");
var configuration = Argument("configuration", "Debug");
/*****************************************************************************
* Configuration
*****************************************************************************/
var ProjectName = "Serialize.OpenXml.CodeGen";
var MainRepo = "rmboggs/Serialize.OpenXml.CodeGen";
var MasterBranch = "master";
var ReleasePlatform = "Any CPU";
var ReleaseConfiguration = "Release";
/*****************************************************************************
* Parameters
*****************************************************************************/
var isPlatformAnyCPU = StringComparer.OrdinalIgnoreCase.Equals(platform, "Any CPU");
var isPlatformX86 = StringComparer.OrdinalIgnoreCase.Equals(platform, "x86");
var isPlatformX64 = StringComparer.OrdinalIgnoreCase.Equals(platform, "x64");
var isLocalBuild = BuildSystem.IsLocalBuild;
var isRunningOnUnix = IsRunningOnUnix();
var isRunningOnWindows = IsRunningOnWindows();
var isRunningOnAppVeyor = BuildSystem.AppVeyor.IsRunningOnAppVeyor;
var isPullRequest = BuildSystem.AppVeyor.Environment.PullRequest.IsPullRequest;
var isMainRepo = StringComparer.OrdinalIgnoreCase.Equals(MainRepo, BuildSystem.AppVeyor.Environment.Repository.Name);
var isMasterBranch = StringComparer.OrdinalIgnoreCase.Equals(MasterBranch, BuildSystem.AppVeyor.Environment.Repository.Branch);
var isTagged = BuildSystem.AppVeyor.Environment.Repository.Tag.IsTag
&& !string.IsNullOrWhiteSpace(BuildSystem.AppVeyor.Environment.Repository.Tag.Name);
var isReleasable = StringComparer.OrdinalIgnoreCase.Equals(ReleasePlatform, platform)
&& StringComparer.OrdinalIgnoreCase.Equals(ReleaseConfiguration, configuration);
var isMyGetRelease = !isTagged && isReleasable;
var isNuGetRelease = isTagged && isReleasable;
/*****************************************************************************
* Directories
*****************************************************************************/
var artifactsDir = (DirectoryPath)Directory("./artifacts");
var zipRootDir = artifactsDir.Combine("zip");
var nugetRoot = artifactsDir.Combine("nuget");
var fileZipSuffix = ".zip";
var buildDirs = GetDirectories("./src/**/bin/**") +
GetDirectories("./src/**/obj/**") +
GetDirectories("./artifacts/**/zip/**") +
GetDirectories(".artifacts/**/nuget/**");
var netCoreAppsRoot= "./src/";
var netCoreApp = String.Concat(netCoreAppsRoot, ProjectName);
var netCoreProjects = new Dictionary<string, string>();
netCoreProjects.Add(ProjectName, netCoreApp);
/*****************************************************************************
* Details
*****************************************************************************/
var version = XmlPeek(String.Format("{0}/{1}.csproj", netCoreApp, ProjectName),
"//*[local-name()='Version']/text()");
Information("Building version {0} of Serialize.OpenXml.CodeGen ({1}, {2}, {3}) using version {4} of Cake.",
version,
platform,
configuration,
target,
typeof(ICakeContext).Assembly.GetName().Version.ToString());
if (isRunningOnAppVeyor)
{
Information("Repository Name: " + BuildSystem.AppVeyor.Environment.Repository.Name);
Information("Repository Branch: " + BuildSystem.AppVeyor.Environment.Repository.Branch);
}
Information("Target: " + target);
Information("Platform: " + platform);
Information("Configuration: " + configuration);
Information("IsLocalBuild: " + isLocalBuild);
Information("IsRunningOnUnix: " + isRunningOnUnix);
Information("IsRunningOnWindows: " + isRunningOnWindows);
Information("IsRunningOnAppVeyor: " + isRunningOnAppVeyor);
Information("IsPullRequest: " + isPullRequest);
Information("IsMainRepo: " + isMainRepo);
Information("IsMasterBranch: " + isMasterBranch);
Information("IsTagged: " + isTagged);
Information("IsReleasable: " + isReleasable);
Information("IsMyGetRelease: " + isMyGetRelease);
Information("IsNuGetRelease: " + isNuGetRelease);
/*****************************************************************************
* Tasks
*****************************************************************************/
Task("Clean")
.Does(()=>{
CleanDirectories(buildDirs);
CleanDirectory(nugetRoot);
CleanDirectory(zipRootDir);
});
Task("Restore-NetCore")
.IsDependentOn("Clean")
.Does(() =>
{
foreach (var project in netCoreProjects)
{
DotNetCoreRestore(project.Value);
}
});
Task("Build-NetCore")
.IsDependentOn("Restore-NetCore")
.Does(() =>
{
foreach (var project in netCoreProjects)
{
Information("Building: {0}", project.Key);
DotNetCoreBuild(project.Value);
}
});
Task("Pack-NetCore")
.IsDependentOn("Build-NetCore")
.Does(() =>
{
foreach (var project in netCoreProjects)
{
Information("Packing: {0}", project.Key);
DotNetCorePack(project.Value);
}
});
Task("Zip-NetCore")
.IsDependentOn("Build-NetCore")
.Does(() =>
{
foreach (var project in netCoreProjects)
{
Information("Zipping: {0}", project.Key);
var netCoreAppBin = String.Concat(project.Value, "/bin/", configuration);
var netCoreAppBinFiles = String.Concat(netCoreAppBin, "/**/*");
//*
Zip(netCoreAppBin,
zipRootDir.CombineWithFilePath(String.Concat(project.Key, ".", version, fileZipSuffix)),
GetFiles(netCoreAppBinFiles));
//*/
}
});
Task("Default")
.IsDependentOn("Restore-NetCore")
.IsDependentOn("Build-NetCore")
.IsDependentOn("Pack-NetCore")
.IsDependentOn("Zip-NetCore");
RunTarget(target);