Skip to content

Commit 98cc21f

Browse files
committed
More build tooling work, moved code generator to the tools directory
1 parent fce9620 commit 98cc21f

12 files changed

+146
-80
lines changed

.gitignore

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -278,9 +278,6 @@ paket-files/
278278
__pycache__/
279279
*.pyc
280280

281-
# Cake - Uncomment if you are using it
282-
[tT]ools/
283-
284281
# Docs
285282
docs/output/
286283
docs/config.wyam.packages.xml

NetlifySharp.sln

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,24 +9,22 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "tests", "tests", "{9D82AABF
99
EndProject
1010
Project("{D954291E-2A0B-460D-934E-DC6B0785DB48}") = "Files", "Files.shproj", "{C3D497EA-3113-4ED0-8806-94B20FC235DD}"
1111
EndProject
12-
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "NetlifySharp.Generator", "src\NetlifySharp.Generator\NetlifySharp.Generator.csproj", "{0DF66273-6B1F-476E-A9AD-ED83B7494F0F}"
13-
EndProject
1412
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "NetlifySharp", "src\NetlifySharp\NetlifySharp.csproj", "{41AF07B8-6EE0-4D1A-9E23-F42689059B9C}"
1513
EndProject
1614
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "build", "build", "{F66FF7CA-79C6-495B-A073-C83B22AFFE51}"
1715
EndProject
18-
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "NetlifySharp.Build", "build\NetlifySharp.Build\NetlifySharp.Build.csproj", "{073ADC33-A84E-470B-8220-89F8FCCD1FC1}"
16+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "NetlifySharp.Build", "build\NetlifySharp.Build\NetlifySharp.Build.csproj", "{073ADC33-A84E-470B-8220-89F8FCCD1FC1}"
17+
EndProject
18+
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "tools", "tools", "{112DF2B8-84D8-46DA-995B-53D4DC30FBC7}"
19+
EndProject
20+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "NetlifySharp.Generator", "tools\NetlifySharp.Generator\NetlifySharp.Generator.csproj", "{7A593078-C658-4F01-B5F3-98C6AE646F0B}"
1921
EndProject
2022
Global
2123
GlobalSection(SolutionConfigurationPlatforms) = preSolution
2224
Debug|Any CPU = Debug|Any CPU
2325
Release|Any CPU = Release|Any CPU
2426
EndGlobalSection
2527
GlobalSection(ProjectConfigurationPlatforms) = postSolution
26-
{0DF66273-6B1F-476E-A9AD-ED83B7494F0F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
27-
{0DF66273-6B1F-476E-A9AD-ED83B7494F0F}.Debug|Any CPU.Build.0 = Debug|Any CPU
28-
{0DF66273-6B1F-476E-A9AD-ED83B7494F0F}.Release|Any CPU.ActiveCfg = Release|Any CPU
29-
{0DF66273-6B1F-476E-A9AD-ED83B7494F0F}.Release|Any CPU.Build.0 = Release|Any CPU
3028
{41AF07B8-6EE0-4D1A-9E23-F42689059B9C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
3129
{41AF07B8-6EE0-4D1A-9E23-F42689059B9C}.Debug|Any CPU.Build.0 = Debug|Any CPU
3230
{41AF07B8-6EE0-4D1A-9E23-F42689059B9C}.Release|Any CPU.ActiveCfg = Release|Any CPU
@@ -35,14 +33,18 @@ Global
3533
{073ADC33-A84E-470B-8220-89F8FCCD1FC1}.Debug|Any CPU.Build.0 = Debug|Any CPU
3634
{073ADC33-A84E-470B-8220-89F8FCCD1FC1}.Release|Any CPU.ActiveCfg = Release|Any CPU
3735
{073ADC33-A84E-470B-8220-89F8FCCD1FC1}.Release|Any CPU.Build.0 = Release|Any CPU
36+
{7A593078-C658-4F01-B5F3-98C6AE646F0B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
37+
{7A593078-C658-4F01-B5F3-98C6AE646F0B}.Debug|Any CPU.Build.0 = Debug|Any CPU
38+
{7A593078-C658-4F01-B5F3-98C6AE646F0B}.Release|Any CPU.ActiveCfg = Release|Any CPU
39+
{7A593078-C658-4F01-B5F3-98C6AE646F0B}.Release|Any CPU.Build.0 = Release|Any CPU
3840
EndGlobalSection
3941
GlobalSection(SolutionProperties) = preSolution
4042
HideSolutionNode = FALSE
4143
EndGlobalSection
4244
GlobalSection(NestedProjects) = preSolution
43-
{0DF66273-6B1F-476E-A9AD-ED83B7494F0F} = {1D456B5E-2874-446C-8CFD-5134FC11ACAF}
4445
{41AF07B8-6EE0-4D1A-9E23-F42689059B9C} = {1D456B5E-2874-446C-8CFD-5134FC11ACAF}
4546
{073ADC33-A84E-470B-8220-89F8FCCD1FC1} = {F66FF7CA-79C6-495B-A073-C83B22AFFE51}
47+
{7A593078-C658-4F01-B5F3-98C6AE646F0B} = {112DF2B8-84D8-46DA-995B-53D4DC30FBC7}
4648
EndGlobalSection
4749
GlobalSection(ExtensibilityGlobals) = postSolution
4850
SolutionGuid = {17A4CA1C-8EEE-4D62-A5F2-06B88FEF22CB}

build/NetlifySharp.Build/NetlifySharp.Build.csproj

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,19 @@
33
<PropertyGroup>
44
<OutputType>Exe</OutputType>
55
<TargetFramework>netcoreapp3.0</TargetFramework>
6+
<RunWorkingDirectory>$(MSBuildProjectDirectory)</RunWorkingDirectory>
67
<DefaultItemExcludes>$(DefaultItemExcludes);output\**;temp\**;reportgenerator.exe;nuget.exe</DefaultItemExcludes>
78
</PropertyGroup>
89

910
<ItemGroup>
10-
<PackageReference Include="Statiq.App" Version="1.0.0-alpha.18" />
11+
<PackageReference Include="Statiq.App" Version="1.0.0-alpha.19" />
1112
</ItemGroup>
13+
14+
<!--
15+
<ItemGroup>
16+
<ProjectReference Include="..\..\..\..\statiqdev\Statiq.Framework\src\core\Statiq.App\Statiq.App.csproj" />
17+
<ProjectReference Include="..\..\..\..\statiqdev\Statiq.Framework\src\core\Statiq.Common\Statiq.Common.csproj" />
18+
<ProjectReference Include="..\..\..\..\statiqdev\Statiq.Framework\src\core\Statiq.Core\Statiq.Core.csproj" />
19+
</ItemGroup>
20+
-->
1221
</Project>

build/NetlifySharp.Build/Program.cs

Lines changed: 124 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,8 @@ namespace NetlifySharp.Build
1111
{
1212
public class Program
1313
{
14-
// Pipeline names
15-
public const string Build = nameof(Build);
16-
public const string Test = nameof(Test);
17-
public const string Docs = nameof(Docs);
18-
public const string Pack = nameof(Pack);
19-
public const string Publish = nameof(Publish);
14+
private const string BuildVersion = nameof(BuildVersion);
15+
private const string BuildProperties = nameof(BuildProperties);
2016

2117
public static async Task<int> Main(string[] args) => await Bootstrapper
2218
.CreateDefault(args, DefaultsToAdd.All & ~DefaultsToAdd.Commands)
@@ -29,85 +25,147 @@ public static async Task<int> Main(string[] args) => await Bootstrapper
2925
{
3026
version += "-build-" + x["BUILD_BUILDNUMBER"];
3127
}
32-
x["BuildVersion"] = version;
33-
x["BuildProperties"] = $"-p:Version={version} -p:AssemblyVersion={version} -p:FileVersion={version}";
28+
x[BuildVersion] = version;
29+
x[BuildProperties] = $"-p:Version={version} -p:AssemblyVersion={version} -p:FileVersion={version}";
3430
})
3531

3632
// Add build commands to the CLI
3733
.AddBuildCommand("build", "Builds all projects.", nameof(Build))
3834
.AddBuildCommand("test", "Builds and tests all projects.", nameof(Test))
39-
.AddBuildCommand("docs", "Previews the documentation.", nameof(Docs))
4035
.AddBuildCommand("pack", "Packs the packages.", nameof(Pack))
36+
.AddBuildCommand("zip", "Zips the binaries.", nameof(Zip))
4137
.AddBuildCommand("publish", "Publishes the packages and documentation site.", nameof(Publish))
4238

4339
// Add pipelines
44-
.BuildPipeline(Build, pipeline => pipeline
45-
.ManuallyExecute()
46-
.WithProcessModules(
40+
.AddPipeline<Build>()
41+
.AddPipeline<Test>()
42+
.AddPipeline<Pack>()
43+
.AddPipeline<Zip>()
44+
.AddPipeline<Publish>()
45+
46+
// Run the app
47+
.RunAsync();
48+
49+
private static DirectoryPath GetBuildPath(IDocument doc, IExecutionContext ctx) =>
50+
ctx.FileSystem.GetOutputPath((DirectoryPath)("build/" + doc.Source.Directory.Name));
51+
52+
public class Build : Pipeline
53+
{
54+
public Build()
55+
{
56+
ExecutionPolicy = ExecutionPolicy.Manual;
57+
ProcessModules = new ModuleList
58+
{
4759
new ReadFiles("../../../src/*/*.csproj"),
48-
new StartProcess(
49-
"dotnet",
50-
Config.FromDocument((doc, ctx) => $"build \"{doc.Source.FullPath}\" {ctx.Settings.GetString("BuildProperties")}"))
60+
new StartProcess("dotnet")
61+
.WithArgument("build")
62+
.WithArgument(Config.FromDocument(doc => doc.Source.FullPath), true)
63+
.WithArgument("-o", Config.FromDocument((doc, ctx) => GetBuildPath(doc, ctx).FullPath), true)
64+
.WithArgument(Config.FromSetting<string>(BuildProperties))
5165
.WithSequentialExecution()
52-
.LogOutput()))
66+
.LogOutput()
67+
};
68+
}
69+
}
5370

54-
.BuildPipeline(Test, pipeline => pipeline
55-
.ManuallyExecute()
56-
.WithDependencies(Build)
57-
.WithProcessModules(
71+
public class Test : Pipeline
72+
{
73+
public Test()
74+
{
75+
ExecutionPolicy = ExecutionPolicy.Manual;
76+
Dependencies.Add(nameof(Build));
77+
ProcessModules = new ModuleList
78+
{
5879
new ReadFiles("../../../tests/*/*.csproj"),
59-
new StartProcess(
60-
"dotnet",
61-
Config.FromDocument((doc, ctx) =>
62-
{
63-
StringBuilder builder = new StringBuilder($"test --no-build --no-restore \"{doc.Source.FullPath}\" {ctx.Settings.GetString("BuildProperties")} /p:CollectCoverage=true");
64-
if (ctx.Settings.ContainsKey("BUILD_BUILDNUMBER"))
65-
{
66-
// We're in Azure Pipelines so add the test logger
67-
builder.Append(" --test-adapter-path:. --logger:AzurePipelines");
68-
}
69-
return builder.ToString();
70-
}))
80+
new StartProcess("dotnet")
81+
.WithArgument("test")
82+
.WithArgument("--no-build")
83+
.WithArgument("--no-restore")
84+
.WithArgument(Config.FromDocument(doc => doc.Source.FullPath))
85+
.WithArgument("-o", Config.FromDocument((doc, ctx) => GetBuildPath(doc, ctx).FullPath), true)
86+
.WithArgument(Config.FromSetting<string>(BuildProperties))
87+
.WithArgument("/p:CollectCoverage=true")
88+
.WithArgument(Config.FromSettings(settings => settings.ContainsKey("BUILD_BUILDNUMBER") ? "--test-adapter-path:. --logger:AzurePipelines" : null))
7189
.WithSequentialExecution()
72-
.LogOutput()))
90+
.LogOutput()
91+
};
92+
}
93+
}
7394

74-
.BuildPipeline(Pack, pipeline => pipeline
75-
.ManuallyExecute()
76-
.WithDependencies(Test)
77-
.WithProcessModules(
78-
new StartProcess(
79-
"dotnet",
80-
Config.FromContext(ctx => $"pack ../../src/NetlifySharp/NetlifySharp.csproj --no-build --no-restore -o \"{ctx.FileSystem.GetOutputDirectory("packages").Path}\" {ctx.Settings.GetString("BuildProperties")}"))
95+
public class Pack : Pipeline
96+
{
97+
public Pack()
98+
{
99+
ExecutionPolicy = ExecutionPolicy.Manual;
100+
Dependencies.Add(nameof(Test));
101+
ProcessModules = new ModuleList
102+
{
103+
new StartProcess("dotnet")
104+
.WithArgument("pack")
105+
.WithArgument("../../src/NetlifySharp/NetlifySharp.csproj", true)
106+
.WithArgument("--no-build")
107+
.WithArgument("--no-restore")
108+
.WithArgument("-o", Config.FromContext(ctx => ctx.FileSystem.GetOutputDirectory("packages").Path.FullPath), true)
109+
.WithArgument(Config.FromSetting<string>(BuildProperties))
81110
.LogOutput(),
82-
new ReadFiles(Config.FromContext(ctx => $"{ctx.FileSystem.GetOutputDirectory("packages").Path}/*.nupkg")),
83-
new ExecuteIf(Config.FromContext(ctx => ctx.Settings.ContainsKey("DAVIDGLICK_CERTPASS") && ctx.FileSystem.GetRootFile("../../digicert-davidglick.pfx").Exists))
111+
new ReadFiles(Config.FromContext(ctx => $"{ctx.FileSystem.GetOutputDirectory("packages")}/*.nupkg")),
112+
new ExecuteIf(Config.FromContext(ctx => ctx.ContainsKey("DAVIDGLICK_CERTPASS") && ctx.FileSystem.GetRootFile("../../digicert-davidglick.pfx").Exists))
84113
{
85-
new StartProcess(
86-
"nuget",
87-
Config.FromDocument((doc, ctx) =>
88-
{
89-
string certPath = ctx.FileSystem.GetRootFile("../../digicert-davidglick.pfx").Path.FullPath;
90-
string password = ctx.Settings.GetString("DAVIDGLICK_CERTPASS");
91-
return $"sign \"{doc.Source.FullPath}\" -CertificatePath \"{certPath}\" -CertificatePassword \"{password}\" -Timestamper \"http://timestamp.digicert.com\" -NonInteractive";
92-
}))
114+
new StartProcess("nuget")
115+
.WithArgument("sign")
116+
.WithArgument(Config.FromDocument(doc => doc.Source.FullPath), true)
117+
.WithArgument("-CertificatePath", Config.FromContext(ctx => ctx.FileSystem.GetRootFile("../../digicert-davidglick.pfx").Path.FullPath), true)
118+
.WithArgument("-CertificatePassword", Config.FromSetting<string>("DAVIDGLICK_CERTPASS"), true)
119+
.WithArgument("-Timestamper", "http://timestamp.digicert.com", true)
120+
.WithArgument("-NonInteractive")
93121
.LogOutput()
94-
}))
122+
}
123+
};
124+
}
125+
}
95126

96-
// TODO: Generate zip
97-
// TODO: Generate GitHub release
98-
// TODO: Run docs generator with deployment
99-
.BuildPipeline(Publish, pipeline => pipeline
100-
.ManuallyExecute()
101-
.WithDependencies(Pack)
102-
.WithProcessModules(
103-
new ReadFiles(Config.FromContext(ctx => $"{ctx.FileSystem.GetOutputDirectory("packages").Path}/*.nupkg")),
104-
new StartProcess(
105-
"dotnet",
106-
Config.FromDocument((doc, ctx) => $"nuget push --api-key {ctx.Settings.GetString("NUGET_KEY")} --source \"https://api.nuget.org/v3/index.json\" \"{doc.Source.FullPath}\" "))
107-
.WithSequentialExecution()
108-
.LogOutput()))
127+
public class Zip : Pipeline
128+
{
129+
public Zip()
130+
{
131+
ExecutionPolicy = ExecutionPolicy.Manual;
132+
Dependencies.Add(nameof(Test));
133+
ProcessModules = new ModuleList
134+
{
135+
new ReadFiles("../../../src/*/*.csproj"),
136+
new ExecuteModules(
137+
new ExecuteConfig(Config.FromDocument((doc, ctx) =>
138+
(object)new CopyFiles("../../../README.md", "../../../ReleaseNotes.md", "../../../LICENSE")
139+
.To(x => Task.FromResult(GetBuildPath(doc, ctx).CombineFile(x.Path.FileName)))))),
140+
new ZipDirectory(Config.FromDocument(GetBuildPath)),
141+
new SetDestination(Config.FromDocument((doc, ctx) => (FilePath)$"zip/{doc.Source.FileNameWithoutExtension}-{ctx.GetString(BuildVersion)}.zip")),
142+
new WriteFiles()
143+
};
144+
}
145+
}
109146

110-
// Run the app
111-
.RunAsync();
147+
// TODO: Generate zip
148+
// TODO: Generate GitHub release
149+
// TODO: Run docs generator with deployment
150+
public class Publish : Pipeline
151+
{
152+
public Publish()
153+
{
154+
ExecutionPolicy = ExecutionPolicy.Manual;
155+
Dependencies.Add(nameof(Pack));
156+
ProcessModules = new ModuleList
157+
{
158+
new ReadFiles(Config.FromContext(ctx => $"{ctx.FileSystem.GetOutputDirectory("packages")}/*.nupkg")),
159+
new StartProcess("dotnet")
160+
.WithArgument("nuget")
161+
.WithArgument("push")
162+
.WithArgument("--api-key", Config.FromSetting<string>("NUGET_KEY"))
163+
.WithArgument("--source", "https://api.nuget.org/v3/index.json", true)
164+
.WithArgument(Config.FromDocument(doc => doc.Source.FullPath), true)
165+
.WithSequentialExecution()
166+
.LogOutput()
167+
};
168+
}
169+
}
112170
}
113171
}

src/NetlifySharp.Generator/NetlifySharp.Generator.csproj renamed to tools/NetlifySharp.Generator/NetlifySharp.Generator.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
</ItemGroup>
1313

1414
<ItemGroup>
15-
<ProjectReference Include="..\NetlifySharp\NetlifySharp.csproj" />
15+
<ProjectReference Include="..\..\src\NetlifySharp\NetlifySharp.csproj" />
1616
</ItemGroup>
1717

1818
</Project>

0 commit comments

Comments
 (0)