-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathbuild.gradle
More file actions
219 lines (193 loc) · 7.65 KB
/
build.gradle
File metadata and controls
219 lines (193 loc) · 7.65 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
import org.gradle.internal.os.OperatingSystem
import org.apache.tools.ant.taskdefs.condition.Os
import org.gradle.api.tasks.AbstractExecTask
import groovy.xml.XmlUtil
import groovy.xml.StreamingMarkupBuilder
plugins {
id 'com.ullink.msbuild' version '2.21'
id 'com.ullink.nuget' version '2.15'
id 'com.ullink.nunit' version '1.10'
id 'com.ullink.opencover' version '1.7'
id 'net.researchgate.release' version '2.6.0'
id 'com.github.jlouns.cpe' version '0.5.0'
id "co.riiid.gradle" version "0.4.2"
}
archivesBaseName = 'callfire-api-client'
ext['nunitConsoleVersion'] = '3.6.1'
ext['buildReleaseConfiguration'] = "CallfireApiClient"
ext['buildReleaseConfiguration'] = "Release"
ext['buildDebugConfiguration'] = "Debug"
ext['assemblyBinReleaseDir'] = "src/CallfireApiClient/bin/$buildReleaseConfiguration"
ext['assemblyBinDebugDir'] = "src/CallfireApiClient/bin/$buildDebugConfiguration"
ext['buildDistDir'] = "$buildDir/dist"
ext['assemblyInfo'] = "src/CallfireApiClient/Properties/AssemblyInfo.cs"
defaultTasks('nugetPack')
nuget {
version = '4.4.0'
}
msbuild.dependsOn nugetRestore
msbuild {
solutionFile = 'callfire-api-client-csharp.sln'
configuration = buildReleaseConfiguration
projectName = 'CallfireApiClient'
generateDoc = true
}
task msbuildDebug (type: com.ullink.Msbuild) {
solutionFile = 'callfire-api-client-csharp.sln'
configuration = buildDebugConfiguration
projectName = 'CallfireApiClient'
}
msbuildDebug.dependsOn nunit
nunit {
nunitVersion = nunitConsoleVersion
testAssemblies = [ msbuild.projects['CallfireApiClient.Tests'].properties.TargetPath ]
}
nunit.dependsOn msbuild
task updateNuspecFile {
doLast {
def specFile = file('CallfireApiClient.nuspec')
def spec = new XmlSlurper().parse(specFile)
project.version = patchVersion(spec.metadata.version.text)
spec.metadata.version = project.version
spec.metadata.releaseNotes = file('Changelog.txt').text
// cleanup previous lib/ and src/ files since they depend on build configuration
spec.files.file.findAll { it.@target == 'lib' || it.@target == 'src' }.each { it.replaceNode {} }
def isWindowsOs = Os.isFamily(Os.FAMILY_WINDOWS)
def monoInstallation = "$System.env.MONO_HOME"
def pdbToMdbConverter
if (isWindowsOs) {
if (monoInstallation != 'null') {
pdbToMdbConverter = "$System.env.MONO_HOME" + "\\bin\\pdb2mdb.bat"
exec { commandLine = [pdbToMdbConverter, "$assemblyBinDebugDir/${archivesBaseName}.dll"] }
}
}
spec.files.appendNode {
file(src: "src/**/*.cs", target: 'src') {}
file(src: "$assemblyBinDebugDir/${archivesBaseName}.dll", target: 'lib') {}
file(src: "$assemblyBinReleaseDir/${archivesBaseName}.dll.config", target: 'lib') {}
file(src: "$assemblyBinReleaseDir/${archivesBaseName}.xml", target: 'lib') {}
if (isWindowsOs) {
file(src: "$assemblyBinDebugDir/${archivesBaseName}.pdb", target: 'lib') {}
}
}
def fw = new FileWriter('CallfireApiClient.nuspec')
XmlUtil.serialize(spec, fw)
// have to close manually because on windows file remains locked
fw.close()
}
}
updateNuspecFile.dependsOn msbuildDebug
def patchVersion(version) {
def regex = ~/\[assembly: AssemblyVersion\("(.*)\.\*"\)\]/
def matcher = regex.matcher(new File(assemblyInfo).text)
while(matcher.find()) {
def updated = matcher.group(1)
println "Patching Nuspec version to $updated"
return updated
}
version
}
task zipBinaries(type: Zip) {
destinationDir = file(buildDistDir)
baseName = "CallfireApiClient"
from 'LICENSE.txt'
from 'Changelog.txt'
from (assemblyBinReleaseDir) {
include "${archivesBaseName}.*"
}
}
zipBinaries.dependsOn nugetSpec
// nuget package for upload to nuget
nugetSpec {
nuspecFile = file('CallfireApiClient.nuspec')
}
nugetSpec.dependsOn updateNuspecFile
nugetPack {
destinationDir = buildDistDir
generateSymbols = true
}
nugetPack.dependsOn zipBinaries
task prepareTestData {
doLast {
def inFile = file('src/CallfireApiClient.IntegrationTests/App.config')
def xml = new XmlSlurper().parse(inFile)
def apiLogin
def apiPassword
try {
apiLogin = "${testApiUsername}"
apiPassword = "${testApiPassword}"
println([ msbuild.projects['CallfireApiClient.IntegrationTests'].properties.TargetPath ])
} catch(Exception ex) {
println("Api Username and/or Password are empty, you can't run integrationTests task, set them with -PtestApiUsername/-PtestApiPassword options")
apiLogin = "login"
apiPassword = "password"
}
if (apiLogin != 'null' && apiPassword != 'null') {
xml.appSettings.add.findAll { it.@key == 'testLogin' || it.@key == 'testPassword' }.each { it.replaceNode {} }
xml.appSettings.appendNode {
add(key: "testLogin", value: apiLogin) {}
add(key: "testPassword", value: apiPassword) {}
}
}
def fw = new FileWriter('src/CallfireApiClient.IntegrationTests/App.config')
XmlUtil.serialize(xml, fw)
// have to close manually because on windows file remains locked
fw.close()
}
}
task msbuildForIntegrationTests (type: com.ullink.Msbuild) {
solutionFile = 'callfire-api-client-csharp.sln'
configuration = buildReleaseConfiguration
projectName = 'CallfireApiClient'
}
msbuildForIntegrationTests.dependsOn prepareTestData
task integrationTests (type: com.ullink.gradle.nunit.NUnit) {
nunitVersion = nunitConsoleVersion
testAssemblies = [ msbuild.projects['CallfireApiClient.IntegrationTests'].properties.TargetPath ]
}
integrationTests.dependsOn msbuildForIntegrationTests
task prepareReleaseData {
doLast {
try {
println("${gitHubOwner}")
println("${gitHubToken}")
} catch(Exception ex) {
println("GitHub Owner and/or Token are empty, you can't run github release task, set them with -PgitHubOwner/-PgitHubToken options")
}
}
}
prepareReleaseData.dependsOn nugetPack
task configureCustomGitHubRelease {
doLast {
github {
owner = "${gitHubOwner}"
repo = 'callfire-api-client-csharp'
token = "${gitHubToken}"
tagName = project.version
targetCommitish = 'master'
name = project.version
body = releaseDescription()
assets = [
'build/dist/CallfireApiClient-' + project.version + '.zip',
'build/dist/CallfireApiClient.' + project.version + '.nupkg'
]
}
}
}
configureCustomGitHubRelease.dependsOn prepareReleaseData
githubRelease.dependsOn configureCustomGitHubRelease
// nuget package upload, requires API key to be set
nugetPush {
apiKey = System.properties[ 'NUGET_API_KEY' ] ?: "key not set"
serverUrl = 'https://www.nuget.org/api/v2/package'
nupkgFile = nugetPack.packageFile
}
def releaseDescription() {
String releaseNotes = file("Changelog.txt").text
String firstVersionEntry = releaseNotes.find(~/Version.*/)
Integer start = releaseNotes.indexOf(firstVersionEntry) + firstVersionEntry.size()
releaseNotes = releaseNotes.substring(start, releaseNotes.size())
String secondVersionEntry = releaseNotes.find(~/Version.*/)
String currentReleaseChanges = releaseNotes.substring(0, (secondVersionEntry == null ? releaseNotes.size() - 1 : releaseNotes.indexOf(secondVersionEntry))).trim()
"$currentReleaseChanges"
}