-
Notifications
You must be signed in to change notification settings - Fork 3
/
build.cake
150 lines (130 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
139
140
141
142
143
144
145
146
147
148
149
150
///////////////////////////////////////////////////////////////////////////////
// TOOLS / ADDINS
///////////////////////////////////////////////////////////////////////////////
#tool nuget:?package=vswhere&version=2.8.4
//////////////////////////////////////////////////////////////////////
// ARGUMENTS
//////////////////////////////////////////////////////////////////////
var msBuildPath = GetFiles(VSWhereLatest() + "/**/MSBuild.exe").FirstOrDefault();
var target = Argument("target", "Default");
var configuration = Argument("configuration", "Release");
var verbosity = Argument("verbosity", Verbosity.Minimal);
var version = Argument("version", "1.1.1");
//////////////////////////////////////////////////////////////////////
// PREPARATION
//////////////////////////////////////////////////////////////////////
var solution = "./HN.Social.Weibo.sln";
//////////////////////////////////////////////////////////////////////
// TASKS
//////////////////////////////////////////////////////////////////////
Task("Clean")
.ContinueOnError()
.Does(() =>
{
CleanDirectories("./src/*/bin");
});
Task("Restore-NuGet-Packages")
.IsDependentOn("Clean")
.Does(() =>
{
NuGetRestore(solution, new NuGetRestoreSettings { NoCache = true });
});
Task("Version")
.IsDependentOn("Restore-NuGet-Packages")
.Does(() =>
{
var file = "./src/SolutionInfo.cs";
CreateAssemblyInfo(file, new AssemblyInfoSettings
{
Version = version,
FileVersion = version,
InformationalVersion = version,
Copyright = string.Format("Copyright © h82258652 2018 - {0}", DateTime.Now.Year)
});
});
Task("Build")
.IsDependentOn("Version")
.Does(() =>
{
if(IsRunningOnWindows())
{
// Use MSBuild
var settings = new MSBuildSettings
{
ToolPath = msBuildPath
}
.SetConfiguration(configuration)
.SetVerbosity(verbosity);
MSBuild(solution, settings);
}
else
{
// Use XBuild
XBuild(solution, configurator =>
configurator.SetConfiguration(configuration)
.SetVerbosity(verbosity));
}
});
Task("Test")
.IsDependentOn("Build")
.Does(() =>
{
var settings = new DotNetCoreTestSettings
{
Configuration = "Release"
};
var testProjects = GetFiles("./test/**/*.csproj");
foreach(var testProject in testProjects)
{
DotNetCoreTest(testProject.FullPath, settings);
}
});
Task("Package")
.IsDependentOn("Test")
.Does(() =>
{
var nugetPackSettings = new NuGetPackSettings
{
Version = version,
OutputDirectory = "./artifacts",
Repository = new NuGetRepository
{
Type = "git",
Url = "https://github.com/h82258652/HN.Social.Weibo"
}
};
var nuspecFiles = GetFiles("./src/*/*.nuspec");
NuGetPack(nuspecFiles, nugetPackSettings);
});
Task("Publish")
.WithCriteria(BuildSystem.IsRunningOnGitHubActions)
.IsDependentOn("Package")
.Does(() =>
{
var packages = GetFiles("./artifacts/*.nupkg");
// 暂时不发布 efcore 的包
for (var i = packages.Count - 1; i >= 0; i--)
{
var package = packages.ElementAt(i);
if(package.FullPath.Contains("EfCore"))
{
packages.Remove(package);
}
}
var nugetApiKey = EnvironmentVariable("NUGET_APIKEY");
NuGetPush(packages, new NuGetPushSettings
{
Source = "https://www.nuget.org",
ApiKey = nugetApiKey,
SkipDuplicate = true
});
});
//////////////////////////////////////////////////////////////////////
// TASK TARGETS
//////////////////////////////////////////////////////////////////////
Task("Default")
.IsDependentOn("Publish");
//////////////////////////////////////////////////////////////////////
// EXECUTION
//////////////////////////////////////////////////////////////////////
RunTarget(target);