-
Notifications
You must be signed in to change notification settings - Fork 25
Expand file tree
/
Copy pathbuild.cake
More file actions
148 lines (127 loc) · 4.56 KB
/
Copy pathbuild.cake
File metadata and controls
148 lines (127 loc) · 4.56 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
145
146
147
148
#tool "dotnet:?package=GitVersion.Tool&version=6.8.2"
var target = Argument("target", "Default");
var configuration = Argument("configuration", "Release");
var nugetApiKey = Argument("nugetApiKey", EnvironmentVariable("NUGET_API_KEY") ?? "");
var nugetSource = Argument("nugetSource", EnvironmentVariable("NUGET_SOURCE") ?? "https://api.nuget.org/v3/index.json");
var solution = "./src/Cake.Sonar.sln";
///////////////////////////////////////////////////////////////////////////////
// WAZZUP
///////////////////////////////////////////////////////////////////////////////
var isLocalBuild = BuildSystem.IsLocalBuild;
var isPullRequest = BuildSystem.GitHubActions.Environment.PullRequest.IsPullRequest;
var gitHubEvent = EnvironmentVariable("GITHUB_EVENT_NAME");
var isReleaseCreation = "release".Equals(gitHubEvent, StringComparison.OrdinalIgnoreCase);
var isMasterBranch = "refs/heads/master".Equals(BuildSystem.GitHubActions.Environment.Workflow.Ref, StringComparison.OrdinalIgnoreCase);
var outputNuGetDir = new DirectoryPath("./nuget/").MakeAbsolute(Context.Environment);
///////////////////////////////////////////////////////////////////////////////
// VERSION
///////////////////////////////////////////////////////////////////////////////
var gitVersion = GitVersion();
///////////////////////////////////////////////////////////////////////////////
// PREPARE
///////////////////////////////////////////////////////////////////////////////
Setup(context =>
{
Information($"Local build: {isLocalBuild}");
Information($"Main branch: {isMasterBranch}");
Information($"Pull request: {isPullRequest}");
Information($"Ref: {BuildSystem.GitHubActions.Environment.Workflow.Ref}");
Information($"Is release creation: {isReleaseCreation}");
});
Task("PrintVersion")
.Does(() =>
{
Information("Current version is " + gitVersion.FullSemVer + ", NuGet version " + gitVersion.SemVer);
});
Task("Clean")
.Does(() =>
{
EnsureDirectoryDoesNotExist(outputNuGetDir, new DeleteDirectorySettings
{
Recursive = true,
Force = true
});
CreateDirectory(outputNuGetDir);
});
//////////////////////////////////////////////////////////////////////////////
// Build
//////////////////////////////////////////////////////////////////////////////
Task("Restore")
.Does(() =>
{
DotNetRestore(solution);
});
Task("Build")
.IsDependentOn("PrintVersion")
.IsDependentOn("Clean")
.IsDependentOn("Restore")
.Does(() =>
{
DotNetBuild(solution, new DotNetBuildSettings
{
Configuration = configuration,
NoRestore = true,
MSBuildSettings = new DotNetMSBuildSettings
{
Version = gitVersion.AssemblySemVer,
InformationalVersion = gitVersion.InformationalVersion,
ContinuousIntegrationBuild = !isLocalBuild
}
});
});
Task("Test")
.IsDependentOn("Build")
.Does(() =>
{
DotNetTest(solution, new DotNetTestSettings
{
Configuration = configuration,
NoRestore = true,
NoBuild = true
});
});
//////////////////////////////////////////////////////////////////////////////
// Nuget
//////////////////////////////////////////////////////////////////////////////
Task("Pack")
.IsDependentOn("Test")
.Does(() =>
{
DotNetPack(solution, new DotNetPackSettings
{
Configuration = configuration,
NoRestore = true,
NoBuild = true,
OutputDirectory = outputNuGetDir,
MSBuildSettings = new DotNetMSBuildSettings
{
PackageVersion = gitVersion.SemVer
}
});
});
Task("Publish")
.IsDependentOn("Pack")
.WithCriteria(() => isReleaseCreation)
.Does(() =>
{
if (string.IsNullOrEmpty(nugetApiKey))
{
throw new InvalidOperationException("Could not resolve NuGet API key.");
}
foreach (var package in GetFiles($"{outputNuGetDir}/*.nupkg"))
{
DotNetNuGetPush(package.FullPath, new DotNetNuGetPushSettings
{
ApiKey = nugetApiKey,
Source = nugetSource,
SkipDuplicate = true
});
}
});
///////////////////////////////////////////////////////////////////////////////
// EXECUTION
///////////////////////////////////////////////////////////////////////////////
Task("Default")
.IsDependentOn("Test")
.IsDependentOn("Publish");
RunTarget(target);