This repository was archived by the owner on Sep 30, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathbuild.gradle
More file actions
143 lines (126 loc) · 4.62 KB
/
build.gradle
File metadata and controls
143 lines (126 loc) · 4.62 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
import org.gradle.internal.os.OperatingSystem
import groovy.xml.XmlUtil
plugins {
id 'com.ullink.msbuild' version '2.21'
id 'com.ullink.nuget' version '2.12'
id 'com.ullink.nunit' version '1.4'
id 'com.ullink.opencover' version '1.2'
id 'net.researchgate.release' version '2.3.4'
id "co.riiid.gradle" version '0.4.2'
}
archivesBaseName = 'EzTextingApiClient'
ext['buildConfiguration'] = System.properties[ 'BUILD_CONFIG' ] ?: "Release"
ext['assemblyBinDir'] = "src/EzTextingApiClient/bin/$buildConfiguration"
ext['buildDistDir'] = "$buildDir/dist"
ext['assemblyInfo'] = "src/EzTextingApiClient/Properties/AssemblyInfo.cs"
defaultTasks('nugetPack')
nuget {
version = '4.4.0'
}
msbuild.dependsOn nugetRestore
msbuild {
solutionFile = 'eztexting-api-client-csharp.sln'
configuration = buildConfiguration
projectName = 'EzTextingApiClient'
generateDoc = true
inputs.file(project.buildFile)
}
nunit {
testAssemblies = [ msbuild.projects['EzTextingApiClient.Tests'].properties.TargetPath ]
}
nunit.dependsOn msbuild
task updateNuspecFile << {
def specFile = file('EzTextingApiClient.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 {} }
spec.files.appendNode {
file(src: "$assemblyBinDir/${archivesBaseName}.dll", target: 'lib') {}
file(src: "$assemblyBinDir/${archivesBaseName}.dll.config", target: 'lib') {}
file(src: "$assemblyBinDir/${archivesBaseName}.xml", target: 'lib') {}
if(buildConfiguration == 'Debug') {
file(src: "src/**/*.cs", target: 'src') {}
}
}
def fw = new FileWriter('EzTextingApiClient.nuspec')
XmlUtil.serialize(spec, fw)
// have to close manually because on windows file remains locked
fw.close()
}
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)
from 'LICENSE.txt'
from 'Changelog.txt'
from (assemblyBinDir) {
include "${archivesBaseName}.*"
}
}
zipBinaries.dependsOn nunit
// nuget package for upload to nuget
nugetSpec {
nuspecFile = file('EzTextingApiClient.nuspec')
}
nugetSpec.dependsOn updateNuspecFile
nugetPack {
destinationDir = buildDistDir
generateSymbols = buildConfiguration == 'Debug'
}
nugetPack.dependsOn zipBinaries
// nuget package upload, requires API key to be set
nugetPush {
serverUrl = 'https://www.nuget.org/api/v2/package'
apiKey = System.properties[ 'NUGET_API_KEY' ] ?: "key not set"
nupkgFile = nugetPack.packageFile
}
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 = 'eztexting-api-client-csharp'
token = "${gitHubToken}"
tagName = project.version
targetCommitish = 'master'
name = project.version
body = releaseDescription()
assets = [
'build/dist/EzTextingApiClient-' + project.version + '.zip',
'build/dist/EzTextingApiClient.' + project.version + '.nupkg'
]
}
}
}
configureCustomGitHubRelease.dependsOn prepareReleaseData
githubRelease.dependsOn configureCustomGitHubRelease
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"
}