-
Notifications
You must be signed in to change notification settings - Fork 52
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
PR #627
- Loading branch information
Showing
27 changed files
with
165 additions
and
138 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
108 changes: 108 additions & 0 deletions
108
build-logic/src/main/kotlin/kotlinx/kover/conventions/kover-release-conventions.gradle.kts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,108 @@ | ||
/* | ||
* Copyright 2017-2024 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license. | ||
*/ | ||
|
||
import java.time.LocalDate | ||
import java.time.format.DateTimeFormatter | ||
|
||
// ==================== | ||
// Release preparation | ||
// ==================== | ||
tasks.register("prepareRelease") { | ||
doLast { | ||
if (!project.hasProperty("releaseVersion")) { | ||
throw GradleException("Property 'releaseVersion' is required to run this task") | ||
} | ||
val releaseVersion = project.property("releaseVersion") as String | ||
val prevReleaseVersion = project.property("kover.release.version") as String | ||
|
||
val projectDir = layout.projectDirectory | ||
|
||
if (project.path == Project.PATH_SEPARATOR) { | ||
projectDir.file("gradle.properties").asFile.patchProperties(releaseVersion) | ||
projectDir.file("CHANGELOG.md").asFile.patchChangeLog(releaseVersion) | ||
|
||
projectDir.file("README.md").asFile.replaceInFile(prevReleaseVersion, releaseVersion) | ||
} else { | ||
// replace versions in examples | ||
projectDir.dir("examples").patchExamples(releaseVersion, prevReleaseVersion) | ||
|
||
// replace versions in docs | ||
projectDir.dir("docs").patchDocs(releaseVersion, prevReleaseVersion) | ||
} | ||
|
||
|
||
} | ||
} | ||
|
||
fun Directory.patchExamples(releaseVersion: String, prevReleaseVersion: String) { | ||
asFileTree.matching { | ||
include("**/*gradle") | ||
include("**/*gradle.kts") | ||
}.files.forEach { | ||
it.replaceInFile(prevReleaseVersion, releaseVersion) | ||
} | ||
} | ||
|
||
fun Directory.patchDocs(releaseVersion: String, prevReleaseVersion: String) { | ||
asFileTree.files.forEach { | ||
it.replaceInFile(prevReleaseVersion, releaseVersion) | ||
} | ||
} | ||
|
||
fun File.patchChangeLog(releaseVersion: String) { | ||
val oldContent = readText() | ||
writer().use { | ||
it.appendLine("$releaseVersion / ${LocalDate.now().format(DateTimeFormatter.ISO_DATE)}") | ||
it.appendLine("===================") | ||
it.appendLine("TODO add changelog!") | ||
it.appendLine() | ||
it.append(oldContent) | ||
} | ||
} | ||
|
||
fun File.patchProperties(releaseVersion: String) { | ||
val oldLines = readLines() | ||
writer().use { writer -> | ||
oldLines.forEach { line -> | ||
when { | ||
line.startsWith("version=") -> writer.append("version=") | ||
.appendLine(increaseSnapshotVersion(releaseVersion)) | ||
|
||
line.startsWith("kover.release.version=") -> writer.append("kover.release.version=") | ||
.appendLine(releaseVersion) | ||
|
||
else -> writer.appendLine(line) | ||
} | ||
} | ||
} | ||
} | ||
|
||
// modify version '1.2.3' to '1.2.4' and '1.2.3-Beta' to '1.2.3-SNAPSHOT' | ||
fun increaseSnapshotVersion(releaseVersion: String): String { | ||
// remove postfix like '-Alpha' | ||
val correctedVersion = releaseVersion.substringBefore('-') | ||
if (correctedVersion != releaseVersion) { | ||
return "$correctedVersion-SNAPSHOT" | ||
} | ||
|
||
// split version 0.0.0 to int parts | ||
val parts = correctedVersion.split('.') | ||
val newVersion = parts.mapIndexed { index, value -> | ||
if (index == parts.size - 1) { | ||
(value.toInt() + 1).toString() | ||
} else { | ||
value | ||
} | ||
}.joinToString(".") | ||
|
||
return "$newVersion-SNAPSHOT" | ||
} | ||
|
||
fun File.replaceInFile(old: String, new: String) { | ||
if (name.endsWith(".png")) return | ||
|
||
val newContent = readText().replace(old, new) | ||
writeText(newContent) | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
version=0.8.1-SNAPSHOT | ||
version=0.8.2-SNAPSHOT | ||
group=org.jetbrains.kotlinx | ||
|
||
# version of the latest release | ||
kover.release.version=0.8.0 | ||
kover.release.version=0.8.1 | ||
kotlin.code.style=official |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.