-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.cake
205 lines (167 loc) · 5.2 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
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
string target = Argument( "target", "taste" );
string testResultOutput = Argument( "test_result_dir", "_TestResults" );
const string gpsDataFolder = "./gpxdata";
#load "_cakefiles/GpxModifier.cake"
const string pretzelExe = "./_pretzel/src/Pretzel/bin/Debug/net6.0/Pretzel.dll";
const string pluginDir = "./_plugins";
const string siteDir = "./_plugins";
const string categoryPlugin = "./_plugins/Pretzel.Categories.dll";
const string extensionPlugin = "./_plugins/Pretzel.SethExtensions.dll";
const string activityPubPlugin = "./_plugins/KristofferStrube.ActivityStreams.dll";
const string mapPlugin = "./_plugins/MapPlugin.dll";
Task( "taste" )
.Does(
() =>
{
RunPretzel( "taste", false );
}
).Description( "Calls pretzel taste to try the site locally" );
Task( "generate" )
.Does(
() =>
{
EnsureDirectoryExists( siteDir );
CleanDirectory( siteDir );
RunPretzel( "bake", true );
}
).Description( "Builds the site for publishing." );
var runTestTask = Task( "run_tests" )
.Does(
() =>
{
DirectoryPath testResultDir = Directory( testResultOutput );
EnsureDirectoryExists( testResultDir );
CleanDirectory( testResultDir );
var settings = new DotNetTestSettings
{
NoBuild = false,
NoRestore = false,
Configuration = "Debug",
ResultsDirectory = testResultDir,
VSTestReportPath = testResultDir.CombineWithFilePath( "SiteTestResults.xml" ),
Verbosity = DotNetVerbosity.Normal
};
DotNetTest( "_WebsitePlugin/WebsiteTests/WebsiteTests.csproj", settings );
}
).Description( "Runs all Tests" );
if( DirectoryExists( siteDir ) == false )
{
runTestTask.IsDependentOn( "generate" );
}
Task( "build_pretzel" )
.Does(
() =>
{
BuildPretzel();
}
).Description( "Compiles Pretzel" );
Task( "build_plugin" )
.Does(
() =>
{
BuildPlugin();
}
).Description( "Builds the map plugin" );
Task( "build_all" )
.IsDependentOn( "build_pretzel" )
.IsDependentOn( "build_plugin")
.IsDependentOn( "taste" );
void BuildPretzel()
{
Information( "Building Pretzel..." );
DotNetBuildSettings settings = new DotNetBuildSettings
{
Configuration = "Debug"
};
DotNetBuild( "./_pretzel/src/Pretzel.sln", settings );
EnsureDirectoryExists( pluginDir );
// Move Pretzel.Categories.
{
FilePathCollection files = GetFiles( "./_pretzel/src/Pretzel.Categories/bin/Debug/net6.0/Pretzel.Categories.*" );
CopyFiles( files, Directory( pluginDir ) );
}
// Move Pretzel.SethExtensions
{
FilePathCollection files = GetFiles( "./_pretzel/src/Pretzel.SethExtensions/bin/Debug/net6.0/Pretzel.SethExtensions.*" );
CopyFiles( files, Directory( pluginDir ) );
}
// Move ActivityPub
{
FilePathCollection files = GetFiles( "./_pretzel/src/ActivityStreams/src/KristofferStrube.ActivityStreams/bin/Debug/net6.0/KristofferStrube.ActivityStreams.*" );
CopyFiles( files, Directory( pluginDir ) );
}
Information( "Building Pretzel... Done!" );
}
void BuildPlugin()
{
CheckPretzelDependency();
Information( "Building Plugin..." );
DotNetPublishSettings settings = new DotNetPublishSettings
{
Configuration = "Debug",
NoBuild = false,
NoRestore = false
};
DotNetPublish( "./_WebsitePlugin/MapPlugin/MapPlugin.csproj", settings );
EnsureDirectoryExists( pluginDir );
FilePathCollection files = GetFiles( "./_WebsitePlugin/MapPlugin/bin/Debug/net6.0/publish/MapPlugin.*" );
CopyFiles( files, Directory( pluginDir ) );
files = GetFiles( "./_WebsitePlugin/MapPlugin/bin/Debug/net6.0/publish/Geodesy.*" );
CopyFiles( files, Directory( pluginDir ) );
Information( "Building Plugin... Done!" );
}
void RunPretzel( string argument, bool abortOnFail )
{
CheckPretzelDependency();
CheckMapPluginDependency();
bool fail = false;
string onStdOut( string line )
{
if( string.IsNullOrWhiteSpace( line ) )
{
return line;
}
else if( line.StartsWith( "Failed to render template" ) )
{
fail = true;
}
Console.WriteLine( line );
return line;
}
ProcessSettings settings = new ProcessSettings
{
Arguments = ProcessArgumentBuilder.FromString( $"\"{pretzelExe}\" {argument} --debug" ),
Silent = false,
RedirectStandardOutput = abortOnFail,
RedirectedStandardOutputHandler = onStdOut
};
int exitCode = StartProcess( "dotnet", settings );
if( exitCode != 0 )
{
throw new Exception( $"Pretzel exited with exit code: {exitCode}" );
}
if( abortOnFail && fail )
{
throw new Exception( "Failed to render template" );
}
}
void CheckPretzelDependency()
{
if(
( FileExists( pretzelExe ) == false ) ||
( FileExists( categoryPlugin ) == false ) ||
( FileExists( extensionPlugin ) == false ) ||
( FileExists( activityPubPlugin ) == false )
)
{
BuildPretzel();
}
}
void CheckMapPluginDependency()
{
if( FileExists( mapPlugin ) == false )
{
BuildPlugin();
}
}
RunTarget( target );