-
-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathbuild.cake
More file actions
222 lines (211 loc) · 8.96 KB
/
Copy pathbuild.cake
File metadata and controls
222 lines (211 loc) · 8.96 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
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
// Install .NET Core Global tools.
#tool dotnet:?package=GitVersion.Tool&version=6.7.0
#load "build/records.cake"
#load "build/helpers.cake"
/*****************************
* Setup
*****************************/
Setup(
static context => {
var assertedVersions = context.GitVersion(new GitVersionSettings
{
OutputType = GitVersionOutput.Json
});
var gh = context.GitHubActions();
var buildDate = DateTime.UtcNow;
var runNumber = gh.IsRunningOnGitHubActions
? gh.Environment.Workflow.RunNumber
: (short)((buildDate - buildDate.Date).TotalSeconds/3);
var version = FormattableString
.Invariant($"{buildDate:yyyy.M.d}.{runNumber}");
var branchName = assertedVersions.BranchName;
var isMainBranch = StringComparer.OrdinalIgnoreCase.Equals("main", branchName);
var configuration = context.Argument("configuration", "Release");
context.Information("Building version {0} (Branch: {1}, IsMain: {2})",
version,
branchName,
isMainBranch);
var artifactsPath = context
.MakeAbsolute(context.Directory("./artifacts"));
var projectRootPath = context
.MakeAbsolute(context.Directory("src"));
return new BuildData(
version,
isMainBranch,
projectRootPath,
configuration,
new DotNetMSBuildSettings()
.SetConfiguration(configuration)
.SetVersion(version)
.WithProperty("Copyright", $"Mattias Karlsson © {DateTime.UtcNow.Year}")
.WithProperty("Authors", "devlead")
.WithProperty("Company", "devlead")
.WithProperty("PackageLicenseExpression", "MIT")
.WithProperty("PackageTags", "Statiq;Extensions;StaticContent;StaticSite;Blog;BlogEngine")
.WithProperty("PackageDescription", "Provides helpers and extensions for the static site generator Statiq, i.e. themes from http uri and TabGroup shortcode.")
.WithProperty("PackageIconUrl", "https://cdn.jsdelivr.net/gh/devlead/Devlead.Console.Template/src/devlead.png")
.WithProperty("PackageIcon", "devlead.png")
.WithProperty("PackageProjectUrl", "https://www.devlead.se")
.WithProperty("RepositoryUrl", "https://github.com/devlead/Devlead.Statiq.git")
.WithProperty("RepositoryType", "git")
.WithProperty("ContinuousIntegrationBuild", gh.IsRunningOnGitHubActions ? "true" : "false")
.WithProperty("EmbedUntrackedSources", "true"),
artifactsPath,
artifactsPath.Combine(version),
"Devlead.Statiq.TestWeb",
new [] {
"net8.0"
}
);
}
);
/*****************************
* Tasks
*****************************/
Task("Clean")
.Does<BuildData>(
static (context, data) => context.CleanDirectories(data.DirectoryPathsToClean)
)
.Then("Restore")
.Does<BuildData>(
static (context, data) => context.DotNetRestore(
data.ProjectRoot.FullPath,
new DotNetRestoreSettings {
MSBuildSettings = data.MSBuildSettings
}
)
)
.Then("DPI")
.Does<BuildData>(
static (context, data) => context.DotNetTool(
"tool",
new DotNetToolSettings {
HandleExitCode = exitCode => true,
ArgumentCustomization = args => args
.Append("run")
.Append("dpi")
.Append("nuget")
.Append("--silent")
.AppendSwitchQuoted("--output", "table")
.Append(
(
!string.IsNullOrWhiteSpace(context.EnvironmentVariable("NuGetReportSettings_SharedKey"))
&&
!string.IsNullOrWhiteSpace(context.EnvironmentVariable("NuGetReportSettings_WorkspaceId"))
)
? "report"
: "analyze"
)
.AppendSwitchQuoted("--buildversion", data.Version)
}
)
)
.Then("Build")
.Does<BuildData>(
static (context, data) => context.DotNetBuild(
data.ProjectRoot.FullPath,
new DotNetBuildSettings {
NoRestore = true,
MSBuildSettings = data.MSBuildSettings
}
)
)
.Then("Test")
.DoesForEach<BuildData, string>(
static (data, context) => data.TestTargetFrameworks,
static (data, item, context) => {
context.Information("Testing target framework {0}", item);
context.DotNetRun(
data.TestProjectPath.FullPath,
new DotNetRunSettings
{
Configuration = data.Configuration,
Framework = item,
NoRestore = true,
NoBuild = true,
ArgumentCustomization = args => args
.Append("--")
.AppendSwitch("-l", "Warning")
.AppendSwitchQuoted("--root", data.IntegrationTestPath.Combine(item).FullPath)
.AppendSwitchQuoted("--input",data.TestProjectPath.Combine("input").FullPath)
}
);
}
)
.Default()
.Then("Pack")
.Does<BuildData>(
static (context, data) => context.DotNetPack(
data.ProjectRoot.FullPath,
new DotNetPackSettings {
NoBuild = true,
NoRestore = true,
OutputDirectory = data.NuGetOutputPath,
MSBuildSettings = data.MSBuildSettings
}
)
)
.Then("Upload-Artifacts")
.WithCriteria<BuildData>( (context, data) => data.ShouldPushGitHubPackages())
.Does<BuildData>(
static (context, data) => context
.GitHubActions()
.Commands
.UploadArtifact(data.ArtifactsPath, "artifacts")
)
.Then("Push-GitHub-Packages")
.WithCriteria<BuildData>( (context, data) => data.ShouldPushGitHubPackages())
.DoesForEach<BuildData, FilePath>(
static (data, context)
=> context.GetFiles(data.NuGetOutputPath.FullPath + "/*.nupkg"),
static (data, item, context)
=> context.DotNetNuGetPush(
item.FullPath,
new DotNetNuGetPushSettings
{
Source = data.GitHubNuGetSource,
ApiKey = data.GitHubNuGetApiKey
}
)
)
.Then("Push-NuGet-Packages")
.WithCriteria<BuildData>( (context, data) => data.ShouldPushNuGetPackages())
.DoesForEach<BuildData, FilePath>(
static (data, context)
=> context.GetFiles(data.NuGetOutputPath.FullPath + "/*.nupkg"),
static (data, item, context)
=> context.DotNetNuGetPush(
item.FullPath,
new DotNetNuGetPushSettings
{
Source = data.NuGetSource,
ApiKey = data.NuGetApiKey
}
)
)
.Then("Create-GitHub-Release")
.WithCriteria<BuildData>( (context, data) => data.ShouldPushNuGetPackages())
.Does<BuildData>(
static (context, data) => context
.Command(
new CommandSettings {
ToolName = "GitHub CLI",
ToolExecutableNames = new []{ "gh.exe", "gh" },
EnvironmentVariables = { { "GH_TOKEN", data.GitHubNuGetApiKey } }
},
new ProcessArgumentBuilder()
.Append("release")
.Append("create")
.Append(data.Version)
.AppendSwitchQuoted("--title", data.Version)
.Append("--generate-notes")
.Append(string.Join(
' ',
context
.GetFiles(data.NuGetOutputPath.FullPath + "/*.nupkg")
.Select(path => path.FullPath.Quote())
))
)
)
.Then("GitHub-Actions")
.Run();