-
-
Notifications
You must be signed in to change notification settings - Fork 757
/
releasing.gradle.kts
102 lines (93 loc) · 3.86 KB
/
releasing.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
import com.vdurmont.semver4j.Semver
plugins {
id("com.github.breadmoirai.github-release")
id("io.codearte.nexus-staging")
}
nexusStaging {
packageGroup = "io.gitlab.arturbosch"
stagingProfileId = "1d8efc8232c5c"
username = findProperty("sonatypeUsername")
?.toString()
?: System.getenv("MAVEN_CENTRAL_USER")
password = findProperty("sonatypePassword")
?.toString()
?: System.getenv("MAVEN_CENTRAL_PW")
}
project.afterEvaluate {
githubRelease {
token(project.findProperty("github.token") as? String ?: "")
owner.set("detekt")
repo.set("detekt")
overwrite.set(true)
dryRun.set(false)
targetCommitish.set("main")
body {
var changelog = project.file("docs/pages/changelog 1.x.x.md").readText()
val nextNonBetaVersion = project.version.toString().substringBeforeLast("-")
val sectionStart = "#### $nextNonBetaVersion"
changelog = changelog.substring(changelog.indexOf(sectionStart) + sectionStart.length)
changelog = changelog.substring(0, changelog.indexOf("#### 1."))
changelog.trim()
}
val cliBuildDir = project(":detekt-cli").buildDir
releaseAssets.setFrom(
files(
cliBuildDir.resolve("libs/detekt-cli-${project.version}-all.jar"),
cliBuildDir.resolve("distributions/detekt-cli-${project.version}.zip"),
project(":detekt-formatting").buildDir.resolve("libs/detekt-formatting-${project.version}.jar")
)
)
}
}
fun updateVersion(increment: (Semver) -> Semver) {
val versionsFile = file("${rootProject.rootDir}/build-logic/src/main/kotlin/Versions.kt")
val newContent = versionsFile.readLines()
.joinToString("\n") {
if (it.contains("const val DETEKT: String")) {
val oldVersion = it.substringAfter("\"").substringBefore("\"")
val newVersion = Semver(oldVersion).let(increment)
println("Next release: $newVersion")
""" const val DETEKT: String = "$newVersion""""
} else {
it
}
}
versionsFile.writeText("$newContent\n")
}
tasks {
register("incrementPatch") { doLast { updateVersion { it.nextPatch() } } }
register("incrementMinor") { doLast { updateVersion { it.nextMinor() } } }
register("incrementMajor") { doLast { updateVersion { it.nextMajor() } } }
register<UpdateVersionInFileTask>("applyDocVersion") {
fileToUpdate.set(file("${rootProject.rootDir}/website/docusaurus.config.js"))
linePartToFind.set(" detektVersion:")
lineTransformation.set(" detektVersion: '${Versions.DETEKT}'")
}
}
tasks.register("publishToMavenLocal") {
description = "Publish all the projects to Maven Local"
subprojects {
if (this.plugins.hasPlugin("publishing")) {
dependsOn(tasks.named("publishToMavenLocal"))
}
}
dependsOn(gradle.includedBuild("detekt-gradle-plugin").task(":publishToMavenLocal"))
}
tasks.register("publishAllToSonatypeSnapshot") {
description = "Publish all the projects to Sonatype Snapshot Repository"
subprojects {
if (this.plugins.hasPlugin("publishing")) {
dependsOn(tasks.named("publishAllPublicationsToSonatypeSnapshotRepository"))
}
}
dependsOn(gradle.includedBuild("detekt-gradle-plugin").task(":publishAllPublicationsToSonatypeSnapshotRepository"))
}
tasks.register("publishAllToMavenCentral") {
description = "Publish all the projects to Sonatype Staging Repository"
subprojects {
if (this.plugins.hasPlugin("publishing")) {
dependsOn(tasks.named("publishAllPublicationsToMavenCentralRepository"))
}
}
dependsOn(gradle.includedBuild("detekt-gradle-plugin").task(":publishAllPublicationsToMavenCentralRepository"))
}