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,131 @@ 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 = ( ) =>
74+ {
75+ if ( RuntimeInformation . IsOSPlatform ( OSPlatform . Windows ) )
76+ {
77+ Run ( "cmd" , "/c yarn" , "docs" ) ;
78+ }
79+ else
80+ {
81+ Run ( "yarn" , string . Empty , "docs" ) ;
82+ }
83+ } ;
84+
85+ private static readonly Action Clean = ( ) =>
86+ {
87+ if ( Directory . Exists ( ArtifactsDir ) )
88+ {
89+ Directory . Delete ( ArtifactsDir , true ) ;
90+ }
91+
92+ if ( Directory . Exists ( PublishDir ) )
93+ {
94+ Directory . Delete ( PublishDir , true ) ;
95+ }
96+ } ;
97+
98+ private static readonly Func < string , Task > GenerateDocumentation = schemaDirectory =>
99+ RunAsync (
100+ "node" ,
101+ $ "node_modules/@adobe/jsonschema2md/cli.js -n --input { schemaDirectory } --out { schemaDirectory } --schema-out=-",
102+ "docs" ) ;
103+
104+ private static readonly Action Build = ( ) => Run (
105+ "dotnet" ,
106+ "build src/SqlStreamStore.HAL.sln --configuration Release" ) ;
107+
108+ private static readonly Action RunTests = ( ) => Run (
109+ "dotnet" ,
110+ $ "test src/SqlStreamStore.HAL.Tests --configuration Release --results-directory ../../{ ArtifactsDir } --verbosity normal --no-build -l trx;LogFileName=SqlStreamStore.HAL.Tests.xml") ;
111+
112+ private static readonly Action Publish = ( ) => Run (
113+ "dotnet" ,
114+ $ "publish --configuration=Release --output=../../{ PublishDir } --runtime=alpine.3.7-x64 /p:ShowLinkerSizeComparison=true src/SqlStreamStore.HAL.DevServer") ;
115+
116+ private static readonly Action Pack = ( ) => Run (
117+ "dotnet" ,
118+ $ "pack src/SqlStreamStore.HAL --configuration Release --output ../../{ ArtifactsDir } --no-build") ;
119+
120+ private static readonly Action Push = ( ) =>
121+ {
122+ var packagesToPush = Directory . GetFiles ( ArtifactsDir , "*.nupkg" , SearchOption . TopDirectoryOnly ) ;
123+ Console . WriteLine ( $ "Found packages to publish: { string . Join ( "; " , packagesToPush ) } ") ;
124+
125+ if ( string . IsNullOrWhiteSpace ( MYGET_API_KEY ) )
126+ {
127+ Console . WriteLine ( "MyGet API key not available. Packages will not be pushed." ) ;
128+ return ;
129+ }
130+
131+ foreach ( var packageToPush in packagesToPush )
132+ {
133+ Run (
134+ "dotnet" ,
135+ $ "nuget push { packageToPush } -s https://www.myget.org/F/sqlstreamstore/api/v3/index.json -k { MYGET_API_KEY } ") ;
136+ }
137+ } ;
138+
119139 private static string [ ] SchemaDirectories ( DirectoryInfo srcDirectory )
120140 => srcDirectory . GetFiles ( "*.schema.json" , SearchOption . AllDirectories )
121141 . Select ( schemaFile => schemaFile . DirectoryName )
0 commit comments