22using System . IO ;
33using System . Linq ;
44using System . Runtime . InteropServices ;
5+ using System . Threading . Tasks ;
56using static Bullseye . Targets ;
67using static SimpleExec . Command ;
78
@@ -10,112 +11,129 @@ static class Program
1011 private const string ArtifactsDir = "artifacts" ;
1112 private const string PublishDir = "publish" ;
1213
13- private const string Clean = nameof ( Clean ) ;
14- private const string Init = nameof ( Init ) ;
15- private const string GenerateDocumentation = nameof ( GenerateDocumentation ) ;
16- private const string Build = nameof ( Build ) ;
17- private const string RunTests = nameof ( RunTests ) ;
18- private const string Pack = nameof ( Pack ) ;
19- private const string Publish = nameof ( Publish ) ;
20- private const string Push = nameof ( Push ) ;
14+ private static readonly string MYGET_API_KEY = Environment . GetEnvironmentVariable ( nameof ( MYGET_API_KEY ) ) ;
2115
2216 public static void Main ( string [ ] args )
2317 {
24- var apiKey = Environment . GetEnvironmentVariable ( "MYGET_API_KEY" ) ;
25- var srcDirectory = new DirectoryInfo ( "./src" ) ;
18+ const string clean = nameof ( Clean ) ;
19+ const string init = nameof ( Init ) ;
20+ const string generateDocumentation = nameof ( GenerateDocumentation ) ;
21+ const string build = nameof ( Build ) ;
22+ const string runTests = nameof ( RunTests ) ;
23+ const string pack = nameof ( Pack ) ;
24+ const string publish = nameof ( Publish ) ;
25+ const string push = nameof ( Push ) ;
2626
27- Target ( Clean , ( ) =>
28- {
29- if ( Directory . Exists ( ArtifactsDir ) )
30- {
31- Directory . Delete ( ArtifactsDir , true ) ;
32- }
27+ var srcDirectory = new DirectoryInfo ( "./src" ) ;
3328
34- if ( Directory . Exists ( PublishDir ) )
35- {
36- Directory . Delete ( PublishDir , true ) ;
37- }
38- } ) ;
29+ Target (
30+ clean ,
31+ Clean ) ;
3932
4033 Target (
41- Init ,
42- ( ) =>
43- {
44- if ( RuntimeInformation . IsOSPlatform ( OSPlatform . Windows ) )
45- {
46- Run ( "cmd" , "/c yarn" , "docs" ) ;
47- }
48- else
49- {
50- Run ( "yarn" , string . Empty , "docs" ) ;
51- }
52- } ) ;
34+ init ,
35+ Init ) ;
5336
5437 Target (
55- GenerateDocumentation ,
56- DependsOn ( Init ) ,
38+ generateDocumentation ,
39+ DependsOn ( init ) ,
5740 ForEach ( SchemaDirectories ( srcDirectory ) ) ,
58- schemaDirectory =>
59- RunAsync (
60- "node" ,
61- $ "node_modules/@adobe/jsonschema2md/cli.js -n --input { schemaDirectory } --out { schemaDirectory } --schema-out=-",
62- "docs" ) ) ;
41+ GenerateDocumentation ) ;
6342
6443 Target (
65- Build ,
66- DependsOn ( GenerateDocumentation ) ,
67- ( ) => Run (
68- "dotnet" ,
69- "build src/SqlStreamStore.HAL.sln -c Release" ) ) ;
44+ build ,
45+ DependsOn ( generateDocumentation ) ,
46+ Build ) ;
7047
7148 Target (
72- RunTests ,
73- DependsOn ( Build ) ,
74- ( ) => Run (
75- "dotnet" ,
76- $ "test src/SqlStreamStore.HAL.Tests -c Release -r ../../{ ArtifactsDir } --verbosity normal --no-build -l trx;LogFileName=SqlStreamStore.HAL.Tests.xml") ) ;
49+ runTests ,
50+ DependsOn ( build ) ,
51+ RunTests ) ;
7752
7853 Target (
79- Publish ,
80- DependsOn ( Build ) ,
81- ( ) => Run (
82- "dotnet" ,
83- $ "publish --configuration=Release --output=../../{ PublishDir } --runtime=alpine.3.7-x64 /p:ShowLinkerSizeComparison=true src/SqlStreamStore.HAL.DevServer") ) ;
54+ publish ,
55+ DependsOn ( build ) ,
56+ Publish ) ;
8457
8558 Target (
86- Pack ,
87- DependsOn ( Publish ) ,
88- ( ) => Run (
89- "dotnet" ,
90- $ "pack src/SqlStreamStore.HAL -c Release -o ../../{ ArtifactsDir } --no-build") ) ;
59+ pack ,
60+ DependsOn ( publish ) ,
61+ Pack ) ;
9162
9263 Target (
93- Push ,
94- DependsOn ( Pack ) ,
95- ( ) =>
96- {
97- var packagesToPush = Directory . GetFiles ( ArtifactsDir , "*.nupkg" , SearchOption . TopDirectoryOnly ) ;
98- Console . WriteLine ( $ "Found packages to publish: { string . Join ( "; " , packagesToPush ) } ") ;
99-
100- if ( string . IsNullOrWhiteSpace ( apiKey ) )
101- {
102- Console . WriteLine ( "MyGet API key not available. Packages will not be pushed." ) ;
103- return ;
104- }
105-
106- foreach ( var packageToPush in packagesToPush )
107- {
108- Run (
109- "dotnet" ,
110- $ "nuget push { packageToPush } -s https://www.myget.org/F/sqlstreamstore/api/v3/index.json -k { apiKey } ") ;
111- }
112- } ) ;
113-
114- Target ( "default" , DependsOn ( Clean , RunTests , Push ) ) ;
64+ push ,
65+ DependsOn ( pack ) ,
66+ Push ) ;
67+
68+ Target ( "default" , DependsOn ( clean , runTests , push ) ) ;
11569
11670 RunTargets ( args . Concat ( new [ ] { "--parallel" } ) ) ;
11771 }
11872
73+ private static readonly Action Init = ( ) => Yarn ( "./docs" ) ;
74+
75+ private static readonly Action Clean = ( ) =>
76+ {
77+ if ( Directory . Exists ( ArtifactsDir ) )
78+ {
79+ Directory . Delete ( ArtifactsDir , true ) ;
80+ }
81+
82+ if ( Directory . Exists ( PublishDir ) )
83+ {
84+ Directory . Delete ( PublishDir , true ) ;
85+ }
86+ } ;
87+
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 (
95+ "dotnet" ,
96+ "build src/SqlStreamStore.HAL.sln --configuration Release" ) ;
97+
98+ private static readonly Action RunTests = ( ) => Run (
99+ "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+
119137 private static string [ ] SchemaDirectories ( DirectoryInfo srcDirectory )
120138 => srcDirectory . GetFiles ( "*.schema.json" , SearchOption . AllDirectories )
121139 . Select ( schemaFile => schemaFile . DirectoryName )
0 commit comments