@@ -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}
0 commit comments