This repository has been archived by the owner on Jan 18, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
/
build.cake
138 lines (111 loc) · 4.28 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
#tool "nuget:?package=Microsoft.TestPlatform&version=15.7.0"
#tool "nuget:?package=OpenCover&version=4.7.922"
#tool "nuget:?package=ReportGenerator&version=4.0.9"
#tool "nuget:?package=GitVersion.CommandLine&version=4.0.0"
#tool "nuget:?package=NuGet.CommandLine&version=4.9.2"
#tool "nuget:?package=chocolatey&version=0.10.11"
#addin "nuget:?package=Cake.FileHelpers&version=3.1.0"
#load "build/paths.cake"
var packageVersion = "0.2.0.0";
///////////////////////////////////////////////////////////////////////////////
// ARGUMENTS
///////////////////////////////////////////////////////////////////////////////
var target = Argument("target", "Compile");
var configuration = Argument("configuration", "Release");
var packageOutputPath = Argument<DirectoryPath>("PackageOutputPath", "packages");
///////////////////////////////////////////////////////////////////////////////
// Setup / Teardown
///////////////////////////////////////////////////////////////////////////////
// Executed BEFORE the first task.
Setup(context =>
{
EnsureDirectoryExists(packageOutputPath);
});
///////////////////////////////////////////////////////////////////////////////
// TASKS
///////////////////////////////////////////////////////////////////////////////
Task("Test-Resolve-Tool")
.Does(()=> {
FilePath nugetPath = Context.Tools.Resolve("choco.exe");
Information(nugetPath?.ToString()?? "not found");
});
Task("Clean")
.Does(()=>{
foreach (var dir in GetDirectories("**/Debug").Concat(GetDirectories("**/Release")))
{
Information($"Cleaning: {dir}");
CleanDirectory(dir);
}
CleanDirectory("TestResults");
});
Task("Restore-NuGet-Packages")
.IsDependentOn("Clean")
.Does(() =>
{
NuGetRestore(Paths.SolutionPath);
});
Task("Build")
.IsDependentOn("Restore-NuGet-Packages")
.Does(()=>{
MSBuild(Paths.SolutionPath.ToString(), settings => settings.SetConfiguration(configuration));
});
Task("Test")
.IsDependentOn("Build")
.Does(()=> {
VSTest($"**/bin/{configuration}/*.Test.dll", new VSTestSettings
{
EnableCodeCoverage = true,
InIsolation = true,
Logger = "trx",
Parallel = true,
TestAdapterPath = @"DependencyScanner.Core.Test\bin\Debug\"
});
});
Task("Version")
.Does(()=> {
Information($"Using version {packageVersion}");
// update assembly version
GitVersion(new GitVersionSettings
{
OutputType = GitVersionOutput.BuildServer,
UpdateAssemblyInfo = true
});
// could be commited
// GitCommit("./", "CakeBuild", "cake@build.com",$"Update assembly version to {packageVersion}")
});
Task("Remove-Packages")
.Does(()=>{
Information($"Cleaning {packageOutputPath}");
CleanDirectory(packageOutputPath);
});
Task("Pack-Chocolatey")
.IsDependentOn("Test")
.Does(()=> {
CheckComfiguration("Release", configuration);
// calculate new hash
var hash = CalculateFileHash(@"DependencyScanner.Standalone\bin\Release\DependencyScanner.Standalone.exe", HashAlgorithm.SHA256);
Information("New hash: {0}", hash.ToHex());
EnsureDoesNotExist(Paths.ChocoHashFile);
FileWriteText(Paths.ChocoHashFile, hash.ToHex());
// create shrim
using (System.IO.File.Create(@"DependencyScanner.Standalone\bin\Release\DependencyScanner.Standalone.exe.gui")){};
// choco pack
ChocolateyPack(
Paths.ChocoNuspecFile,
new ChocolateyPackSettings
{
Version = packageVersion
});
// move choco nuget to packages/choco/...
var chocoFileName=$"dependency-scanner.{packageVersion}.nupkg";
EnsureDirectoryExists(packageOutputPath);
var chocoPackageFileName = Combine(packageOutputPath, chocoFileName);
EnsureDoesNotExist(chocoPackageFileName);
MoveFile(chocoFileName, chocoPackageFileName);
});
//////////////////////////////////////////////////////////////////////
// TASK TARGETS
//////////////////////////////////////////////////////////////////////
Task("Default")
.IsDependentOn("Test");
RunTarget(target);