-
Notifications
You must be signed in to change notification settings - Fork 0
/
release.gradle
90 lines (76 loc) · 2.44 KB
/
release.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
import java.nio.file.Files
task tag {
group = 'jSupla'
doLast {
def gradleProps = project.file('gradle.properties')
def match = gradleProps.text =~ /jSuplaVersion=(.+)/
if (!match) {
throw new RuntimeException("Version not found in gradle.properties")
}
//noinspection GroovyAssignabilityCheck
def version = match[0][1]
def tagName = "jSupla-$version"
def tagFile = project.buildDir.toPath().resolve("tag.txt")
Files.createDirectories(tagFile.parent)
if (Files.exists(tagFile)) {
Files.delete(tagFile)
}
Files.createFile(tagFile)
tagFile.write(tagName)
}
}
task noSnapshots {
group = 'jSupla'
doLast {
def gradleProps = project.file('gradle.properties')
def versionLine = gradleProps.text.find(/jSuplaVersion=(\d+\.\d+\.\d+(.+)?)/)
if (!versionLine) {
throw new RuntimeException("Version not found in gradle.properties")
}
if (versionLine.contains('SNAPSHOT')) {
throw new RuntimeException("No snapshots allowed at this point! version=$versionLine")
}
logger.debug("version=$versionLine is not snapshot")
}
}
prodProjects {
publish.dependsOn ":noSnapshots"
}
tag.dependsOn "noSnapshots"
task releaseVersion {
group = 'jSupla'
doLast {
def gradleProps = project.file('gradle.properties')
def originalContent = gradleProps.text
def updatedContent = originalContent.replaceAll(/jSuplaVersion=(\d+\.\d+\.\d+)-SNAPSHOT/, "jSuplaVersion=\$1")
gradleProps.text = updatedContent
def versionLine = gradleProps.text.find(/jSuplaVersion=(\d+\.\d+\.\d+)/)
if (!versionLine) {
throw new RuntimeException("Version not found in gradle.properties")
}
def currentVersion = versionLine[1]
logger.info "Current version: $currentVersion"
}
}
task nextSnapshot {
group = 'jSupla'
doLast {
def gradleProps = project.file('gradle.properties')
def match = gradleProps.text =~ /jSuplaVersion=(\d+)\.(\d+)\.(\d+)/
if (!match) {
throw new RuntimeException("Version not found in gradle.properties")
}
//noinspection GroovyAssignabilityCheck
def major = match[0][1] as int
//noinspection GroovyAssignabilityCheck
def minor = match[0][2] as int
//noinspection GroovyAssignabilityCheck
def patch = match[0][3] as int
// Increment the minor version
minor++
// Update the version line
def updatedVersion = "jSuplaVersion=$major.$minor.$patch-SNAPSHOT"
gradleProps.text = gradleProps.text.replaceFirst(/jSuplaVersion=\d+\.\d+\.\d+/, updatedVersion)
logger.info("Updated version: $updatedVersion")
}
}