22using Nuke . Common . IO ;
33using Nuke . Common . Tooling ;
44using Nuke . Common . Tools . MSBuild ;
5- using Nuke . Common . Utilities . Collections ;
65using System ;
76using System . IO ;
8- using System . Linq ;
9- using System . Text ;
10- using System . Text . Json ;
117using System . Text . RegularExpressions ;
128using System . Threading . Tasks ;
139using static Nuke . Common . Tools . DocFX . DocFXTasks ;
14- using static Nuke . Common . Tools . Git . GitTasks ;
1510using static Nuke . Common . Tools . MSBuild . MSBuildTasks ;
1611using static Nuke . Common . Tools . Unity . UnityTasks ;
1712using static UnityHelper ;
@@ -22,8 +17,6 @@ class Build : NukeBuild
2217
2318 public static int Main ( ) => Execute < Build > ( x => x . Compile ) ;
2419
25- [ PathExecutable ] readonly Tool Gh = default ! ;
26-
2720 [ Parameter ( "Configuration to build - Default is 'Debug' (local) or 'Release' (server)" ) ]
2821 readonly Configuration Configuration = IsLocalBuild ? Configuration . Debug : Configuration . Release ;
2922
@@ -33,9 +26,6 @@ class Build : NukeBuild
3326
3427 [ Parameter ( "Are we running in CI" ) ] bool IsCi = false ;
3528
36- string CurrentVersion { get ; set ; } = default ! ;
37- bool IsNewestVersion { get ; set ; }
38-
3929 static AbsolutePath UnityProjectPath => RootDirectory / "UnityResourceGenerator" ;
4030 static AbsolutePath UnitySolution => UnityProjectPath / "UnityResourceGenerator.sln" ;
4131
@@ -123,66 +113,4 @@ async Task GenerateSolution()
123113 Target ServeDocs => _ => _
124114 . DependsOn ( BuildDocs )
125115 . Executes ( ( ) => DocFX ( $ "{ DocFxJsonPath } --serve") ) ;
126-
127- Target CreateGithubRelease => _ => _
128- . OnlyWhenDynamic ( ( ) => IsNewestVersion )
129- . OnlyWhenDynamic ( ( ) => IsCi )
130- . Executes ( ( ) =>
131- {
132- var version = CurrentVersion ;
133-
134- var notes = File . ReadAllLines ( RootDirectory / "CHANGELOG.md" )
135- . Skip ( 1 )
136- . TakeUntil ( string . IsNullOrWhiteSpace )
137- . Aggregate ( new StringBuilder ( ) , ( sb , l ) => sb . AppendLine ( l ) )
138- . ToString ( ) ;
139-
140- Gh ( $ "release create { version } -t { version } -n \" { notes } \" ") ;
141- } ) ;
142-
143-
144- protected override void OnBuildInitialized ( )
145- {
146- bool GetIsNewestVersion ( )
147- {
148- var currentVersion = new Version ( CurrentVersion ) ;
149-
150- GitLogger = ( _ , s ) => Logger . Info ( s ) ;
151-
152- Git ( "fetch --tags" ) ;
153-
154- var maxPublishedVersion = Git ( "tag" )
155- . Select ( o => new Version ( o . Text ) )
156- . OrderBy ( v => v )
157- . LastOrDefault ( ) ;
158-
159- return currentVersion . CompareTo ( maxPublishedVersion ) > 0 ;
160- }
161-
162- string GetCurrentVersion ( )
163- {
164- var packagePath = UnityProjectPath / "Assets" / "AutSoft.UnityResourceGenerator" / "package.json" ;
165-
166- if ( ! File . Exists ( packagePath ) ) throw new InvalidOperationException ( $ "package.json does not exist at path: { packagePath } ") ;
167-
168- var jsonContent = File . ReadAllText ( packagePath ) ;
169- var package = JsonSerializer . Deserialize < PackageJson > ( jsonContent , new JsonSerializerOptions { PropertyNameCaseInsensitive = true } ) ;
170-
171- if ( package ? . Version is null ) throw new InvalidOperationException ( $ "Cloud not deserialize package.json:{ Environment . NewLine } { jsonContent } ") ;
172-
173- return package . Version ;
174- }
175-
176- CurrentVersion = GetCurrentVersion ( ) ;
177- IsNewestVersion = GetIsNewestVersion ( ) ;
178-
179- base . OnBuildInitialized ( ) ;
180- }
181-
182- sealed class PackageJson
183- {
184- public PackageJson ( string version ) => Version = version ;
185-
186- public string Version { get ; }
187- }
188116}
0 commit comments