forked from twilio/audioswitch
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.gradle
240 lines (203 loc) · 7.85 KB
/
build.gradle
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
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
buildscript {
ext.kotlin_version = '1.3.72'
/**
* Properties and environment variables needed to publish to Bintray.
*/
ext.mavenRepo = (project.hasProperty('maven.repo') ?
project.property("maven.repo") : '')
ext.mavenUsername = (project.hasProperty('maven.username') ?
project.property("maven.username") : '')
ext.mavenPassword = (project.hasProperty('maven.password') ?
project.property("maven.password") : '')
ext.jfrogUsername = (project.hasProperty('jfrog.username') ?
project.property("jfrog.username") : '')
ext.jfrogPassword = (project.hasProperty('jfrog.password') ?
project.property("jfrog.password") : '')
ext.getPropertyValue = { propertyKey ->
def property = System.getenv(propertyKey)
if (property == null) {
logger.log(LogLevel.INFO, "Could not locate $propertyKey as environment variable. " +
"Trying local.properties")
Properties properties = new Properties()
if (project.rootProject.file('local.properties').exists()) {
properties.load(project.rootProject.file('local.properties').newDataInputStream())
property = properties.getProperty(propertyKey)
}
}
if (property == null) {
logger.log(LogLevel.WARN, "$propertyKey unavailable.")
}
return property
}
ext.getAudioSwitchJfrogOssPassword = {
def audioSwitchJfrogOssPassword = System.getenv("AUDIOSWITCH_JFROG_OSS_PASSWORD");
if (audioSwitchJfrogOssPassword == null) {
logger.log(LogLevel.INFO, "Could not locate AUDIOSWITCH_JFROG_OSS_PASSWORD environment variable. " +
"Trying local.properties")
Properties properties = new Properties()
if (project.rootProject.file('local.properties').exists()) {
properties.load(project.rootProject.file('local.properties').newDataInputStream())
audioSwitchJfrogOssPassword = properties.getProperty('AUDIOSWITCH_JFROG_OSS_PASSWORD')
}
}
if (audioSwitchJfrogOssPassword == null) {
logger.log(LogLevel.WARN, "AudioSwitch Jfrog OSS password unavailable.")
}
return audioSwitchJfrogOssPassword;
}
ext.getShortCommitSha = {
def gitSha = System.getenv("CIRCLE_SHA1")
if(gitSha != null) return gitSha.substring(0, 7) else return ""
}
ext.audioSwitchVersion = "${versionMajor}.${versionMinor}.${versionPatch}" +
((project.hasProperty("preRelease") && project.property("preRelease").toBoolean() == true) ?
"-SNAPSHOT" :
'')
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:4.0.0'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
}
}
plugins {
id "com.diffplug.gradle.spotless" version "4.0.1"
id "com.jfrog.artifactory" version "4.15.2"
}
apply plugin: "com.diffplug.gradle.spotless"
spotless {
format 'misc', {
target '**/*.gradle', '**/*.md', '**/.gitignore'
trimTrailingWhitespace()
indentWithSpaces()
endWithNewline()
}
java {
target '**/*.java'
googleJavaFormat().aosp()
}
kotlin {
target '**/*.kt'
ktlint()
}
}
allprojects {
repositories {
google()
jcenter()
}
}
/*
* Utility GradleBuild task that enables defining custom tasks derived from gradle modules in a
* root level gradle file.
*
* TODO: Replace this approach in favor of pushing tasks down into their respective modules.
*/
class RootGradleBuild extends GradleBuild {
private static final String ROOT_PROJECT_NAME = "audioswitch-root"
RootGradleBuild() {
super()
buildName = ROOT_PROJECT_NAME
}
}
/*
* Checks if release tag matches version and current commit
*/
def matchesVersion(versionTag) {
def properties = new Properties()
file("${rootDir}/gradle.properties").withInputStream { properties.load(it) }
def releaseTag = "${properties.getProperty("versionMajor")}." +
"${properties.getProperty("versionMinor")}." +
"${properties.getProperty("versionPatch")}"
return releaseTag == versionTag
}
task validateReleaseTag {
description = 'Validate the release tag matches the release version ' +
'present on commit'
group = 'Git'
doLast {
def circleTag = System.getenv("CIRCLE_TAG")
def tagsMatch = (matchesVersion(circleTag)) ? ("true") : ("false")
exec {
workingDir "${rootDir}"
commandLine tagsMatch
}
}
}
task incrementVersion(type: RootGradleBuild) {
description = 'Increment the SDK version after a release'
group = 'Git'
doLast {
def stdOut = new ByteArrayOutputStream()
exec {
commandLine "bash", "-c", "git remote show origin | grep HEAD | cut -d: -f2-"
standardOutput stdOut
}
def gitBranch = stdOut.toString().replaceAll("\\s","")
def circleTag = System.getenv("CIRCLE_TAG")
def nextVersionPatch = versionPatch.toInteger() + 1
if (!buildDir.exists()) {
buildDir.mkdir()
}
exec {
workingDir "${rootDir}"
commandLine "git", "checkout", "${gitBranch}"
}
/*
* Only update the version on upstream branch if the version matches tag. It is possible
* these values do not match if a job is performed on an earlier commit and a PR
* with a version update occurs later in history.
*/
if (matchesVersion(circleTag)) {
exec {
workingDir "${rootDir}"
commandLine "echo", "Incrementing from versionPatch ${versionPatch} to " +
"${nextVersionPatch}"
}
exec {
workingDir "${rootDir}"
commandLine "sed",
"s@versionPatch=.*@versionPatch=${nextVersionPatch}@",
"gradle.properties"
standardOutput new FileOutputStream("${buildDir}/gradle.properties")
}
exec {
workingDir "${rootDir}"
commandLine "mv", "${buildDir}/gradle.properties", "gradle.properties"
}
exec {
workingDir "${rootDir}"
commandLine "git", "commit", "gradle.properties", "-m", "\"Bump patch version [skip ci]\""
}
exec {
workingDir "${rootDir}"
commandLine "git", "push", "origin", "${gitBranch}"
}
}
}
}
task jfrogOssSnapshotsAudioSwitchUpload(type: RootGradleBuild) {
description = 'Publish an AudioSwitch Snapshot to JFrog OSS'
group = 'Publishing'
buildFile = file('audioswitch/build.gradle')
tasks = ['assembleRelease', 'artifactoryPublish']
startParameter.projectProperties += gradle.startParameter.projectProperties + [
'preRelease': true,
'jfrog.username': "${getPropertyValue("AUDIOSWITCH_JFROG_OSS_USERNAME")}",
'jfrog.password': "${getPropertyValue("AUDIOSWITCH_JFROG_OSS_PASSWORD")}"
]
}
task bintrayAudioSwitchReleaseUpload(type: RootGradleBuild) {
description = 'Publish an AudioSwitch release'
group = 'Publishing'
dependsOn validateReleaseTag
buildFile = file('audioswitch/build.gradle')
tasks = ['assembleRelease', 'uploadArchives']
startParameter.projectProperties += gradle.startParameter.projectProperties + [
'maven.repo': 'https://api.bintray.com/maven/twilio/releases/audioswitch/;publish=1',
'maven.username': "${getPropertyValue("AUDIOSWITCH_BINTRAY_USERNAME")}",
'maven.password': "${getPropertyValue("AUDIOSWITCH_BINTRAY_PASSWORD")}"
]
}