Skip to content

Commit

Permalink
More build tooling work, moved code generator to the tools directory
Browse files Browse the repository at this point in the history
  • Loading branch information
daveaglick committed Nov 22, 2019
1 parent fce9620 commit 98cc21f
Show file tree
Hide file tree
Showing 12 changed files with 146 additions and 80 deletions.
3 changes: 0 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -278,9 +278,6 @@ paket-files/
__pycache__/
*.pyc

# Cake - Uncomment if you are using it
[tT]ools/

# Docs
docs/output/
docs/config.wyam.packages.xml
Expand Down
18 changes: 10 additions & 8 deletions NetlifySharp.sln
Original file line number Diff line number Diff line change
Expand Up @@ -9,24 +9,22 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "tests", "tests", "{9D82AABF
EndProject
Project("{D954291E-2A0B-460D-934E-DC6B0785DB48}") = "Files", "Files.shproj", "{C3D497EA-3113-4ED0-8806-94B20FC235DD}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "NetlifySharp.Generator", "src\NetlifySharp.Generator\NetlifySharp.Generator.csproj", "{0DF66273-6B1F-476E-A9AD-ED83B7494F0F}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "NetlifySharp", "src\NetlifySharp\NetlifySharp.csproj", "{41AF07B8-6EE0-4D1A-9E23-F42689059B9C}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "build", "build", "{F66FF7CA-79C6-495B-A073-C83B22AFFE51}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "NetlifySharp.Build", "build\NetlifySharp.Build\NetlifySharp.Build.csproj", "{073ADC33-A84E-470B-8220-89F8FCCD1FC1}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "NetlifySharp.Build", "build\NetlifySharp.Build\NetlifySharp.Build.csproj", "{073ADC33-A84E-470B-8220-89F8FCCD1FC1}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "tools", "tools", "{112DF2B8-84D8-46DA-995B-53D4DC30FBC7}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "NetlifySharp.Generator", "tools\NetlifySharp.Generator\NetlifySharp.Generator.csproj", "{7A593078-C658-4F01-B5F3-98C6AE646F0B}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{0DF66273-6B1F-476E-A9AD-ED83B7494F0F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{0DF66273-6B1F-476E-A9AD-ED83B7494F0F}.Debug|Any CPU.Build.0 = Debug|Any CPU
{0DF66273-6B1F-476E-A9AD-ED83B7494F0F}.Release|Any CPU.ActiveCfg = Release|Any CPU
{0DF66273-6B1F-476E-A9AD-ED83B7494F0F}.Release|Any CPU.Build.0 = Release|Any CPU
{41AF07B8-6EE0-4D1A-9E23-F42689059B9C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{41AF07B8-6EE0-4D1A-9E23-F42689059B9C}.Debug|Any CPU.Build.0 = Debug|Any CPU
{41AF07B8-6EE0-4D1A-9E23-F42689059B9C}.Release|Any CPU.ActiveCfg = Release|Any CPU
Expand All @@ -35,14 +33,18 @@ Global
{073ADC33-A84E-470B-8220-89F8FCCD1FC1}.Debug|Any CPU.Build.0 = Debug|Any CPU
{073ADC33-A84E-470B-8220-89F8FCCD1FC1}.Release|Any CPU.ActiveCfg = Release|Any CPU
{073ADC33-A84E-470B-8220-89F8FCCD1FC1}.Release|Any CPU.Build.0 = Release|Any CPU
{7A593078-C658-4F01-B5F3-98C6AE646F0B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{7A593078-C658-4F01-B5F3-98C6AE646F0B}.Debug|Any CPU.Build.0 = Debug|Any CPU
{7A593078-C658-4F01-B5F3-98C6AE646F0B}.Release|Any CPU.ActiveCfg = Release|Any CPU
{7A593078-C658-4F01-B5F3-98C6AE646F0B}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(NestedProjects) = preSolution
{0DF66273-6B1F-476E-A9AD-ED83B7494F0F} = {1D456B5E-2874-446C-8CFD-5134FC11ACAF}
{41AF07B8-6EE0-4D1A-9E23-F42689059B9C} = {1D456B5E-2874-446C-8CFD-5134FC11ACAF}
{073ADC33-A84E-470B-8220-89F8FCCD1FC1} = {F66FF7CA-79C6-495B-A073-C83B22AFFE51}
{7A593078-C658-4F01-B5F3-98C6AE646F0B} = {112DF2B8-84D8-46DA-995B-53D4DC30FBC7}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {17A4CA1C-8EEE-4D62-A5F2-06B88FEF22CB}
Expand Down
11 changes: 10 additions & 1 deletion build/NetlifySharp.Build/NetlifySharp.Build.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,19 @@
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp3.0</TargetFramework>
<RunWorkingDirectory>$(MSBuildProjectDirectory)</RunWorkingDirectory>
<DefaultItemExcludes>$(DefaultItemExcludes);output\**;temp\**;reportgenerator.exe;nuget.exe</DefaultItemExcludes>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Statiq.App" Version="1.0.0-alpha.18" />
<PackageReference Include="Statiq.App" Version="1.0.0-alpha.19" />
</ItemGroup>

<!--
<ItemGroup>
<ProjectReference Include="..\..\..\..\statiqdev\Statiq.Framework\src\core\Statiq.App\Statiq.App.csproj" />
<ProjectReference Include="..\..\..\..\statiqdev\Statiq.Framework\src\core\Statiq.Common\Statiq.Common.csproj" />
<ProjectReference Include="..\..\..\..\statiqdev\Statiq.Framework\src\core\Statiq.Core\Statiq.Core.csproj" />
</ItemGroup>
-->
</Project>
190 changes: 124 additions & 66 deletions build/NetlifySharp.Build/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,8 @@ namespace NetlifySharp.Build
{
public class Program
{
// Pipeline names
public const string Build = nameof(Build);
public const string Test = nameof(Test);
public const string Docs = nameof(Docs);
public const string Pack = nameof(Pack);
public const string Publish = nameof(Publish);
private const string BuildVersion = nameof(BuildVersion);
private const string BuildProperties = nameof(BuildProperties);

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

// Add build commands to the CLI
.AddBuildCommand("build", "Builds all projects.", nameof(Build))
.AddBuildCommand("test", "Builds and tests all projects.", nameof(Test))
.AddBuildCommand("docs", "Previews the documentation.", nameof(Docs))
.AddBuildCommand("pack", "Packs the packages.", nameof(Pack))
.AddBuildCommand("zip", "Zips the binaries.", nameof(Zip))
.AddBuildCommand("publish", "Publishes the packages and documentation site.", nameof(Publish))

// Add pipelines
.BuildPipeline(Build, pipeline => pipeline
.ManuallyExecute()
.WithProcessModules(
.AddPipeline<Build>()
.AddPipeline<Test>()
.AddPipeline<Pack>()
.AddPipeline<Zip>()
.AddPipeline<Publish>()

// Run the app
.RunAsync();

private static DirectoryPath GetBuildPath(IDocument doc, IExecutionContext ctx) =>
ctx.FileSystem.GetOutputPath((DirectoryPath)("build/" + doc.Source.Directory.Name));

public class Build : Pipeline
{
public Build()
{
ExecutionPolicy = ExecutionPolicy.Manual;
ProcessModules = new ModuleList
{
new ReadFiles("../../../src/*/*.csproj"),
new StartProcess(
"dotnet",
Config.FromDocument((doc, ctx) => $"build \"{doc.Source.FullPath}\" {ctx.Settings.GetString("BuildProperties")}"))
new StartProcess("dotnet")
.WithArgument("build")
.WithArgument(Config.FromDocument(doc => doc.Source.FullPath), true)
.WithArgument("-o", Config.FromDocument((doc, ctx) => GetBuildPath(doc, ctx).FullPath), true)
.WithArgument(Config.FromSetting<string>(BuildProperties))
.WithSequentialExecution()
.LogOutput()))
.LogOutput()
};
}
}

.BuildPipeline(Test, pipeline => pipeline
.ManuallyExecute()
.WithDependencies(Build)
.WithProcessModules(
public class Test : Pipeline
{
public Test()
{
ExecutionPolicy = ExecutionPolicy.Manual;
Dependencies.Add(nameof(Build));
ProcessModules = new ModuleList
{
new ReadFiles("../../../tests/*/*.csproj"),
new StartProcess(
"dotnet",
Config.FromDocument((doc, ctx) =>
{
StringBuilder builder = new StringBuilder($"test --no-build --no-restore \"{doc.Source.FullPath}\" {ctx.Settings.GetString("BuildProperties")} /p:CollectCoverage=true");
if (ctx.Settings.ContainsKey("BUILD_BUILDNUMBER"))
{
// We're in Azure Pipelines so add the test logger
builder.Append(" --test-adapter-path:. --logger:AzurePipelines");
}
return builder.ToString();
}))
new StartProcess("dotnet")
.WithArgument("test")
.WithArgument("--no-build")
.WithArgument("--no-restore")
.WithArgument(Config.FromDocument(doc => doc.Source.FullPath))
.WithArgument("-o", Config.FromDocument((doc, ctx) => GetBuildPath(doc, ctx).FullPath), true)
.WithArgument(Config.FromSetting<string>(BuildProperties))
.WithArgument("/p:CollectCoverage=true")
.WithArgument(Config.FromSettings(settings => settings.ContainsKey("BUILD_BUILDNUMBER") ? "--test-adapter-path:. --logger:AzurePipelines" : null))
.WithSequentialExecution()
.LogOutput()))
.LogOutput()
};
}
}

.BuildPipeline(Pack, pipeline => pipeline
.ManuallyExecute()
.WithDependencies(Test)
.WithProcessModules(
new StartProcess(
"dotnet",
Config.FromContext(ctx => $"pack ../../src/NetlifySharp/NetlifySharp.csproj --no-build --no-restore -o \"{ctx.FileSystem.GetOutputDirectory("packages").Path}\" {ctx.Settings.GetString("BuildProperties")}"))
public class Pack : Pipeline
{
public Pack()
{
ExecutionPolicy = ExecutionPolicy.Manual;
Dependencies.Add(nameof(Test));
ProcessModules = new ModuleList
{
new StartProcess("dotnet")
.WithArgument("pack")
.WithArgument("../../src/NetlifySharp/NetlifySharp.csproj", true)
.WithArgument("--no-build")
.WithArgument("--no-restore")
.WithArgument("-o", Config.FromContext(ctx => ctx.FileSystem.GetOutputDirectory("packages").Path.FullPath), true)
.WithArgument(Config.FromSetting<string>(BuildProperties))
.LogOutput(),
new ReadFiles(Config.FromContext(ctx => $"{ctx.FileSystem.GetOutputDirectory("packages").Path}/*.nupkg")),
new ExecuteIf(Config.FromContext(ctx => ctx.Settings.ContainsKey("DAVIDGLICK_CERTPASS") && ctx.FileSystem.GetRootFile("../../digicert-davidglick.pfx").Exists))
new ReadFiles(Config.FromContext(ctx => $"{ctx.FileSystem.GetOutputDirectory("packages")}/*.nupkg")),
new ExecuteIf(Config.FromContext(ctx => ctx.ContainsKey("DAVIDGLICK_CERTPASS") && ctx.FileSystem.GetRootFile("../../digicert-davidglick.pfx").Exists))
{
new StartProcess(
"nuget",
Config.FromDocument((doc, ctx) =>
{
string certPath = ctx.FileSystem.GetRootFile("../../digicert-davidglick.pfx").Path.FullPath;
string password = ctx.Settings.GetString("DAVIDGLICK_CERTPASS");
return $"sign \"{doc.Source.FullPath}\" -CertificatePath \"{certPath}\" -CertificatePassword \"{password}\" -Timestamper \"http://timestamp.digicert.com\" -NonInteractive";
}))
new StartProcess("nuget")
.WithArgument("sign")
.WithArgument(Config.FromDocument(doc => doc.Source.FullPath), true)
.WithArgument("-CertificatePath", Config.FromContext(ctx => ctx.FileSystem.GetRootFile("../../digicert-davidglick.pfx").Path.FullPath), true)
.WithArgument("-CertificatePassword", Config.FromSetting<string>("DAVIDGLICK_CERTPASS"), true)
.WithArgument("-Timestamper", "http://timestamp.digicert.com", true)
.WithArgument("-NonInteractive")
.LogOutput()
}))
}
};
}
}

// TODO: Generate zip
// TODO: Generate GitHub release
// TODO: Run docs generator with deployment
.BuildPipeline(Publish, pipeline => pipeline
.ManuallyExecute()
.WithDependencies(Pack)
.WithProcessModules(
new ReadFiles(Config.FromContext(ctx => $"{ctx.FileSystem.GetOutputDirectory("packages").Path}/*.nupkg")),
new StartProcess(
"dotnet",
Config.FromDocument((doc, ctx) => $"nuget push --api-key {ctx.Settings.GetString("NUGET_KEY")} --source \"https://api.nuget.org/v3/index.json\" \"{doc.Source.FullPath}\" "))
.WithSequentialExecution()
.LogOutput()))
public class Zip : Pipeline
{
public Zip()
{
ExecutionPolicy = ExecutionPolicy.Manual;
Dependencies.Add(nameof(Test));
ProcessModules = new ModuleList
{
new ReadFiles("../../../src/*/*.csproj"),
new ExecuteModules(
new ExecuteConfig(Config.FromDocument((doc, ctx) =>
(object)new CopyFiles("../../../README.md", "../../../ReleaseNotes.md", "../../../LICENSE")
.To(x => Task.FromResult(GetBuildPath(doc, ctx).CombineFile(x.Path.FileName)))))),
new ZipDirectory(Config.FromDocument(GetBuildPath)),
new SetDestination(Config.FromDocument((doc, ctx) => (FilePath)$"zip/{doc.Source.FileNameWithoutExtension}-{ctx.GetString(BuildVersion)}.zip")),
new WriteFiles()
};
}
}

// Run the app
.RunAsync();
// TODO: Generate zip
// TODO: Generate GitHub release
// TODO: Run docs generator with deployment
public class Publish : Pipeline
{
public Publish()
{
ExecutionPolicy = ExecutionPolicy.Manual;
Dependencies.Add(nameof(Pack));
ProcessModules = new ModuleList
{
new ReadFiles(Config.FromContext(ctx => $"{ctx.FileSystem.GetOutputDirectory("packages")}/*.nupkg")),
new StartProcess("dotnet")
.WithArgument("nuget")
.WithArgument("push")
.WithArgument("--api-key", Config.FromSetting<string>("NUGET_KEY"))
.WithArgument("--source", "https://api.nuget.org/v3/index.json", true)
.WithArgument(Config.FromDocument(doc => doc.Source.FullPath), true)
.WithSequentialExecution()
.LogOutput()
};
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\NetlifySharp\NetlifySharp.csproj" />
<ProjectReference Include="..\..\src\NetlifySharp\NetlifySharp.csproj" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public static async Task Main(string[] args)
code = code.Replace($"public {clientSettings.ClassName}(", $"private {clientSettings.ClassName}(");

// Write to a file in the client project
System.IO.File.WriteAllText($"../NetlifySharp/{clientSettings.ClassName}.Generated.cs", code);
System.IO.File.WriteAllText($"../../src/NetlifySharp/{clientSettings.ClassName}.Generated.cs", code);
}
}
}

0 comments on commit 98cc21f

Please sign in to comment.