-
-
Notifications
You must be signed in to change notification settings - Fork 10
/
build.gradle.kts
140 lines (122 loc) · 4.05 KB
/
build.gradle.kts
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
/*
* halcyon-core
* Copyright (C) 2018 Tigase, Inc. ([email protected])
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, version 3 of the License.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. Look for COPYING file in the top folder.
* If not, see http://www.gnu.org/licenses/.
*/
import java.util.*
plugins {
`maven-publish`
signing
id("net.researchgate.release") version "3.0.2"
}
configure<net.researchgate.release.ReleaseExtension> {
ignoredSnapshotDependencies.set(listOf("net.researchgate:gradle-release"))
versionPropertyFile.set("gradle.properties")
versionProperties.set(listOf("version", "halcyonVersion"))
preTagCommitMessage.set("Release version: ")
tagCommitMessage.set("Tag version: ")
newVersionCommitMessage.set("Bump version: ")
// Fail the release process when there are un-committed changes. Will commit files automatically if set to false.
failOnCommitNeeded.set(true)
failOnUnversionedFiles.set(true)
failOnPublishNeeded.set(false)
failOnSnapshotDependencies.set(false)
failOnUpdateNeeded.set(true)
with(git) {
requireBranch.set("master")
}
}
val props = Properties().also { props ->
val file = File("local.properties")
if (file.exists()) file.reader().use { props.load(it) }
}
tasks["afterReleaseBuild"].dependsOn("publish")
buildscript {
repositories {
google()
mavenCentral()
mavenLocal()
jcenter()
}
dependencies {
classpath(deps.kotlin.kotlinGradlePlug)
classpath(deps.kotlinx.serialization.gradlePlug)
classpath(deps.kotlin.dokkaPlug)
}
}
repositories {
mavenCentral()
jcenter()
gradlePluginPortal()
}
allprojects {
group = "tigase.halcyon"
version = insertBuildNumber(findProperty("version").toString(), "git rev-list --count HEAD".runCommand(File("./")))
}
fun insertBuildNumber(version: String, build: String): String {
return version
// if (!version.contains("-SNAPSHOT")) return "$version.$build"
// return version.substringBefore("-SNAPSHOT") + ".$build"
}
subprojects {
repositories {
mavenCentral()
mavenLocal()
maven(url = findProperty("tigaseMavenRepoRelease").toString())
maven(url = findProperty("tigaseMavenRepoSnapshot").toString())
jcenter()
}
pluginManager.withPlugin("signing") {
val secretKey = props["signing.secretKey"]?.toString()
val password = props["signing.password"]?.toString()
if (!secretKey.isNullOrBlank()) {
logger.info("Signing is enabled.")
signing {
useInMemoryPgpKeys(secretKey, password)
sign(publishing.publications)
}
} else {
logger.info("Signing is disabled.")
}
}
pluginManager.withPlugin("maven-publish") {
publishing {
repositories {
maven {
url = if (project.version.toString().endsWith("-SNAPSHOT", ignoreCase = true)) {
uri(findProperty("tigaseMavenRepoSnapshot").toString())
} else {
uri(findProperty("tigaseMavenRepoRelease").toString())
}
credentials {
username = props["mavenUsername"]?.toString() ?: findProperty("mavenUsername").toString()
password = props["mavenPassword"]?.toString() ?: findProperty("mavenPassword").toString()
}
}
}
}
}
}
fun String.runCommand(
workingDir: File = File("."), timeoutAmount: Long = 60, timeoutUnit: TimeUnit = TimeUnit.SECONDS,
): String = ProcessBuilder(split("\\s(?=(?:[^'\"`]*(['\"`])[^'\"`]*\\1)*[^'\"`]*$)".toRegex())).directory(workingDir)
.redirectOutput(ProcessBuilder.Redirect.PIPE).redirectError(ProcessBuilder.Redirect.PIPE).start()
.apply { waitFor(timeoutAmount, timeoutUnit) }.run {
val error = errorStream.bufferedReader().readText().trim()
if (error.isNotEmpty()) {
println("Cannot determine build number.")
"0"
} else inputStream.bufferedReader().readText().trim()
}