1
- #addin "MagicChunks"
1
+ #tool "nuget:?package=xunit.runner.console&version=2.3.1"
2
+ #tool "nuget:?package=GitVersion.CommandLine&version=3.6.5"
3
+ #tool "nuget:?package=gitreleasemanager&version=0.7.1"
4
+ #tool "nuget:?package=gitlink&version=2.4.0"
5
+ #addin "nuget:?package=Cake.Incubator&version=3.1.0"
2
6
3
- var target = Argument ( "target" , "Default" ) ;
4
- var configuration = Argument < string > ( "configuration" , "Release" ) ;
7
+ ///////////////////////////////////////////////////////////////////////////////
8
+ // ARGUMENTS
9
+ ///////////////////////////////////////////////////////////////////////////////
10
+ var envBuildNumber = EnvironmentVariable < int > ( "APPVEYOR_BUILD_NUMBER" , 0 ) ;
11
+ var gitHubUserName = EnvironmentVariable ( "GITHUB_USERNAME" ) ;
12
+ var gitHubPassword = EnvironmentVariable ( "GITHUB_PASSWORD" ) ;
13
+ var nugetSourceUrl = EnvironmentVariable ( "NUGET_SOURCE" ) ;
14
+ var nugetApiKey = EnvironmentVariable ( "NUGET_API_KEY" ) ;
15
+
16
+ var target = Argument ( "target" , "Default" ) ;
17
+ var configuration = Argument ( "configuration" , "Release" ) ;
18
+ var buildNumber = Argument < int > ( "buildNumber" , envBuildNumber ) ;
5
19
6
20
///////////////////////////////////////////////////////////////////////////////
7
- // GLOBAL VARIABLES
21
+ // VARIABLES
8
22
///////////////////////////////////////////////////////////////////////////////
9
- var isLocalBuild = ! AppVeyor . IsRunningOnAppVeyor ;
10
- var projects = new [ ]
11
- {
12
- "./src/IdentityServer4.Contrib.ServiceStack/IdentityServer4.Contrib.ServiceStack.csproj" ,
13
- "./src/ServiceStack.Authentication.IdentityServer/ServiceStack.Authentication.IdentityServer.csproj"
14
- } ;
15
- var sourcePath = Directory ( "./src" ) ;
16
- var buildArtifacts = Directory ( "./Artifacts" ) ;
17
23
18
- var nugetSources = new [ ] { "https://api.nuget.org/v3/index.json" } ;
24
+ // folders
25
+ var artifactsDir = Directory ( "./artifacts" ) ;
26
+ var nugetPackageDir = artifactsDir + Directory ( "nuget-packages" ) ;
27
+ var srcDir = Directory ( "./src" ) ;
28
+ var rootPath = MakeAbsolute ( Directory ( "./" ) ) ;
29
+ var releaseNotesPath = rootPath . CombineWithFilePath ( "CHANGELOG.md" ) ;
19
30
20
- Task ( "Build" )
21
- . IsDependentOn ( "Clean" )
22
- . IsDependentOn ( "Version" )
23
- . IsDependentOn ( "Restore" )
24
- . Does ( ( ) =>
31
+ // project specific
32
+ var solutionFile = srcDir + File ( "servicestack.auth.identityserver.sln" ) ;
33
+ var gitHubRepositoryOwner = "wwwlicious" ;
34
+ var gitHubRepositoryName = "servicestack-authentication-identityserver" ;
35
+
36
+ var isLocalBuild = BuildSystem . IsLocalBuild ;
37
+ var isPullRequest = BuildSystem . AppVeyor . Environment . PullRequest . IsPullRequest ;
38
+ var isMasterBranch = BuildSystem . AppVeyor . Environment . Repository . Branch . EqualsIgnoreCase ( "master" ) ;
39
+ var isReleaseBranch = BuildSystem . AppVeyor . Environment . Repository . Branch . StartsWithIgnoreCase ( "release" ) ;
40
+ var isHotFixBranch = BuildSystem . AppVeyor . Environment . Repository . Branch . StartsWithIgnoreCase ( "hotfix" ) ;
41
+ var isTagged = BuildSystem . AppVeyor . Environment . Repository . Tag . IsTag && ! BuildSystem . AppVeyor . Environment . Repository . Tag . Name . IsNullOrEmpty ( ) ;
42
+ var publishingError = false ;
43
+
44
+ var shouldPublishNuGet = ( ! isLocalBuild && ! isPullRequest && ( isMasterBranch || isReleaseBranch || isHotFixBranch ) && isTagged ) ;
45
+ var shouldPublishGitHub = shouldPublishNuGet ;
46
+
47
+ var gitVersionResults = GitVersion ( new GitVersionSettings { UpdateAssemblyInfo = false } ) ;
48
+ var semVersion = $ "{ gitVersionResults . MajorMinorPatch } .{ buildNumber } ";
49
+
50
+ Information ( "SemverVersion -> {0}" , semVersion ) ;
51
+
52
+ var projects = ParseSolution ( solutionFile ) . GetProjects ( ) . Select ( x => ParseProject ( x . Path , configuration ) ) ;
53
+
54
+ ///////////////////////////////////////////////////////////////////////////////
55
+ // SETUP / TEARDOWN
56
+ ///////////////////////////////////////////////////////////////////////////////
57
+
58
+ Setup ( ctx =>
25
59
{
26
- foreach ( var project in projects )
27
- {
28
- var settings = new DotNetCoreBuildSettings
29
- {
30
- Configuration = configuration
31
- } ;
32
- DotNetCoreBuild ( project , settings ) ;
60
+ // Executed BEFORE the first task.
61
+ Information ( "Running tasks..." ) ;
62
+
63
+ if ( isMasterBranch && ( ctx . Log . Verbosity != Verbosity . Diagnostic ) ) {
64
+ Information ( "Increasing verbosity to diagnostic." ) ;
65
+ ctx . Log . Verbosity = Verbosity . Diagnostic ;
33
66
}
34
67
} ) ;
35
68
36
- Task ( "Version" )
37
- . Does ( ( ) =>
69
+ Teardown ( ctx =>
38
70
{
39
- if ( AppVeyor . IsRunningOnAppVeyor )
40
- {
41
- foreach ( var project in projects )
42
- {
43
- string version = XmlPeek ( project , "/Project/PropertyGroup/VersionPrefix" ) ;
44
- version = version . Substring ( 0 , version . LastIndexOf ( '.' ) ) + "." + AppVeyor . Environment . Build . Number . ToString ( ) ;
45
-
46
- TransformConfig ( project , project , new TransformationCollection {
47
- { "Project/PropertyGroup/VersionPrefix" , version }
48
- } ) ;
49
- }
50
- }
71
+ // Executed AFTER the last task.
72
+ Information ( "Finished running tasks." ) ;
51
73
} ) ;
52
74
53
- Task ( "Restore" )
54
- . Does ( ( ) =>
55
- {
56
- var settings = new DotNetCoreRestoreSettings { Sources = nugetSources } ;
57
- DotNetCoreRestore ( Directory ( "." ) , settings ) ;
75
+ ///////////////////////////////////////////////////////////////////////////////
76
+ // TASKS
77
+ ///////////////////////////////////////////////////////////////////////////////
78
+
79
+ Task ( "Default" )
80
+ . IsDependentOn ( "Clean" )
81
+ . IsDependentOn ( "Build" )
82
+ . IsDependentOn ( "Test" ) ;
83
+
84
+ Task ( "Build" )
85
+ . Does ( ( ) => {
86
+ Information ( "Building {0}" , solutionFile ) ;
87
+ var msbuildBinaryLogFile = artifactsDir + new FilePath ( solutionFile . Path . GetFilenameWithoutExtension ( ) + ".binlog" ) ;
88
+
89
+ MSBuild ( solutionFile . Path , settings => {
90
+ settings
91
+ . SetConfiguration ( configuration )
92
+ . SetMaxCpuCount ( 0 ) // use as many cpu's as are available
93
+ . WithRestore ( )
94
+ . WithProperty ( "TreatresultsAsErrors" , "false" )
95
+ . WithProperty ( "resultsAsErrors" , "3884" )
96
+ . WithProperty ( "CodeContractsRunCodeAnalysis" , "true" )
97
+ . WithProperty ( "RunCodeAnalysis" , "false" )
98
+ . WithProperty ( "Version" , semVersion )
99
+ . WithProperty ( "PackageVersion" , gitVersionResults . MajorMinorPatch )
100
+ . WithProperty ( "PackageOutputPath" , MakeAbsolute ( nugetPackageDir ) . FullPath )
101
+ . UseToolVersion ( MSBuildToolVersion . VS2017 )
102
+ . SetNodeReuse ( false ) ;
103
+
104
+ // setup binary logging for solution to artifacts dir
105
+ settings . ArgumentCustomization = arguments => {
106
+ arguments . Append ( $ "/bl:{ msbuildBinaryLogFile } ") ;
107
+ return arguments ;
108
+ } ;
109
+ } ) ;
58
110
} ) ;
59
111
60
- Task ( "Pack" )
61
- . IsDependentOn ( "Build" )
62
- . Does ( ( ) =>
112
+ Task ( "Test" )
113
+ . Does ( ( ) => {
114
+ Information ( "Testing for {0}" , solutionFile ) ;
115
+ projects . Where ( x => x . IsTestProject ( ) ) . Each ( x => DotNetCoreTest ( x . ProjectFilePath . FullPath ) ) ;
116
+ } ) ;
117
+
118
+ Task ( "ReleaseNotes" )
119
+ . IsDependentOn ( "Create-Release-Notes" ) ;
120
+
121
+ Task ( "AppVeyor" )
122
+ . IsDependentOn ( "Default" )
123
+ . IsDependentOn ( "Upload-AppVeyor-Artifacts" )
124
+ . IsDependentOn ( "Publish-Nuget-Packages" )
125
+ . IsDependentOn ( "Publish-GitHub-Release" )
126
+ . Finally ( ( ) =>
63
127
{
64
- var settings = new DotNetCorePackSettings
128
+ if ( publishingError )
129
+ {
130
+ throw new Exception ( $ "An error occurred during the publishing of { solutionFile . Path } . All publishing tasks have been attempted.") ;
131
+ }
132
+ } ) ;
133
+
134
+ Task ( "Create-Release-Notes" )
135
+ . Does ( ( ) => {
136
+ Information ( "Creating release notes for {0}" , semVersion ) ;
137
+ gitHubUserName . ThrowIfNull ( nameof ( gitHubUserName ) ) ;
138
+ gitHubPassword . ThrowIfNull ( nameof ( gitHubPassword ) ) ;
139
+ GitReleaseManagerCreate ( gitHubUserName , gitHubPassword , gitHubRepositoryOwner , gitHubRepositoryName , new GitReleaseManagerCreateSettings {
140
+ Milestone = gitVersionResults . MajorMinorPatch ,
141
+ Name = gitVersionResults . MajorMinorPatch ,
142
+ Prerelease = false ,
143
+ TargetCommitish = "master" ,
144
+ } ) ;
145
+ } ) ;
146
+
147
+ Task ( "Export-Release-Notes" )
148
+ . WithCriteria ( ( ) => ! isLocalBuild )
149
+ . WithCriteria ( ( ) => BuildSystem . IsRunningOnAppVeyor && ! isPullRequest )
150
+ . WithCriteria ( ( ) => isMasterBranch || isReleaseBranch || isHotFixBranch )
151
+ . WithCriteria ( ( ) => isTagged )
152
+ . Does ( ( ) => {
153
+ Information ( "Exporting release notes for {0}" , solutionFile ) ;
154
+ gitHubUserName . ThrowIfNull ( nameof ( gitHubUserName ) ) ;
155
+ gitHubPassword . ThrowIfNull ( nameof ( gitHubPassword ) ) ;
156
+
157
+ GitReleaseManagerExport ( gitHubUserName , gitHubPassword , gitHubRepositoryOwner , gitHubRepositoryName , releaseNotesPath ,
158
+ new GitReleaseManagerExportSettings {
159
+ TagName = gitVersionResults . MajorMinorPatch
160
+ } ) ;
161
+ } ) ;
162
+
163
+ Task ( "Publish-GitHub-Release" )
164
+ . IsDependentOn ( "Export-Release-Notes" )
165
+ . WithCriteria ( ( ) => shouldPublishGitHub )
166
+ . Does ( ( ) => {
167
+ Information ( "Publishing github release for {0}" , solutionFile ) ;
168
+ gitHubUserName . ThrowIfNull ( nameof ( gitHubUserName ) ) ;
169
+ gitHubPassword . ThrowIfNull ( nameof ( gitHubPassword ) ) ;
170
+
171
+ // upload packages as assets
172
+ foreach ( var package in GetFiles ( nugetPackageDir . Path + "/*" ) )
65
173
{
66
- Configuration = configuration ,
67
- OutputDirectory = buildArtifacts ,
68
- } ;
69
-
70
- foreach ( var project in projects )
71
- {
72
- DotNetCorePack ( Directory ( project ) , settings ) ;
73
- }
74
-
75
- if ( ! isLocalBuild )
76
- {
77
- var artifacts = GetFiles ( buildArtifacts . Path + "/*.nupkg" ) ;
78
- foreach ( var artifact in artifacts )
79
- {
80
- AppVeyor . UploadArtifact ( artifact ) ;
81
- }
82
- }
174
+ GitReleaseManagerAddAssets ( gitHubUserName , gitHubPassword , gitHubRepositoryOwner , gitHubRepositoryName , gitVersionResults . MajorMinorPatch , package . ToString ( ) ) ;
175
+ }
176
+
177
+ // close the release
178
+ GitReleaseManagerClose ( gitHubUserName , gitHubPassword , gitHubRepositoryOwner , gitHubRepositoryName , gitVersionResults . MajorMinorPatch ) ;
83
179
} ) ;
84
180
85
- Task ( "Clean" )
86
- . Does ( ( ) =>
87
- {
88
- CleanDirectories ( new DirectoryPath [ ] { buildArtifacts } ) ;
181
+ Task ( "Publish-Nuget-Packages" )
182
+ . WithCriteria ( ( ) => shouldPublishNuGet )
183
+ . WithCriteria ( ( ) => DirectoryExists ( nugetPackageDir ) )
184
+ . Does ( ( ) => {
185
+
186
+ Information ( "Publishing NuGet Packages for {0}" , solutionFile ) ;
187
+
188
+ nugetSourceUrl . ThrowIfNull ( nameof ( nugetSourceUrl ) ) ;
189
+ nugetApiKey . ThrowIfNull ( nameof ( nugetApiKey ) ) ;
190
+ var nupkgFiles = GetFiles ( nugetPackageDir . Path + "/**/*.nupkg" ) ;
191
+
192
+ foreach ( var nupkgFile in nupkgFiles )
193
+ {
194
+ // Push the package.
195
+ NuGetPush ( nupkgFile , new NuGetPushSettings {
196
+ Source = nugetSourceUrl ,
197
+ ApiKey = nugetApiKey ,
198
+ } ) ;
199
+ }
89
200
} ) ;
90
201
91
- Task ( "Default" )
92
- . IsDependentOn ( "Build" )
93
- . IsDependentOn ( "Pack" ) ;
202
+
203
+ Task ( "Upload-AppVeyor-Artifacts" )
204
+ . IsDependentOn ( "Export-Release-Notes" )
205
+ . WithCriteria ( ( ) => BuildSystem . IsRunningOnAppVeyor )
206
+ . WithCriteria ( ( ) => DirectoryExists ( nugetPackageDir ) )
207
+ . Does ( ( ) => {
208
+ Information ( "Uploading AppVeyor artifacts for {0}" , solutionFile ) ;
209
+ foreach ( var package in GetFiles ( nugetPackageDir . Path + "/*" ) )
210
+ {
211
+ AppVeyor . UploadArtifact ( package ) ;
212
+ }
213
+ } ) ;
214
+
215
+ Task ( "Sample" )
216
+ . Does ( ( ) => {
217
+ Information ( "Restoring NuGet Packages for {0}" , solutionFile ) ;
218
+ } ) ;
219
+
220
+ Task ( "Clean" )
221
+ . Does ( ( ) => {
222
+ CleanDirectories ( new DirectoryPath [ ] {
223
+ artifactsDir ,
224
+ nugetPackageDir
225
+ } ) ;
226
+ } ) ;
94
227
95
228
RunTarget ( target ) ;
0 commit comments