forked from bt-skyrise/Postgres2Go
-
Notifications
You must be signed in to change notification settings - Fork 2
/
build.cake
139 lines (115 loc) · 4.64 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
// Tools
#tool "xunit.runner.console"
#tool "nuget:?package=GitVersion.CommandLine"
// Parameters
var configuration = Argument("Configuration", "Release");
var target = Argument("Target", "Default");
// Variables
GitVersion versionInfo = null;
var outputDir = Directory("./artifacts");
var projectDir = GetFiles("./src/Postgres2Go/*.csproj").FirstOrDefault();
var solution = GetFiles("./src/*.sln").FirstOrDefault();
var tests = GetFiles("./src/Postgres2Go.Tests/*.csproj").FirstOrDefault();
var testResultsDir = Directory("./test-results/");
// Tasks
Task("Clean")
.Does(() => {
Information("Removing previous build artifacts");
if(DirectoryExists(testResultsDir.Path))
DeleteDirectory(testResultsDir.Path,
new DeleteDirectorySettings()
{
Recursive = true
});
if(DirectoryExists(outputDir.Path))
DeleteDirectory(outputDir.Path,
new DeleteDirectorySettings()
{
Recursive = true
});
});
Task("Prepare-Directories")
.IsDependentOn("Clean")
.Does(() =>
{
Information("Prepare directory for tests output");
EnsureDirectoryExists(testResultsDir.Path);
Information("Prepare directory for lib output");
EnsureDirectoryExists(outputDir.Path);
});
Task("Restore-NuGet-Packages")
.IsDependentOn("Prepare-Directories")
.Does(() => {
Information("Restoring nuget packages for solution");
DotNetCoreRestore(solution.FullPath);
});
Task("Get-Version-Info")
.Does(() => {
Information("Get version:");
versionInfo = GitVersion(
new GitVersionSettings {
UpdateAssemblyInfo = true,
OutputType = GitVersionOutput.Json
});
Information("Version.FullSemVer = " + versionInfo.FullSemVer);
Information("Version.InformationalVersion = " + versionInfo.InformationalVersion);
Information("Version.LegacySemVer = " + versionInfo.LegacySemVer);
Information("Version.LegacySemVerPadded = " + versionInfo.LegacySemVerPadded);
Information("Version.MajorMinorPatch = " + versionInfo.MajorMinorPatch);
Information("Version.NuGetVersion = " + versionInfo.NuGetVersion);
Information("Version.NuGetVersionV2 = " + versionInfo.NuGetVersionV2);
Information("Version.PreReleaseLabel = " + versionInfo.PreReleaseLabel);
Information("Version.PreReleaseTag = " + versionInfo.PreReleaseTag);
Information("Version.PreReleaseTagWithDash = " + versionInfo.PreReleaseTagWithDash);
Information("Version.SemVer = " + versionInfo.SemVer);
});
Task("Build")
.IsDependentOn("Restore-NuGet-Packages")
.IsDependentOn("Get-Version-Info")
.Does(() => {
Information("Build solution");
DotNetCoreBuild(solution.FullPath,
new DotNetCoreBuildSettings()
{
Configuration = configuration,
ArgumentCustomization = args => args
.Append("--no-restore")
.Append("/p:SemVer=" + versionInfo.NuGetVersion) ,
});
});
Task("Test")
.IsDependentOn("Build")
.Does(() => {
var resultsFile = $"..\\..\\..\\test-results\\{tests.GetFilenameWithoutExtension()}.xml";
var testProject = tests.FullPath;
Information($"Run tests of {tests.GetFilenameWithoutExtension()}");
DotNetCoreTest(testProject,
new DotNetCoreTestSettings()
{
Configuration = configuration,
NoBuild = true,
ArgumentCustomization = args => args
.Append($"-r {testResultsDir.Path.FullPath}")
.Append($"-l trx;logfilename={resultsFile}")
});
});
Task("Pack")
.IsDependentOn("Test")
.Does(() => {
Information("Creating nuget package");
DotNetCorePack(
projectDir.GetDirectory().FullPath,
new DotNetCorePackSettings()
{
Configuration = configuration,
NoBuild = true,
OutputDirectory = outputDir.Path,
ArgumentCustomization = args=> args
.Append(" --include-symbols")
.Append("/p:PackageVersion=" + versionInfo.NuGetVersion)
});
});
Task("Default")
.IsDependentOn("Pack");
// Run
RunTarget(target);