-
Notifications
You must be signed in to change notification settings - Fork 29
/
build.cake
123 lines (96 loc) · 3.09 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
#addin "Cake.ExtendedNuGet"
#addin "nuget:?package=NuGet.Core"
var target = Argument("Target", "Test");
FilePath SolutionFile = MakeAbsolute(File("EMG.XML.sln"));
var testFolder = SolutionFile.GetDirectory().Combine("tests");
var outputFolder = SolutionFile.GetDirectory().Combine("outputs");
var testOutputFolder = outputFolder.Combine("tests");
Setup(context =>
{
CleanDirectory(outputFolder);
});
Task("Restore")
.Does(() =>
{
DotNetCoreRestore(SolutionFile.FullPath);
});
Task("Build")
.IsDependentOn("Restore")
.Does(() =>
{
var settings = new DotNetCoreBuildSettings
{
Configuration = "Debug"
};
DotNetCoreBuild(SolutionFile.FullPath, settings);
});
Task("Test")
.IsDependentOn("Build")
.Does(() =>
{
Information($"Looking for test projects in {testFolder.FullPath}");
var testProjects = GetFiles($"{testFolder}/**/*.csproj").Where(p => !p.FullPath.Contains("Helper"));
foreach (var project in testProjects)
{
Information($"Testing {project.FullPath}");
var testResultFile = testOutputFolder.CombineWithFilePath(project.GetFilenameWithoutExtension() + ".trx");
Verbose($"Saving test results on {testResultFile.FullPath}");
var settings = new DotNetCoreTestSettings
{
NoBuild = true,
NoRestore = true,
Logger = $"trx;LogFileName={testResultFile.FullPath}"
};
DotNetCoreTest(project.FullPath, settings);
if (BuildSystem.IsRunningOnTeamCity)
{
TeamCity.ImportData("mstest", testResultFile);
}
}
});
Task("Pack")
.IsDependentOn("Test")
.Does(() =>
{
var packSettings = new DotNetCorePackSettings
{
Configuration = "Release",
OutputDirectory = outputFolder
};
DotNetCorePack(SolutionFile.FullPath, packSettings);
});
Task("Push")
.IsDependentOn("Pack")
.WithCriteria(!BuildSystem.IsLocalBuild, "This step can only be executed when on a build server")
.WithCriteria(!IsBuildPersonal(), "This step cannot be executed on personal builds")
.WithCriteria(IsMaster(), "This step can only be executed when on the master branch")
.Does(() =>
{
var apiKey = EnvironmentVariable("NuGetApiKey");
var settings = new DotNetCoreNuGetPushSettings
{
Source = "https://api.nuget.org/v3/index.json",
ApiKey = apiKey
};
var files = GetFiles($"{outputFolder}/*.nupkg");
foreach (var file in files)
{
var fileName = file.GetFilename();
try
{
Information($"Pushing {fileName}");
DotNetCoreNuGetPush(file.FullPath, settings);
Information($"{fileName} pushed!");
}
catch (CakeException)
{
Warning($"{fileName} already published, removing from artifacts");
DeleteFile(file);
}
}
});
Task("CI")
.IsDependentOn("Push");
bool IsBuildPersonal() => bool.TryParse(EnvironmentVariable("BUILD_IS_PERSONAL"), out bool res) && res;
bool IsMaster() => EnvironmentVariable("Git_Branch") == @"refs/heads/master";
RunTarget(target);