1+ #tool "nuget:?package=NUnit.ConsoleRunner"
2+ #tool "nuget:?package=GitReleaseNotes"
3+
4+ var target = Argument ( "target" , "Default" ) ;
5+ var configuration = Argument ( "configuration" , "Release" ) ;
6+
7+ string version = null ;
8+ string nugetVersion = null ;
9+ string preReleaseTag = null ;
10+ string semVersion = null ;
11+ string milestone = null ;
12+ bool publishingError = false ;
13+ bool IsTagged = ( BuildSystem . AppVeyor . Environment . Repository . Tag . IsTag &&
14+ ! string . IsNullOrWhiteSpace ( BuildSystem . AppVeyor . Environment . Repository . Tag . Name ) ) ;
15+ bool IsMainGitVersionRepo = StringComparer . OrdinalIgnoreCase . Equals ( "gittools/gitversion" , BuildSystem . AppVeyor . Environment . Repository . Name ) ;
16+ bool IsPullRequest = BuildSystem . AppVeyor . Environment . PullRequest . IsPullRequest ;
17+
18+ void Build ( string configuration , string nugetVersion , string semVersion , string version , string preReleaseTag )
19+ {
20+ if ( IsRunningOnUnix ( ) )
21+ {
22+ XBuild ( "./src/GitVersion.sln" , new XBuildSettings ( )
23+ . SetConfiguration ( configuration )
24+ . WithProperty ( "POSIX" , "True" )
25+ . SetVerbosity ( Verbosity . Verbose ) ) ;
26+ }
27+ else
28+ {
29+ var msBuildSettings = new MSBuildSettings ( )
30+ . SetConfiguration ( configuration )
31+ . SetPlatformTarget ( PlatformTarget . MSIL )
32+ . WithProperty ( "Windows" , "True" )
33+ . UseToolVersion ( MSBuildToolVersion . VS2015 )
34+ . SetVerbosity ( Verbosity . Minimal )
35+ . SetNodeReuse ( false ) ;
36+
37+ if ( BuildSystem . AppVeyor . IsRunningOnAppVeyor )
38+ {
39+ msBuildSettings = msBuildSettings
40+ . WithProperty ( "GitVersion_NuGetVersion" , nugetVersion )
41+ . WithProperty ( "GitVersion_SemVer" , semVersion )
42+ . WithProperty ( "GitVersion_MajorMinorPatch" , version )
43+ . WithProperty ( "GitVersion_PreReleaseTag" , preReleaseTag ) ;
44+ }
45+ MSBuild ( "./src/GitVersion.sln" , msBuildSettings ) ;
46+ }
47+ }
48+
49+ Task ( "DogfoodBuild" )
50+ . IsDependentOn ( "NuGet-Package-Restore" )
51+ . Does ( ( ) =>
52+ {
53+ Build ( configuration , nugetVersion , semVersion , version , preReleaseTag ) ;
54+ } ) ;
55+
56+ Task ( "Version" )
57+ . IsDependentOn ( "DogfoodBuild" )
58+ . Does ( ( ) =>
59+ {
60+ GitVersion ( new GitVersionSettings
61+ {
62+ UpdateAssemblyInfo = true ,
63+ LogFilePath = "console" ,
64+ OutputType = GitVersionOutput . BuildServer ,
65+ ToolPath = @"src\GitVersionExe\bin\Release\GitVersion.exe"
66+ } ) ;
67+ GitVersion assertedVersions = GitVersion ( new GitVersionSettings
68+ {
69+ OutputType = GitVersionOutput . Json ,
70+ ToolPath = @"src\GitVersionExe\bin\Release\GitVersion.exe"
71+ } ) ;
72+
73+ version = assertedVersions . MajorMinorPatch ;
74+ nugetVersion = assertedVersions . NuGetVersion ;
75+ preReleaseTag = assertedVersions . PreReleaseTag ;
76+ semVersion = assertedVersions . LegacySemVerPadded ;
77+ } ) ;
78+
79+ Task ( "NuGet-Package-Restore" )
80+ . Does ( ( ) =>
81+ {
82+ NuGetRestore ( "./src/GitVersion.sln" ) ;
83+ } ) ;
84+
85+ Task ( "Build" )
86+ . IsDependentOn ( "Version" )
87+ . IsDependentOn ( "NuGet-Package-Restore" )
88+ . Does ( ( ) =>
89+ {
90+ Build ( configuration , nugetVersion , semVersion , version , preReleaseTag ) ;
91+ } ) ;
92+
93+ Task ( "Run-NUnit-Tests" )
94+ . IsDependentOn ( "Build" )
95+ . Does ( ( ) =>
96+ {
97+ var settings = new NUnit3Settings ( ) ;
98+ if ( IsRunningOnUnix ( ) )
99+ {
100+ settings . Where = "cat != NoMono" ;
101+ }
102+ NUnit3 ( new [ ] {
103+ "src/GitVersionCore.Tests/bin/" + configuration + "/GitVersionCore.Tests.dll" ,
104+ "src/GitVersionExe.Tests/bin/" + configuration + "/GitVersionExe.Tests.dll" ,
105+ "src/GitVersionTask.Tests/bin/" + configuration + "/GitVersionTask.Tests.dll" } ,
106+ settings ) ;
107+ if ( AppVeyor . IsRunningOnAppVeyor )
108+ {
109+ Information ( "Uploading test results" ) ;
110+ AppVeyor . UploadTestResults ( "TestResult.xml" , AppVeyorTestResultsType . NUnit3 ) ;
111+ }
112+ } ) ;
113+
114+ Task ( "Zip-Files" )
115+ . IsDependentOn ( "Run-NUnit-Tests" )
116+ . Does ( ( ) =>
117+ {
118+ Zip ( "./build/NuGetCommandLineBuild/Tools/" , "build/GitVersion_" + nugetVersion + ".zip" ) ;
119+ } ) ;
120+
121+ Task ( "Create-Release-Notes" )
122+ . IsDependentOn ( "Build" )
123+ . Does ( ( ) =>
124+ {
125+ var releaseNotesExitCode = StartProcess (
126+ @"tools\GitReleaseNotes\tools\gitreleasenotes.exe" ,
127+ new ProcessSettings { Arguments = ". /o build/releasenotes.md" } ) ;
128+ if ( string . IsNullOrEmpty ( System . IO . File . ReadAllText ( "./build/releasenotes.md" ) ) )
129+ System . IO . File . WriteAllText ( "./build/releasenotes.md" , "No issues closed since last release" ) ;
130+
131+ if ( releaseNotesExitCode != 0 ) throw new Exception ( "Failed to generate release notes" ) ;
132+ } ) ;
133+
134+ Task ( "Package" )
135+ . IsDependentOn ( "Create-Release-Notes" )
136+ . IsDependentOn ( "Zip-Files" ) ;
137+
138+ Task ( "Upload-AppVeyor-Artifacts" )
139+ . IsDependentOn ( "Package" )
140+ . WithCriteria ( ( ) => AppVeyor . IsRunningOnAppVeyor )
141+ . Does ( ( ) =>
142+ {
143+ var gem = string . IsNullOrEmpty ( preReleaseTag ) ?
144+ "gitversion-" + version + ".gem" :
145+ "gitversion-" + version + "." + preReleaseTag + ".gem" ;
146+
147+ System . IO . File . WriteAllLines ( "build/artifacts" , new [ ] {
148+ "NuGetExeBuild:GitVersion.Portable." + nugetVersion + ".nupkg" ,
149+ "NuGetCommandLineBuild:GitVersion.CommandLine." + nugetVersion + ".nupkg" ,
150+ "NuGetRefBuild:GitVersion." + nugetVersion + ".nupkg" ,
151+ "NuGetTaskBuild:GitVersionTask." + nugetVersion + ".nupkg" ,
152+ "GitVersionTfsTaskBuild:gittools.gitversion." + semVersion + ".vsix" ,
153+ "GemBuild:" + gem ,
154+ "zip:GitVersion_" + nugetVersion + ".zip" ,
155+ "releaseNotes:releasenotes.md"
156+ } ) ;
157+
158+ AppVeyor . UploadArtifact ( "build/NuGetExeBuild/GitVersion.Portable." + nugetVersion + ".nupkg" ) ;
159+ AppVeyor . UploadArtifact ( "build/NuGetCommandLineBuild/GitVersion.CommandLine." + nugetVersion + ".nupkg" ) ;
160+ AppVeyor . UploadArtifact ( "build/NuGetRefBuild/GitVersion." + nugetVersion + ".nupkg" ) ;
161+ AppVeyor . UploadArtifact ( "build/NuGetTaskBuild/GitVersionTask." + nugetVersion + ".nupkg" ) ;
162+ AppVeyor . UploadArtifact ( "build/GitVersionTfsTaskBuild/gittools.gitversion-" + semVersion + ".vsix" ) ;
163+ AppVeyor . UploadArtifact ( "build/GitVersion_" + nugetVersion + ".zip" ) ;
164+ AppVeyor . UploadArtifact ( "build/GemBuild/" + gem ) ;
165+ } ) ;
166+
167+
168+ Task ( "Travis" )
169+ . IsDependentOn ( "Run-NUnit-Tests" ) ;
170+
171+ Task ( "Default" )
172+ . IsDependentOn ( "Upload-AppVeyor-Artifacts" ) ;
173+
174+ RunTarget ( target ) ;
0 commit comments