-
Notifications
You must be signed in to change notification settings - Fork 24
Expand file tree
/
Copy pathbuild.cake
More file actions
144 lines (113 loc) · 4.36 KB
/
build.cake
File metadata and controls
144 lines (113 loc) · 4.36 KB
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
#addin "Cake.Git&version=5.0.1"
#tool "dotnet:?package=GitVersion.Tool&version=6.1.0"
#tool "nuget:?package=xunit.runner.console&version=2.9.3"
#tool "nuget:?package=NuGet.CommandLine&version=6.12.2"
var target = Argument("target", "Default");
var configuration = Argument("configuration", "Release");
var solution = "./src/Cake.Sonar.sln";
///////////////////////////////////////////////////////////////////////////////
// WAZZUP
///////////////////////////////////////////////////////////////////////////////
var local = BuildSystem.IsLocalBuild;
var isRunningOnAppVeyor = AppVeyor.IsRunningOnAppVeyor;
var isPullRequest = AppVeyor.Environment.PullRequest.IsPullRequest;
var buildNumber = AppVeyor.Environment.Build.Number;
var branchName = isRunningOnAppVeyor ? EnvironmentVariable("APPVEYOR_REPO_BRANCH") : GitBranchCurrent(DirectoryPath.FromString(".")).FriendlyName;
var isMasterBranch = System.String.Equals("master", branchName, System.StringComparison.OrdinalIgnoreCase);
var outputDirNuGet = new DirectoryPath("./nuget/").MakeAbsolute(Context.Environment);
///////////////////////////////////////////////////////////////////////////////
// VERSION
///////////////////////////////////////////////////////////////////////////////
var gitVersion = GitVersion();
///////////////////////////////////////////////////////////////////////////////
// PREPARE
///////////////////////////////////////////////////////////////////////////////
Task("PrintVersion")
.Does(() =>
{
Information("Current version is " + gitVersion.FullSemVer + ", nuget version " + gitVersion.SemVer);
});
Task("Clean")
.Does(() =>
{
EnsureDirectoryDoesNotExist(outputDirNuGet, new DeleteDirectorySettings
{
Recursive = true,
Force = true
});
CreateDirectory(outputDirNuGet);
});
Task("Restore-Nuget-Packages")
.IsDependentOn("Clean")
.Does(() =>
{
DotNetRestore(solution);
});
//////////////////////////////////////////////////////////////////////////////
// Build
//////////////////////////////////////////////////////////////////////////////
Task("Build")
.IsDependentOn("PrintVersion")
.IsDependentOn("Restore-Nuget-Packages")
.IsDependentOn("Clean")
.Does(() =>
{
var msBuildSettings = new DotNetMSBuildSettings()
{
Version = gitVersion.AssemblySemVer,
InformationalVersion = gitVersion.InformationalVersion,
PackageVersion = gitVersion.SemVer
};
msBuildSettings.WithProperty("PackageOutputPath", outputDirNuGet.FullPath);
var settings = new DotNetBuildSettings
{
Configuration = configuration,
MSBuildSettings = msBuildSettings
};
DotNetBuild(solution, settings);
});
Task("Test")
.IsDependentOn("Build")
.Does(() =>
{
DotNetTest("./src/Cake.Sonar.Test/Cake.Sonar.Test.csproj");
});
//////////////////////////////////////////////////////////////////////////////
// Nuget
//////////////////////////////////////////////////////////////////////////////
Task("Publish")
.IsDependentOn("Test")
.WithCriteria(() => isRunningOnAppVeyor)
.WithCriteria(() => !isPullRequest)
.WithCriteria(() => isMasterBranch)
.Does(() =>
{
var apiKey = EnvironmentVariable("NUGET_API_KEY");
if (string.IsNullOrEmpty(apiKey))
throw new InvalidOperationException("Could not resolve Nuget API key.");
var package = "./nuget/Cake.Sonar." + gitVersion.SemVer + ".nupkg";
// Push the package.
NuGetPush(package, new NuGetPushSettings
{
Source = "https://www.nuget.org/api/v2/package",
ApiKey = apiKey
});
});
///////////////////////////////////////////////////////////////////////////////
// APPVEYOR
///////////////////////////////////////////////////////////////////////////////
Task("Update-AppVeyor-Build-Number")
.WithCriteria(() => isRunningOnAppVeyor)
.Does(() =>
{
//AppVeyor.UpdateBuildVersion(gitVersion.FullSemVer);
});
Task("AppVeyor")
.IsDependentOn("Update-AppVeyor-Build-Number")
.IsDependentOn("Publish");
///////////////////////////////////////////////////////////////////////////////
// EXECUTION
///////////////////////////////////////////////////////////////////////////////
Task("Default")
.IsDependentOn("Test");
RunTarget(target);