-
Notifications
You must be signed in to change notification settings - Fork 6
/
build.cake
162 lines (141 loc) · 3.85 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
155
156
157
158
159
160
161
162
#nullable enable
#addin nuget:?package=Cake.Git&version=4.0.0
using System.Text.RegularExpressions;
const string projDir = "./src/WindowsTerminalShaderTool";
const string projPath = "./src/WindowsTerminalShaderTool/WindowsTerminalShaderTool.csproj";
var target = Argument("target", "Run");
var configuration = Argument("configuration", "Release");
var nugetApi = "https://api.nuget.org/v3/index.json";
var nugetApiKey = EnvironmentVariable("NUGET_API_KEY");
record BuildData(
string? Version
);
Setup(ctx =>
{
var tip = GitLogTip(".");
var tags = GitTags(".", true);
var tipTag = tags
.FirstOrDefault(tag => tag.Target.Sha == tip.Sha)
;
string? version = null;
if (tipTag is not null)
{
var tagName = tipTag.FriendlyName;
var match = Regex.Match(tagName, @"^v(?<version>\d+\.\d+\.\d+)$");
if (match.Success)
{
version = match.Groups["version"].Value;
Information($"Tip is tagged with version: {version}");
}
else
{
Warning($"Tip is tagged, but the tag doesn't match the version schema: {tagName}");
}
}
else
{
Information("Tip is not tagged with version");
}
return new BuildData(version);
});
Task("Clean")
.WithCriteria(c => HasArgument("rebuild"))
.Does(() =>
{
Information($"Cleaning tool: {projDir}");
DotNetClean(projPath);
});
Task("Restore")
.IsDependentOn("Clean")
.Does(() =>
{
Information($"Restoring tool: {projDir}");
DotNetRestore(
projPath
, new()
{
LockedMode = true
});
});
Task("Build")
.IsDependentOn("Restore")
.Does(() =>
{
Information($"Building tool: {projDir}");
DotNetBuild(
projPath
, new()
{
Configuration = configuration
, NoRestore = true
});
});
Task("Pack")
.IsDependentOn("Build")
.Does<BuildData>((ctx, bd) =>
{
Information($"Packing tool: {projDir}");
var bs = new DotNetMSBuildSettings()
.SetVersion(bd.Version??"0.0.1")
;
DotNetPack(projPath, new()
{
Configuration = configuration
, NoBuild = true
, NoRestore = true
, MSBuildSettings = bs
});
});
Task("PublishToNuGet")
.WithCriteria<BuildData>((ctx, bd) => bd.Version is not null)
.IsDependentOn("Pack")
.Does<BuildData>((ctx, bd) =>
{
Information($"Publishing tool to nuget: {projDir}");
var packPath = $"{projDir}/nupkg/WindowsTerminalShaderTool.{bd.Version}.nupkg";
Information($"Publishing package: {packPath}");
DotNetNuGetPush(packPath, new()
{
ApiKey = nugetApiKey
, Source = nugetApi
});
});
Task("Run")
.IsDependentOn("Build")
.Does(() =>
{
Information($"Running tool: {projDir}");
DotNetRun(
projPath
, new DotNetRunSettings ()
{
// Already built by Build step
NoBuild = true
// Already restored by Restore step
, NoRestore = true
, Configuration = configuration
});
});
Task("AllMetaData")
.IsDependentOn("Clean")
.Does(() =>
{
Information("Building all metadata: ./gallery/all_metadata.json");
DotNetTool(".", "t4", "-o ./gallery/all_metadata.json ./src/T4Site/all_metadata.tt");
});
Task("GithubPages")
.IsDependentOn("Clean")
.Does(() =>
{
Information("Building Github Pages: ./docs/");
DotNetTool(".", "t4", "-o ./docs/index.html ./src/T4Site/index.tt");
});
Task("Site")
.IsDependentOn("AllMetaData")
.IsDependentOn("GithubPages")
;
Task("All")
.IsDependentOn("Pack")
.IsDependentOn("Site")
;
RunTarget(target);