forked from agc93/spectre.cli.extensions.dependencyinjection
-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathcake.cs
More file actions
155 lines (135 loc) · 4.78 KB
/
cake.cs
File metadata and controls
155 lines (135 loc) · 4.78 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
149
150
151
152
153
154
155
#:sdk Cake.Sdk@6.1.1
#:package Cake.BuildSystems.Module@9.0.0
#:package Cake.MinVer@4.0.0
#:property IncludeAdditionalFiles=./build/*.cs
///////////////////////////////////////////////////////////////////////////////
// ARGUMENTS
///////////////////////////////////////////////////////////////////////////////
var target = Argument("target", "Default");
var configuration = Argument("configuration", "Release");
///////////////////////////////////////////////////////////////////////////////
// GLOBAL VARIABLES
///////////////////////////////////////////////////////////////////////////////
var projects = GetProjects(File("./src/Spectre.Console.Cli.Extensions.DependencyInjection.sln"), configuration);
var artifacts = "./dist/";
var frameworks = new List<string> { "netstandard2.0", "net8.0", "net9.0" };
var packageVersion = string.Empty;
///////////////////////////////////////////////////////////////////////////////
// SETUP / TEARDOWN
///////////////////////////////////////////////////////////////////////////////
Setup(ctx =>
{
InstallTool("dotnet:?package=minver-cli&version=6.0.0");
// Executed BEFORE the first task.
Information("Running tasks...");
CreateDirectory(artifacts);
packageVersion = BuildVersion(fallbackVersion);
if (FileExists("./build/.dotnet/dotnet.exe")) {
Information("Using local install of `dotnet` SDK!");
Context.Tools.RegisterFile("./build/.dotnet/dotnet.exe");
}
});
Teardown(ctx =>
{
// Executed AFTER the last task.
Information("Finished running tasks.");
});
///////////////////////////////////////////////////////////////////////////////
// TASKS
///////////////////////////////////////////////////////////////////////////////
Task("Clean")
.Does(() =>
{
// Clean solution directories.
foreach(var path in projects.AllProjectPaths)
{
Information("Cleaning {0}", path);
CleanDirectories(path + "/**/bin/" + configuration);
CleanDirectories(path + "/**/obj/" + configuration);
}
Information("Cleaning common files...");
CleanDirectory(artifacts);
});
Task("Restore")
.Does(() =>
{
// Restore all NuGet packages.
Information("Restoring solution...");
DotNetRestore(projects.SolutionPath);
});
Task("Build")
.IsDependentOn("Clean")
.IsDependentOn("Restore")
.Does(() =>
{
Information("Building solution...");
foreach (var project in projects.SourceProjectPaths) {
Information($"Building {project.GetDirectoryName()} for {configuration}");
var settings = new DotNetBuildSettings {
Configuration = configuration,
ArgumentCustomization = args => args.Append("/p:NoWarn=NU1701"),
};
DotNetBuild(project.FullPath, settings);
}
});
Task("NuGet")
.IsDependentOn("Build")
.Does(() =>
{
Information("Building NuGet package");
CreateDirectory(artifacts + "package/");
var packSettings = new DotNetPackSettings {
Configuration = configuration,
NoBuild = true,
OutputDirectory = $"{artifacts}package",
ArgumentCustomization = args => args
.Append($"/p:Version=\"{packageVersion}\"")
.Append("/p:NoWarn=\"NU1701 NU1602\"")
};
foreach(var project in projects.SourceProjectPaths) {
Information($"Packing {project.GetDirectoryName()}...");
DotNetPack(project.FullPath, packSettings);
}
});
Task("Post-Build")
.IsDependentOn("Build")
.Does(() =>
{
CreateDirectory(artifacts + "build");
foreach (var project in projects.SourceProjects) {
CreateDirectory(artifacts + "build/" + project.Name);
foreach (var framework in frameworks) {
var frameworkDir = $"{artifacts}build/{project.Name}/{framework}";
CreateDirectory(frameworkDir);
var files = GetFiles($"{project.Path.GetDirectory()}/bin/{configuration}/{framework}/*.*");
CopyFiles(files, frameworkDir);
}
}
});
Task("Publish-NuGet-Package")
.IsDependentOn("NuGet")
.WithCriteria(() => HasEnvironmentVariable("NUGET_TOKEN"))
.WithCriteria(() => HasEnvironmentVariable("GITHUB_REF"))
.WithCriteria(() => EnvironmentVariable("GITHUB_REF").StartsWith("refs/tags/v") || EnvironmentVariable("GITHUB_REF") == "refs/heads/main")
.Does(() => {
var nugetToken = EnvironmentVariable("NUGET_TOKEN");
var pkgFiles = GetFiles($"{artifacts}package/*.nupkg");
Information($"Pushing {pkgFiles.Count} package files!");
foreach(var pkgFile in pkgFiles)
{
Information($"Pushing {pkgFile}...");
DotNetNuGetPush(
pkgFile,
new DotNetNuGetPushSettings {
Source = "https://api.nuget.org/v3/index.json",
ApiKey = nugetToken
});
}
});
Task("Release")
.IsDependentOn("Default")
.IsDependentOn("Publish-NuGet-Package");
Task("Default")
.IsDependentOn("Post-Build")
.IsDependentOn("NuGet");
RunTarget(target);