forked from cake-contrib/Cake.Sonar
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.cake
154 lines (121 loc) · 6.04 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
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
#addin Cake.Git&version=0.19.0
#tool nuget:?package=GitVersion.CommandLine&version=4.0.0
#tool nuget:?package=xunit.runner.console&version=2.4.1
var target = Argument("target", "Default");
var configuration = Argument("configuration", "Release");
var solution = "./src/Cake.Sonar.sln";
var appName = "Cake.Sonar";
///////////////////////////////////////////////////////////////////////////////
// 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);
///////////////////////////////////////////////////////////////////////////////
// VERSION
///////////////////////////////////////////////////////////////////////////////
var gitVersion = GitVersion();
///////////////////////////////////////////////////////////////////////////////
// PREPARE
///////////////////////////////////////////////////////////////////////////////
Task("PrintVersion")
.Does(() => {
Information("Current version is " + gitVersion.FullSemVer + ", nuget version " + gitVersion.NuGetVersionV2);
});
Task("Clean")
.Does(() => {
CleanDirectory("./nuget");
});
Task("Restore-Nuget-Packages")
.IsDependentOn("Clean")
.Does(() => {
NuGetRestore(solution);
});
//////////////////////////////////////////////////////////////////////////////
// Build
//////////////////////////////////////////////////////////////////////////////
Task("Build")
.IsDependentOn("PrintVersion")
.IsDependentOn("Restore-Nuget-Packages")
.Does(() => {
MSBuild(solution,new MSBuildSettings {
Verbosity = Verbosity.Minimal,
Configuration = configuration
});
});
Task("Test")
.IsDependentOn("Build")
.Does(() => {
DotNetCoreTest("./src/Cake.Sonar.Test/Cake.Sonar.Test.csproj");
});
//////////////////////////////////////////////////////////////////////////////
// Nuget
//////////////////////////////////////////////////////////////////////////////
Task("Pack")
.IsDependentOn("Test")
.Does(() => {
CreateDirectory("nuget");
CleanDirectory("nuget");
var nuGetPackSettings = new NuGetPackSettings {
Id = appName,
Version = gitVersion.NuGetVersionV2,
Title = appName,
Authors = new[] {"Tom Staijen"},
Owners = new[] {"Tom Staijen", "cake-contrib"},
Description = "Run sonar for msbuild",
Summary = "Run sonar for msbuild",
IconUrl = new Uri("https://cdn.jsdelivr.net/gh/cake-contrib/graphics/png/cake-contrib-medium.png"),
ProjectUrl = new Uri("https://github.com/AgileArchitect/Cake.Sonar"),
LicenseUrl = new Uri("https://github.com/AgileArchitect/Cake.Sonar/blob/master/LICENCE"),
Tags = new [] {"Cake", "Sonar", "MSBuild"},
RequireLicenseAcceptance= false,
Symbols = false,
NoPackageAnalysis = true,
Files = new [] {
new NuSpecContent {Source = "netstandard2.0/Cake.Sonar.dll", Target = "lib/netstandard2.0" },
new NuSpecContent {Source = "netstandard2.0/Cake.Sonar.xml", Target = "lib/netstandard2.0" },
new NuSpecContent {Source = "net46/Cake.Sonar.dll", Target = "lib/net46" },
new NuSpecContent {Source = "net46/Cake.Sonar.xml", Target = "lib/net46" }
},
BasePath = "./src/Cake.Sonar/bin/release",
OutputDirectory = "./nuget"
};
NuGetPack(nuGetPackSettings);
});
Task("Publish")
.IsDependentOn("Pack")
.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.NuGetVersionV2 + ".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("Pack");
RunTarget(target);