-
Notifications
You must be signed in to change notification settings - Fork 1.1k
/
Copy pathversion.gradle
59 lines (52 loc) · 1.72 KB
/
version.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
ext {
versionTags = [
[start: "gradle-small:", end: "'", path: 'README.md'],
[start: "gradle-small:", end: "'", path: '../../Sample/build.gradle'],
[start: "gradle-small:", end: "'", path: '../../../Android/README.md'],
[start: "gradle-small:", end: "'", path: '../../../Android/GETTING-STARTED.md'],
[start: '"smallPluginVersion" value="', end: '" />', path: '../../../Android/templates/activities/SmallLauncher/globals.xml.ftl']
]
}
def updateVersion(File f, String start, String end, version) {
def s = ''
def updated = false
f.eachLine { line ->
def loc = line.indexOf(start)
if (loc > 0) {
updated = true
line = "${line.substring(0, loc)}${start}${version}${end}"
}
s += "$line\n"
}
if (updated) {
f.write(s, 'utf-8')
}
}
def updateVersions() {
versionTags.each { Map<String, String> it ->
def file = new File(project.rootDir, it.path)
if (!file.exists()) return
updateVersion(file, it.start, it.end, version)
}
}
task ('checkVersions') .doLast {
def changelog = project.file('CHANGELOG.md')
if (!changelog.exists()) return
def reader = new BufferedReader(new FileReader(changelog))
def top = reader.readLine()
reader.close()
if (!top.startsWith("## $version")) {
throw new RuntimeException(
"The CHANGELOG should be update first. Required '$version', but got '$top'")
}
}
task ('updateVersions') .doLast {
updateVersions()
}
project.afterEvaluate {
def upload = project.tasks['bintrayUpload']
upload.dependsOn(project.tasks['checkVersions'])
upload.doLast {
updateVersions()
}
}