forked from uber/rides-android-sdk
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.gradle
208 lines (183 loc) · 6.59 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
apply plugin: 'distribution'
apply plugin: 'net.researchgate.release'
apply plugin: 'co.riiid.gradle'
import groovy.text.GStringTemplateEngine
import org.codehaus.groovy.runtime.DateGroovyMethods
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.1.0'
classpath 'net.researchgate:gradle-release:2.3.5'
classpath 'co.riiid:gradle-github-plugin:0.4.2'
classpath 'net.saliman:gradle-cobertura-plugin:2.3.1'
}
}
allprojects {
apply plugin: 'checkstyle'
apply plugin: 'maven'
["githubToken", "ossrhUsername", "ossrhPassword",
"signing.keyId", "signing.password", "signing.secretKeyRingFile",].each {
checkAndDefaultProperty(it)
}
ext.set("unsnapshottedVersion", version.replaceAll("-SNAPSHOT", ""))
ext.set("samples", project(":samples").subprojects.collect { it.path })
ext.set("isReleaseVersion", !version.endsWith("SNAPSHOT"))
repositories {
jcenter()
}
checkstyle {
toolVersion = "6.11.2"
}
task checkstyleMain(type: Checkstyle, overwrite: true) {
configFile = new File("{$project.projectDir}/config/checkstyle/checkstyle-main.xml")
}
task checkstyleTest(type: Checkstyle, overwrite: true) {
configFile = new File("{$project.projectDir}/config/checkstyle/checkstyle-test.xml")
}
}
def generateReleaseNotes() {
def changelogSnippet = generateChangelogSnippet()
def model = [title : "Uber Rides Android SDK (Beta) v${unsnapshottedVersion}",
date : DateGroovyMethods.format(new Date(), 'MM/dd/yyyy'),
snippet: changelogSnippet,
assets : project.samples.collect {
[
title : project(it).name,
download : githubDownloadPrefix + "v${unsnapshottedVersion}/"
+ project(it).name + "-v${unsnapshottedVersion}.zip",
description: project(it).description,
]
}]
def engine = new GStringTemplateEngine()
def template = engine.createTemplate(rootProject.file('releasenotes.gtpl')).make(model)
return template.toString()
}
def generateChangelogSnippet() {
def changelog = rootProject.file('CHANGELOG.md').text
def snippet = ""
def stop = false
changelog.eachLine { line, count ->
if (count >= 2) {
stop = stop || line.startsWith("v");
if (!stop) {
snippet += line + "\n";
}
}
}
return " " + snippet.trim();
}
def checkAndDefaultProperty(prop) {
if (!project.hasProperty(prop)) {
logger.warn("Add " + prop + " to your ~/.gradle/gradle.properties file.")
rootProject.ext.set(prop, prop)
}
}
def checkForChangelogUpdates(task) {
def changelogtext = rootProject.file('CHANGELOG.md').text
if (!changelogtext.startsWith("v${unsnapshottedVersion} -")) {
throw new AssertionError(
"Changelog must be updated with v{$unsnapshottedVersion} before release. Please check " +
rootProject.file('CHANGELOG.md').absolutePath)
}
}
gradle.taskGraph.afterTask { Task task, TaskState state ->
if (task.path.endsWith("release") || task.path.endsWith("githubReleaseZip")
|| task.path.endsWith("publicrepoDistZip")) {
checkForChangelogUpdates(task)
}
}
// Skip signing archives on Jenkins when -SNAPSHOT is being checked in.
gradle.taskGraph.beforeTask { Task task ->
if (task.path.contains("sign") && !ext.isReleaseVersion) {
task.enabled = false
}
}
task updateChangelog() << {
def newVersion = findProperty("version").replaceAll('-SNAPSHOT', '')
def changelog = rootProject.file('CHANGELOG.md')
def changelogText = changelog.text
if (!changelogText.startsWith("v${newVersion} -")) {
def updatedChangelog = "v${newVersion} - TBD\n"
def dashesCount = updatedChangelog.length()-1
updatedChangelog += "-"*dashesCount + "\n\n"
changelog.write(updatedChangelog + changelogText)
}
}
afterReleaseBuild.dependsOn(":core-android:uploadArchives", ":rides-android:uploadArchives")
updateVersion.dependsOn ":githubRelease"
commitNewVersion.dependsOn ':updateChangelog'
githubRelease.dependsOn project(":samples").subprojects.collect { it.path + ":githubReleaseZip" }
release {
failOnCommitNeeded = false
failOnPublishNeeded = false
failOnSnapshotDependencies = false
revertOnFail = true
tagTemplate = "v${unsnapshottedVersion}"
}
github {
owner = 'uber'
repo = 'rides-android-sdk'
token = "${githubToken}"
tagName = "v${unsnapshottedVersion}"
targetCommitish = 'master'
name = "v${unsnapshottedVersion}"
body = generateReleaseNotes()
assets = project.samples.collect {
project(it).buildDir.absolutePath + "/distributions/" + project(it).name +
"-v${unsnapshottedVersion}.zip"
}
}
distributions {
publicrepo {
baseName = 'publicrepo'
contents {
from(rootDir) {
include 'build.gradle'
include 'CHANGELOG.md'
include 'gradle.properties'
include 'gradlew'
include 'gradlew.bat'
include 'LICENSE'
include 'releasenotes.gtpl'
include 'settings.gradle'
include 'gradle/'
include 'config'
include 'test-shared/'
include '.travis.yml'
}
from(rootDir) {
include 'README.md'
filter { String line ->
line.replaceAll("_version_", unsnapshottedVersion)
}
}
from('core-android') {
filesNotMatching("**/*.png") {
filter { String line ->
line.replaceAll("_version_", unsnapshottedVersion)
}
}
exclude 'build'
exclude '*.iml'
into 'core-android'
}
from('rides-android') {
filesNotMatching("**/*.png") {
filter { String line ->
line.replaceAll("_version_", unsnapshottedVersion)
}
}
exclude 'build'
exclude '*.iml'
into 'rides-android'
}
from('samples') {
exclude '**/build'
exclude '**/*.iml'
into 'samples'
}
}
}
}