-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.cake
77 lines (65 loc) · 2.79 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
var target = Argument("target", "Pack");
var srcDir = Argument<string>("srcDir");
var buildDir = Argument<string>("buildDir");
var outputDir = Argument<string>("outputDir");
var testResultsDir = Argument<string>("testResultsDir");
var nugetProject = Argument<string>("nugetProject");
var branchName = Argument<string>("branchName");
var nugetVersion = string.Empty;
Setup(context =>
{
context.Environment.WorkingDirectory = buildDir;
CopyDirectory(new DirectoryPath(srcDir), context.Environment.WorkingDirectory);
// it's needed for GitVersion - it doesn't work well in 'detached head' state
var prefix = "refs/heads/";
var branch = branchName.StartsWith(prefix) ? branchName.Substring(prefix.Length) : branchName;
StartProcess("git", new ProcessSettings{ Arguments = $"checkout {branch}" });
});
Task("GetVersionInfo")
.Does(() =>
{
var assemblyInfoFilename = "AssemblyInfo_FromGitVersion.cs";
var result = GitVersion(new GitVersionSettings
{
ArgumentCustomization = args => args.Append($"/ensureassemblyinfo /updateassemblyinfo {assemblyInfoFilename}")
});
var projectDirectories = GetFiles($"./**/*.csproj").Select(x => x.GetDirectory());
var assemblyInfoFilePath = new FilePath(assemblyInfoFilename);
foreach(var directory in projectDirectories)
{
CopyFile(assemblyInfoFilePath, directory.CombineWithFilePath(assemblyInfoFilename));
}
nugetVersion = result.FullSemVer;
});
Task("Tests")
.Does(()=>
{
var settings = new DotNetCoreTestSettings
{
Logger = "trx",
ResultsDirectory = new DirectoryPath(testResultsDir)
};
var projectFiles = GetFiles("./**/*Tests.csproj").Concat(GetFiles("./**/*Test.csproj"));
foreach(var file in projectFiles)
{
DotNetCoreTest(file.FullPath, settings);
}
});
Task("Pack")
.IsDependentOn("Tests")
.IsDependentOn("GetVersionInfo")
.Does(()=>
{
var projectFile = GetFiles($"./**/{nugetProject}.csproj").Single();
var settings = new DotNetCorePackSettings
{
Configuration = "Release",
OutputDirectory = new DirectoryPath(outputDir),
ArgumentCustomization = args => args.Append($"/p:Version={nugetVersion}")
.Append($"/p:GenerateAssemblyVersionAttribute=false")
.Append($"/p:GenerateAssemblyFileVersionAttribute=false")
.Append($"/p:GenerateAssemblyInformationalVersionAttribute=false")
};
DotNetCorePack(projectFile.FullPath, settings);
});
RunTarget(target);