-
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathcake.cs
More file actions
116 lines (99 loc) · 3 KB
/
cake.cs
File metadata and controls
116 lines (99 loc) · 3 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
#:sdk Cake.Sdk
#:package Cake.BuildSystems.Module@9.0.0
var target = Argument("target", "Pack");
//////////////////////////////////////////////////////////////////////
// TASKS
//////////////////////////////////////////////////////////////////////
Setup(context =>
{
var configuration = Argument("configuration", "Release");
InstallTool("dotnet:https://api.nuget.org/v3/index.json?package=GitVersion.Tool&version=6.7.0");
var version = GitVersion();
Information(
"Building Version: {0}, Configuration: {1}",
version.FullSemVer,
configuration);
return new BuildData(
Version: version.FullSemVer,
Configuration: configuration,
SolutionFile: "./src/Example.sln",
ArtifactsDirectory: "./artifacts",
MSBuildSettings: new DotNetMSBuildSettings()
.SetVersion(version.FullSemVer)
.SetConfiguration(configuration)
.WithProperty("TreatWarningsAsErrors", "true"));
});
Task("Clean")
.WithCriteria(c => HasArgument("rebuild"))
.Does<BuildData>((ctx, data) =>
{
CleanDirectories(data.DirectoriesToClean);
});
Task("Build")
.IsDependentOn("Clean")
.Does<BuildData>((ctx, data) =>
{
DotNetBuild(
data.SolutionFile.FullPath,
new DotNetBuildSettings
{
MSBuildSettings = data.MSBuildSettings
});
});
Task("Test")
.IsDependentOn("Build")
.Does<BuildData>((ctx, data) =>
{
DotNetTest(
data.SolutionFile.FullPath,
new DotNetTestSettings
{
MSBuildSettings = data.MSBuildSettings,
NoRestore = true,
NoBuild = true
});
});
Task("Pack")
.IsDependentOn("Test")
.Does<BuildData>((ctx, data) =>
{
DotNetPack(
data.SolutionFile.FullPath,
new DotNetPackSettings
{
MSBuildSettings = data.MSBuildSettings,
NoRestore = true,
NoBuild = true,
OutputDirectory = data.ArtifactsDirectory
});
});
Task("UploadArtifacts")
.IsDependentOn("Pack")
.Does<BuildData>((ctx, data) =>
GitHubActions.Commands.UploadArtifact(
data.ArtifactsDirectory,
"ExampleArtifacts"));
Task("GitHubActions")
.IsDependentOn("UploadArtifacts");
//////////////////////////////////////////////////////////////////////
// EXECUTION
//////////////////////////////////////////////////////////////////////
RunTarget(target);
//////////////////////////////////////////////////////////////////////
// Models
//////////////////////////////////////////////////////////////////////
public record BuildData(
string Version,
string Configuration,
FilePath SolutionFile,
DirectoryPath ArtifactsDirectory,
DotNetMSBuildSettings MSBuildSettings
)
{
public DirectoryPath[] DirectoriesToClean { get; init; } =
[
$"./src/Example/bin/{Configuration}",
$"./src/Example/obj/{Configuration}",
ArtifactsDirectory
];
}