1+ // Build
2+ // Copyright (c) 2023 MTS spol. s r.o, and Contributors. All Rights Reserved.
3+ // Contributors: https://github.com/inxton/AXOpen/graphs/contributors
4+ // See the LICENSE file in the repository root for more information.
5+ // https://github.com/inxton/AXOpen/blob/master/LICENSE
6+ // Third party licenses: https://github.com/inxton/AXOpen/blob/master/notices.md
7+
8+ using System ;
9+ using System . IO ;
10+ using System . Text ;
11+ using Cake . Core . IO ;
12+ using Path = System . IO . Path ;
13+
14+ public static class ApaxCmd
15+ {
16+ public static void UpdateApaxVersion ( this BuildContext context , string file , string version )
17+ {
18+ var sb = new StringBuilder ( ) ;
19+ foreach ( var line in System . IO . File . ReadLines ( file ) )
20+ {
21+ var newLine = line ;
22+
23+ if ( line . Trim ( ) . StartsWith ( "version" ) )
24+ {
25+ var semicPosition = line . IndexOf ( ":" ) ;
26+ var lenght = line . Length - semicPosition ;
27+
28+ newLine = $ "{ line . Substring ( 0 , semicPosition ) } : '{ version } '";
29+ }
30+
31+ sb . AppendLine ( newLine ) ;
32+ }
33+
34+ System . IO . File . WriteAllText ( file , sb . ToString ( ) ) ;
35+ }
36+
37+ public static void ApaxPack ( this BuildContext context , string apaxFolder )
38+ {
39+ {
40+ context . ProcessRunner . Start ( Helpers . GetApaxCommand ( ) , new ProcessSettings ( )
41+ {
42+ Arguments = $ "pack --key={ context . ApaxSignKey } ",
43+ WorkingDirectory = apaxFolder ,
44+ RedirectStandardOutput = false ,
45+ RedirectStandardError = false ,
46+ Silent = false
47+ } ) . WaitForExit ( ) ;
48+ }
49+ }
50+
51+ public static void ApaxCopyArtifacts ( this BuildContext context , string folder , string name )
52+ {
53+ var packageFile = $ "{ context . ApaxRegistry } -{ name } -{ GitVersionInformation . SemVer } .apax.tgz";
54+ var sourceFile = Path . Combine ( folder , packageFile ) ;
55+ File . Copy ( sourceFile , Path . Combine ( context . ArtifactsApax , packageFile ) ) ;
56+ }
57+
58+ public static void ApaxPublishAllArtefacts ( this BuildContext context )
59+ {
60+ context . ProcessRunner . Start ( Helpers . GetApaxCommand ( ) , new ProcessSettings ( )
61+ {
62+ Arguments =
63+ $ "login --registry https://npm.pkg.github.com --username { context . GitHubUser } --password { context . GitHubToken } ",
64+ WorkingDirectory = context . ArtifactsApax ,
65+ RedirectStandardOutput = false ,
66+ RedirectStandardError = false ,
67+ Silent = false
68+ } ) . WaitForExit ( ) ;
69+
70+ foreach ( var apaxPackageFile in Directory . EnumerateFiles ( context . ArtifactsApax ) )
71+ {
72+ var process = context . ProcessRunner . Start ( Helpers . GetApaxCommand ( ) , new ProcessSettings ( )
73+ {
74+ Arguments = $ "publish -p { apaxPackageFile } -r https://npm.pkg.github.com",
75+ WorkingDirectory = context . ArtifactsApax ,
76+ RedirectStandardOutput = false ,
77+ RedirectStandardError = false ,
78+ Silent = false
79+ } ) ;
80+
81+ process . WaitForExit ( ) ;
82+
83+ if ( process . GetExitCode ( ) != 0 )
84+ {
85+ throw new PublishFailedException ( ) ;
86+ }
87+ }
88+ }
89+ }
90+
91+ public class PublishFailedException : Exception
92+ {
93+ }
0 commit comments