1+
2+ #tool "nuget:https://api.nuget.org/v3/index.json?package=GitVersion.CommandLine&version=3.6.2"
3+ #tool nuget : ? package= NUnit . ConsoleRunner & version = 3.4 .0
4+
5+ ///////////////////////////////////////////////////////////////////////////////
6+ // ARGUMENTS
7+ ///////////////////////////////////////////////////////////////////////////////
8+
9+ var target = Argument( "target", " Default") ;
10+ var configuration = Argument ( "configuration" , "Release" ) ;
11+
12+ //////////////////////////////////////////////////////////////////////
13+ // PARAMETERS
14+ //////////////////////////////////////////////////////////////////////
15+
16+ DotNetCoreMSBuildSettings msBuildSettings = null ;
17+ string version = null ,
18+ semVersion = null ,
19+ milestone = null ;
20+
21+ ///////////////////////////////////////////////////////////////////////////////
22+ // SETUP / TEARDOWN
23+ ///////////////////////////////////////////////////////////////////////////////
24+
25+ Setup ( ctx =>
26+ {
27+ Information ( "Calculating Semantic Version" ) ;
28+ if ( ! BuildSystem . IsLocalBuild )
29+ {
30+ GitVersion ( new GitVersionSettings {
31+ OutputType = GitVersionOutput . BuildServer
32+ } ) ;
33+ }
34+
35+ CopyFile ( "./src/LitJson/AssemblyInfo.cs.in" , "./src/LitJson/AssemblyInfo.cs" ) ;
36+
37+ GitVersion assertedVersions = GitVersion ( new GitVersionSettings
38+ {
39+ UpdateAssemblyInfoFilePath = "./src/LitJson/AssemblyInfo.cs" ,
40+ UpdateAssemblyInfo = true ,
41+ OutputType = GitVersionOutput . Json ,
42+ } ) ;
43+
44+ version = assertedVersions . MajorMinorPatch ;
45+ semVersion = assertedVersions . LegacySemVerPadded ;
46+ milestone = string . Concat ( "v" , version ) ;
47+
48+ Information ( "Calculated Semantic Version: {0}" , semVersion ) ;
49+
50+ msBuildSettings = new DotNetCoreMSBuildSettings ( )
51+ . WithProperty ( "Version" , semVersion )
52+ . WithProperty ( "AssemblyVersion" , version )
53+ . WithProperty ( "FileVersion" , version ) ;
54+
55+ if ( ! IsRunningOnWindows ( ) )
56+ {
57+ var frameworkPathOverride = new FilePath ( typeof ( object ) . Assembly . Location ) . GetDirectory ( ) . FullPath + "/" ;
58+
59+ // Use FrameworkPathOverride when not running on Windows.
60+ Information ( "Build will use FrameworkPathOverride={0} since not building on Windows." , frameworkPathOverride ) ;
61+ msBuildSettings . WithProperty ( "FrameworkPathOverride" , frameworkPathOverride ) ;
62+ }
63+
64+ // Executed BEFORE the first task.
65+ Information ( "Running tasks..." ) ;
66+ } ) ;
67+
68+ Teardown ( ctx =>
69+ {
70+ // Executed AFTER the last task.
71+ Information ( "Finished running tasks." ) ;
72+ } ) ;
73+
74+ ///////////////////////////////////////////////////////////////////////////////
75+ // TASKS
76+ ///////////////////////////////////////////////////////////////////////////////
77+
78+ Task ( "Clean" )
79+ . Does ( ( ) => {
80+ CleanDirectories (
81+ new [ ] {
82+ "./src/bin" ,
83+ "./test/bin" ,
84+ "./src/obj" ,
85+ "./test/obj" ,
86+ "./artifacts/nuget"
87+ }
88+ ) ;
89+ } ) ;
90+
91+ Task ( "Restore" )
92+ . IsDependentOn ( "Clean" )
93+ . Does ( ( ) => {
94+ DotNetCoreRestore ( "./LitJSON.sln" ,
95+ new DotNetCoreRestoreSettings { MSBuildSettings = msBuildSettings }
96+ ) ;
97+ } ) ;
98+
99+ Task ( "Build" )
100+ . IsDependentOn ( "Restore" )
101+ . Does ( ( ) => {
102+ DotNetCoreBuild ( "./LitJSON.sln" ,
103+ new DotNetCoreBuildSettings {
104+ Configuration = configuration ,
105+ MSBuildSettings = msBuildSettings
106+ }
107+ ) ;
108+ } ) ;
109+
110+ Task ( "Test" )
111+ . IsDependentOn ( "Build" )
112+ . Does ( ( ) => {
113+ DotNetCoreTest ( "./test/LitJSON.Tests.csproj" ,
114+ new DotNetCoreTestSettings {
115+ Configuration = configuration ,
116+ Framework = "netcoreapp2.0" ,
117+ NoBuild = true
118+ }
119+ ) ;
120+
121+ NUnit3 ( "./test/**/bin/" + configuration + "/net45/*.Tests.dll" , new NUnit3Settings {
122+ NoResults = true
123+ } ) ;
124+ } ) ;
125+
126+ Task ( "Package" )
127+ . IsDependentOn ( "Test" )
128+ . Does ( ( ) => {
129+ DotNetCorePack ( "./src/LitJSON/LitJSON.csproj" ,
130+ new DotNetCorePackSettings {
131+ Configuration = configuration ,
132+ NoBuild = true ,
133+ IncludeSymbols = true ,
134+ OutputDirectory = "./artifacts/nuget" ,
135+ MSBuildSettings = msBuildSettings
136+ }
137+ ) ;
138+ } ) ;
139+
140+ Task ( "Upload-AppVeyor-Artifacts" )
141+ . IsDependentOn ( "Package" )
142+ . WithCriteria ( AppVeyor . IsRunningOnAppVeyor )
143+ . Does ( ( ) => {
144+
145+ foreach ( var artifact in GetFiles ( "./artifacts/**/*.*" ) )
146+ {
147+ AppVeyor . UploadArtifact ( artifact ) ;
148+ }
149+ } ) ;
150+
151+ Task ( "Publish-MyGet" )
152+ . IsDependentOn ( "Package" )
153+ . WithCriteria ( ( AppVeyor . IsRunningOnAppVeyor && ! AppVeyor . Environment . PullRequest . IsPullRequest )
154+ || StringComparer . OrdinalIgnoreCase . Equals ( target , "Publish-MyGet" ) )
155+ . Does ( ( ) => {
156+
157+ // Resolve the API key.
158+ var apiKey = EnvironmentVariable ( "MYGET_API_KEY" ) ;
159+ if ( string . IsNullOrEmpty ( apiKey ) ) {
160+ throw new InvalidOperationException ( "Could not resolve MyGet API key." ) ;
161+ }
162+
163+ // Resolve the API url.
164+ var apiUrl = EnvironmentVariable ( "MYGET_API_URL" ) ;
165+ if ( string . IsNullOrEmpty ( apiUrl ) ) {
166+ throw new InvalidOperationException ( "Could not resolve MyGet API url." ) ;
167+ }
168+
169+ foreach ( var package in ( GetFiles ( "./artifacts/nuget/*.nupkg" ) - GetFiles ( "./artifacts/nuget/*.symbols.nupkg" ) ) )
170+ {
171+ DotNetCoreNuGetPush ( package . FullPath ,
172+ new DotNetCoreNuGetPushSettings {
173+ ApiKey = apiKey ,
174+ Source = apiUrl
175+ }
176+ ) ;
177+ }
178+ } ) ;
179+
180+ Task ( "Publish-NuGet" )
181+ . IsDependentOn ( "Package" )
182+ . WithCriteria ( ( AppVeyor . IsRunningOnAppVeyor && AppVeyor . Environment . Repository . Tag . IsTag && ! AppVeyor . Environment . PullRequest . IsPullRequest )
183+ || StringComparer . OrdinalIgnoreCase . Equals ( target , "Publish-NuGet" ) )
184+ . Does ( ( ) => {
185+
186+ // Resolve the API key.
187+ var apiKey = EnvironmentVariable ( "NUGET_API_KEY" ) ;
188+ if ( string . IsNullOrEmpty ( apiKey ) ) {
189+ throw new InvalidOperationException ( "Could not resolve MyGet API key." ) ;
190+ }
191+
192+ // Resolve the API url.
193+ var apiUrl = EnvironmentVariable ( "NUGET_API_URL" ) ;
194+ if ( string . IsNullOrEmpty ( apiUrl ) ) {
195+ throw new InvalidOperationException ( "Could not resolve MyGet API url." ) ;
196+ }
197+
198+ foreach ( var package in ( GetFiles ( "./artifacts/nuget/*.nupkg" ) - GetFiles ( "./artifacts/nuget/*.symbols.nupkg" ) ) )
199+ {
200+ DotNetCoreNuGetPush ( package . FullPath ,
201+ new DotNetCoreNuGetPushSettings {
202+ ApiKey = apiKey ,
203+ Source = apiUrl
204+ }
205+ ) ;
206+ }
207+ } ) ;
208+
209+ Task ( "AppVeyor" )
210+ . IsDependentOn ( "Upload-AppVeyor-Artifacts" )
211+ . IsDependentOn ( "Publish-MyGet" )
212+ . IsDependentOn ( "Publish-NuGet" ) ;
213+
214+ Task ( "Default" )
215+ . IsDependentOn ( "Package" ) ;
216+
217+ RunTarget ( target ) ;
0 commit comments