11using System ;
22using System . IO ;
33using System . Linq ;
4- using System . Runtime . InteropServices ;
5- using System . Threading . Tasks ;
4+ using Fclp ;
65using static Bullseye . Targets ;
76using static SimpleExec . Command ;
87
@@ -11,67 +10,48 @@ static class Program
1110 private const string ArtifactsDir = "artifacts" ;
1211 private const string PublishDir = "publish" ;
1312
14- private static readonly string MYGET_API_KEY = Environment . GetEnvironmentVariable ( nameof ( MYGET_API_KEY ) ) ;
15-
1613 public static void Main ( string [ ] args )
1714 {
1815 const string clean = nameof ( Clean ) ;
19- const string init = nameof ( Init ) ;
20- const string generateDocumentation = nameof ( GenerateDocumentation ) ;
2116 const string build = nameof ( Build ) ;
22- const string runTests = nameof ( RunTests ) ;
23- const string pack = nameof ( Pack ) ;
2417 const string publish = nameof ( Publish ) ;
25- const string push = nameof ( Push ) ;
2618
27- var srcDirectory = new DirectoryInfo ( "./src" ) ;
19+ var runtime = "alpine-x64" ;
20+ var libraryVersion = "1.2.0-beta.*" ;
2821
29- Target (
30- clean ,
31- Clean ) ;
22+ var parser = new FluentCommandLineParser ( ) ;
23+ parser . Setup < string > ( "runtime" )
24+ . Callback ( r => runtime = r ) ;
25+ parser . Setup < string > ( "library-version" )
26+ . Callback ( v => libraryVersion = v ) ;
3227
33- Target (
34- init ,
35- Init ) ;
28+ var result = parser . Parse ( args ) ;
3629
37- Target (
38- generateDocumentation ,
39- DependsOn ( init ) ,
40- ForEach ( SchemaDirectories ( srcDirectory ) ) ,
41- GenerateDocumentation ) ;
30+ args = result
31+ . AdditionalOptions
32+ . SelectMany ( option => new [ ] { option . Key . Length == 1 ? $ "- { option . Key } " : $ "-- { option . Key } " , option . Value } )
33+ . Where ( arg => arg != null )
34+ . ToArray ( ) ;
4235
4336 Target (
44- build ,
45- DependsOn ( generateDocumentation ) ,
46- Build ) ;
37+ clean ,
38+ Clean ) ;
4739
4840 Target (
49- runTests ,
50- DependsOn ( build ) ,
51- RunTests ) ;
41+ build ,
42+ DependsOn ( clean ) ,
43+ Build ( libraryVersion ) ) ;
5244
5345 Target (
5446 publish ,
5547 DependsOn ( build ) ,
56- Publish ) ;
48+ Publish ( runtime , libraryVersion ) ) ;
5749
58- Target (
59- pack ,
60- DependsOn ( publish ) ,
61- Pack ) ;
50+ Target ( "default" , DependsOn ( publish ) ) ;
6251
63- Target (
64- push ,
65- DependsOn ( pack ) ,
66- Push ) ;
67-
68- Target ( "default" , DependsOn ( clean , runTests , push ) ) ;
69-
70- RunTargetsAndExit ( args . Concat ( new [ ] { "--parallel" } ) ) ;
52+ RunTargetsAndExit ( args ) ;
7153 }
7254
73- private static readonly Action Init = ( ) => Yarn ( "./docs" ) ;
74-
7555 private static readonly Action Clean = ( ) =>
7656 {
7757 if ( Directory . Exists ( ArtifactsDir ) )
@@ -85,59 +65,11 @@ public static void Main(string[] args)
8565 }
8666 } ;
8767
88- private static readonly Func < string , Task > GenerateDocumentation = schemaDirectory =>
89- RunAsync (
90- "node" ,
91- $ "node_modules/@adobe/jsonschema2md/cli.js -n --input { schemaDirectory } --out { schemaDirectory } --schema-out=-",
92- "docs" ) ;
93-
94- private static readonly Action Build = ( ) => Run (
68+ private static Action Build ( string libraryVersion ) => ( ) => Run (
9569 "dotnet" ,
96- "build src/ SqlStreamStore.HAL .sln --configuration Release" ) ;
70+ $ "build SqlStreamStore.Server .sln --configuration= Release /p:LibraryVersion= { libraryVersion } ") ;
9771
98- private static readonly Action RunTests = ( ) => Run (
72+ private static Action Publish ( string runtime , string libraryVersion ) => ( ) => Run (
9973 "dotnet" ,
100- $ "test src/SqlStreamStore.HAL.Tests --configuration Release --results-directory ../../{ ArtifactsDir } --verbosity normal --no-build -l trx;LogFileName=SqlStreamStore.HAL.Tests.xml") ;
101-
102- private static readonly Action Publish = ( ) => Run (
103- "dotnet" ,
104- $ "publish --configuration=Release --output=../../{ PublishDir } --runtime=alpine.3.7-x64 /p:ShowLinkerSizeComparison=true src/SqlStreamStore.HAL.ApplicationServer") ;
105-
106- private static readonly Action Pack = ( ) => Run (
107- "dotnet" ,
108- $ "pack src/SqlStreamStore.HAL --configuration Release --output ../../{ ArtifactsDir } --no-build") ;
109-
110- private static readonly Action Push = ( ) =>
111- {
112- var packagesToPush = Directory . GetFiles ( ArtifactsDir , "*.nupkg" , SearchOption . TopDirectoryOnly ) ;
113- Console . WriteLine ( $ "Found packages to publish: { string . Join ( "; " , packagesToPush ) } ") ;
114-
115- if ( string . IsNullOrWhiteSpace ( MYGET_API_KEY ) )
116- {
117- Console . WriteLine ( "MyGet API key not available. Packages will not be pushed." ) ;
118- return ;
119- }
120-
121- foreach ( var packageToPush in packagesToPush )
122- {
123- Run (
124- "dotnet" ,
125- $ "nuget push { packageToPush } -s https://www.myget.org/F/sqlstreamstore/api/v3/index.json -k { MYGET_API_KEY } ") ;
126- }
127- } ;
128-
129- private static void Yarn ( string workingDirectory , string args = default )
130- {
131- if ( RuntimeInformation . IsOSPlatform ( OSPlatform . Windows ) )
132- Run ( "cmd" , "/c yarn" , workingDirectory ) ;
133- else
134- Run ( "yarn" , args , workingDirectory ) ;
135- }
136-
137- private static string [ ] SchemaDirectories ( DirectoryInfo srcDirectory )
138- => srcDirectory . GetFiles ( "*.schema.json" , SearchOption . AllDirectories )
139- . Select ( schemaFile => schemaFile . DirectoryName )
140- . Distinct ( )
141- . Select ( schemaDirectory => schemaDirectory . Replace ( Path . DirectorySeparatorChar , '/' ) )
142- . ToArray ( ) ;
74+ $ "publish --configuration=Release --output=../../{ PublishDir } --runtime={ runtime } /p:ShowLinkerSizeComparison=true /p:LibraryVersion={ libraryVersion } src/SqlStreamStore.Server") ;
14375}
0 commit comments